boost-serialization

Set tracking traits of template class in boost serialization to reduce memory consumption

时光毁灭记忆、已成空白 提交于 2019-12-12 08:17:26
问题 As this link stated for defining traits for a template class we should define it manually or we extract our class from the trait class. But I want to make this process automatically, for this reason inspired from BOOST_CLASS_TRACKING I wrote the blow code: #include<boost/preprocessor/tuple/enum.hpp> ... #define FOO_CLASS_TRACKING(E, PARAMETER_TUPLE, ...) \ namespace boost { \ namespace serialization { \ template<BOOST_PP_TUPLE_ENUM(PARAMETER_TUPLE)> \ struct tracking_level< __VA_ARGS__ > \ {

Put the serialization of a class into a DLL

旧巷老猫 提交于 2019-12-12 08:06:45
问题 I'm looking for a (working) example for externally serializing a class-structure in a DLL. Currently I'm not able to find any examples for that. The Boost documentation is just stating some macros, the forums and newsgroups are just discussing specific problems with their solutions. So I'm asking for an example for (externally) serializing a class-structure like the following. Along with the class-code I added some code of mine for serializing (which does not work, see bottom for error

Disallow serializing an object directly (not through a pointer) if it doesn't have a default constructor

爷,独闯天下 提交于 2019-12-12 02:49:22
问题 I have recently been using save_construct_data() and load_construct_data() when I need to serialize an object without a default constructor. Since it doesn't make sense to do: MyObject a; // can't do this because there is no default constructor archive >> a; we must do: MyObject* aPointer; archive >> a; which calls load_construct_data() before serialize() . However, of course this only works if the object was serialized using save_constructor_data() which is only called if it is written as a

Serializing Vector of Objects which contains Vectors of Pointers

血红的双手。 提交于 2019-12-11 11:58:59
问题 I have 3 classes ("Leader", "Researchers", "Workers") which all derive from a base-class "Team". I have a class "Project" which contains a vector of pointers to different Teams. I use all of the following headers, in this order, in all of my class declarations: #include <sstream> #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> #include <boost/serialization/serialization.hpp> #include <boost/serialization/export.hpp> #include <boost/serialization/vector

Store a vector of pointers to custom objects to file

倾然丶 夕夏残阳落幕 提交于 2019-12-11 10:57:32
问题 I am using the boost example code to store a vector of pointers of objects in a file. My vector is: class VOMC{ public: vector<State*> vomc; ... ... private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & vomc; } } This gives me the following error(among few more): /usr/local/include/boost/serialization/access.hpp:118:9: error: ‘class State’ has no member named ‘serialize’ The error makes is probably telling

Seg fault when saving data using boost::serialization

我只是一个虾纸丫 提交于 2019-12-11 08:16:57
问题 When trying to save the database using boost serialization, I encounter the segfault that I could not resolve. Would you please help? Any suggestion is greately appreciated. I've pinned down the statement below as the culprit but not sure of how to resolve it oa << *this; My code section is below: template<class Archive> void nDB::serialize(Archive &ar, const unsigned int version) { ar & _LAYERS; ar & _MACROS; ar & _MODULES; ar & _INSTS; } void nDB::save_db(string filename) { std::ofstream

Boost::Serialization: How to avoid the double-saving of a pointer? (And getting a free.c error)

萝らか妹 提交于 2019-12-11 05:07:25
问题 I currently have a stl:list, which contains some base objects and some derived classes as well. I can load and save this list without any problems. With the BOOST_CLASS_EXPORT(...) macro, everything is working properly, until i add the following: -------------------------------------------------------------------------------------- I need some objects which contain pointers of other objects in the list. (To stop beeing so abstract: These are some "Game-Objects" and they have some References

boost serialization: see whether a stream is “good”

断了今生、忘了曾经 提交于 2019-12-11 02:06:51
问题 I currently develop a server application which has to receive serialized data from clients, deserialize it and finally process it. The serialized data is sent in form of an array of chars. My problem is that my application can be easily broken by sending invalid data to it. So I wanted to ask whether it's possible to check a string(-stream) and see whether it's good for (de-)serialization (e.g. whether it has a valid signature) before trying to get data from it. By the way: as the title

Boost deserialize a derived class to base class pointer

六眼飞鱼酱① 提交于 2019-12-11 02:06:41
问题 Please help me deserialize a derived class to base-class pointer. I attach the complete source code example. request.hpp (no pair cpp file) #ifndef REQUEST_HPP #define REQUEST_HPP #include <memory> #include <string> #include <boost/archive/xml_oarchive.hpp> #include <boost/archive/xml_iarchive.hpp> namespace demo { namespace common { class request { public: static const int INVALID_ID = -42; request() : id_(INVALID_ID), timestamp_(0), source_ip_("unknown") {}; request(int id, long timestamp,

C++ Boost ptr_map serialization error

◇◆丶佛笑我妖孽 提交于 2019-12-11 00:53:14
问题 I have some code that I want to build. The code uses boost::ptr_map class to serialize certain objects. I have Visual Studio 2008 with boost1.38 and I am getting following error from compiler. I wonder if any one else has seen any thing like this. C2039: 'serialize' : is not a member of 'boost::ptr_map' Looks like some reference is missing and I wonder what it is, I don't see any boost/serialization/ptr_map. I have Googled a lot and nothing has proved to be viable. I have created a sample