boost-serialization

how to use boost::serialize::make_binary_object against a map

我是研究僧i 提交于 2020-01-15 11:03:08
问题 my intention is to get input from map<int,std::string> and create the binary archive which the below code is failing to do , is this the right way of creating it? And how to know whether the data is correctly archived or not(desirializing using boost) Do i just need to create a boost::archive::binary_iarchive oa(oss,1); and copy it to oss ? #include <fstream> #include <boost/serialization/map.hpp> #include <boost/serialization/nvp.hpp> #include <boost/archive/xml_oarchive.hpp> #include

Boost serialization with template classes

a 夏天 提交于 2020-01-04 14:21:15
问题 I'm adding boost serialization support for existing C++ project in linux. In that project there is Template class Called ContainerT and MString is derived from that class by using template type as char. The MString type is used in Person Class and I want to serialize data in Person Class.The Person class is like below.(Since the actual project is large only part of it is given here) #ifndef PERSON_H_ #define PERSON_H_ #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text

boost serialization of nested struct does not work

我是研究僧i 提交于 2020-01-04 14:21:09
问题 I'm trying to serialize a struct which contains two or more other types of sturct. But it seems that serialization does not work. Below is sampel code : //SimpleData.hpp #include <boost/serialization/access.hpp> #include <boost/serialization/base_object.hpp> #include <boost/serialization/optional.hpp> #include <boost/serialization/map.hpp> #include <boost/serialization/shared_ptr.hpp> namespace A { Struct Name { std::string firstname; std::string lastname; template<class Archive> void

Boost:Serialization: Who cleans up the deserialized data?

爱⌒轻易说出口 提交于 2020-01-04 06:30:15
问题 I'm serializing and sending a raw-pointer of an object to another application. When deserializing I'm getting another raw-pointer. This means that Boost::Serialization is constructing the object behind this pointer internally. I'm now curious who has ownership of the object and if Boost will delete that object, if it isn't needed anymore. Some code which perhaps better shows what the question is: void anyMethod() { std::ifstream file("archiv.txt"); boost::archive::text_iarchive ia(file);

Trouble overriding save_construct_data when serializing a pointer to a class without a default constructor

爱⌒轻易说出口 提交于 2020-01-02 08:12:32
问题 I'm trying to follow this example http://www.boost.org/doc/libs/1_42_0/libs/serialization/doc/serialization.html#constructors but I keep getting errors. Following the example, I get an error trying to access a private variable (fair enough): bs.cpp:10: error: ‘const int my_class::m_attribute’ is private But, if I add save_construct_data as a friend, I get an ambiguity error: /usr/include/boost/serialization/serialization.hpp:148: error: call of overloaded ‘save_construct_data(boost::archive:

how to customise default Boost xml Serialisation default node naming to make it more readable

只愿长相守 提交于 2019-12-29 01:46:30
问题 The code below generates a xml file but , when it loops theough a map , it always names the map key as first and value as second Is there a way that we can customise tag names first and second to groupid and groupType as shown in desired output #include <fstream> #include <boost/serialization/map.hpp> #include <boost/serialization/nvp.hpp> #include <boost/archive/xml_oarchive.hpp> #include <string> #include <iostream> #include <map> using namespace std; class MyConnections { public:

how do i serialize list variable of type <boost::shared_ptr<void *>>

余生颓废 提交于 2019-12-25 03:47:20
问题 I'm really not sure how do i serialize a list variable of type boost::shared_ptr <void *> inside a class or struct. Generally, i would go with same method that we generally use like struct A { std::list<boost::shared_ptr<void *>> mdb; } template<class Archive> void serialize(Archive &d,const unsigned int version) { d & mdb; // not sure that this would work } while compiling it does not give error but does not serialize at my end. 回答1: You don't. In all likelihood, the void* is a HANDLE (for

boost::mpi and boost:serialization with std::variant

自古美人都是妖i 提交于 2019-12-24 16:48:05
问题 c++17 introduces the new type std::variant . Is it possible to define a serialization routine, so as to use std::variant in conjunction with boost::mpi ? Consider, e.g., a simple program #include <variant> #include <boost/mpi.hpp> #include <boost/serialization/string.hpp> namespace mpi = boost::mpi; class A { friend class boost::serialization::access; template <class Archive> void serialize(Archive& ar, const unsigned int version) { ar & x; ar & y; } public: int x, y; }; class B { friend

how get name-value pair when creating JSON string from using JSON boost serialization?

雨燕双飞 提交于 2019-12-24 16:07:41
问题 Before answering this question I would request all you good people here to first take a look at this output that I am getting presently. The output is fetched from a sqlite3 table SiteCode which has two columns ID and Code . Although, I go the output but i still dont see the field name in the output. i mean I need an ouput which looks like the following (name-value pair) {"ID":"7","Code":"786","ID":"8","Code":"78","ID":"9","Code":"785","ID":"10","Code":"998","ID":"11","Code":"656"} So do I

deserialization issue after changing namespace to customise tag names for boost xml

旧时模样 提交于 2019-12-24 10:56:06
问题 I have made the below changes to have customised names for tags. And the below code changes worked successfully and i could create a xml doc with customised names. namespace boost { namespace serialization { template <typename Ar> void serialize(Ar& ar,std::pair<int const , Myclass::Pgroups>& p, unsigned) { ar & make_nvp("assetid", p.first) & make_nvp("assetdata", p.second); } } } namespace boost { namespace serialization { template <typename Ar> void serialize(Ar& ar,std::pair<int const ,