boost-serialization

boost serialization std::unique_ptr support

ε祈祈猫儿з 提交于 2019-12-03 12:25:16
Does the boost serialization library support serialization of std::unique_ptr? I tried to compile the code below, but if I include the boost::archive::text_oarchive oa(ofs); oa << g; line, the compiler (btw gcc4.7 with -std=c++11 flag) throws an error /usr/include/boost/serialization/access.hpp:118:9: error: ‘class std::unique_ptr’ has no member named ‘serialize’ #include <iostream> #include <memory> #include <fstream> #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> class MyDegrees { public: void setDeg(int d){deg = d;} int getDeg()const {return deg;}

LevelDB vs. std::map

試著忘記壹切 提交于 2019-12-03 10:03:20
问题 In our application we use std::map to store (key, value) data and use serialization to store that data on disk. With this approach we are finding that the disk I/O is performance bottleneck and finding values using key is not very fast. I have come across LevelDB and thinking of using it. But I have some questions. LevelDB's documentation says its made for (string, string) key value pair. Does it mean that I can not use for custom key value pairs? It seems the difference between std::map and

Error serializing an abstract class with boost

瘦欲@ 提交于 2019-12-03 08:21:43
I'm trying to serialize my data structures in order to write them to a tcp socket. So far I found that my problem is the serialization. I even tried to use BOOST_SERIALIZATION_ASSUME_ABSTRACT(T) but I can't find any working example similar to my program and how to implement it correctly. Here are some of the links that I have visited: http://programmers-blog.com/category/c-c http://www.boost.org/doc/libs/1_48_0/libs/serialization/doc/tutorial.html#simplecase http://en.highscore.de/cpp/boost/serialization.html#serialization_class_hierarchies My data structures are a little more complicated then

c++11 std::shared_ptr + boost::serialization [duplicate]

半腔热情 提交于 2019-12-03 06:58:48
This question already has an answer here: How can boost::serialization be used with std::shared_ptr from C++11? 7 answers boost serialize and std::shared_ptr 2 answers Hi has anybody already managed to serialize a C++11 std::shared_ptr with boost::serialization. There are lots of obsolete posts out there but none with an acceptable solution. I am not going into discussion why I want to use the std::shared_ptr just accept it! I found this other post: boost serialize and std::shared_ptr but it does not answer my problem how to serialize the std::shared_ptr it only suggests to uses the boost:

boost::asio read n bytes from socket to streambuf

自闭症网瘾萝莉.ら 提交于 2019-12-03 03:58:36
问题 I have a serialized structure, which is being sent via socket. I need to read it in chunks, since one of its fields contains the size of the data remaining: I need to read first few bytes, find out the length and read the rest. This is what I have got: boost::asio::streambuf buffer; boost::system::error_code err_code; // here I need to read only first 16 bytes boost::asio::read(socket, buffer, err_code); std::istream is(&buffer); boost::archive::binary_iarchive ia(is); ia >> my_struct; I have

calling a template function of a derived class

牧云@^-^@ 提交于 2019-12-03 03:44:18
I'm having a problem in C++ with calling a function of a derived class while having a pointer to the base class. EDIT: Some answers referred me to CRTP but my point is that I need to have a pointer to the "Base*" class not "Base*" because I'm unaware of the type currently being handled (The current instance is created from some sort of a factory). Classes: class Base { .. template<typename T> func (T arg) { ... }; }; class Derived1 : public Base { ... template<typename T> func (T arg) { ... }; }; class Derived1 : public Base { ... template<typename T> func (T arg) { ... }; }; Usage: int main()

Where to put BOOST_CLASS_EXPORT for boost::serialization?

蹲街弑〆低调 提交于 2019-12-03 02:23:08
I'm trying to serialize a pointer to a polymorphic class Shape . So I need to use the BOOST_CLASS_EXPORT macro to define a GUID for each subclass. The problem: where to put it? Let me show a minimal test case first: shapes.hpp #include <boost/serialization/access.hpp> #include <boost/serialization/base_object.hpp> #include <boost/serialization/export.hpp> class Shape { friend class boost::serialization::access; template<typename Archive> void serialize(Archive &ar, unsigned int const version) { // nothing to do } public: virtual ~Shape() { } }; class Rect : public Shape { friend class boost:

LevelDB vs. std::map

孤者浪人 提交于 2019-12-03 01:36:45
In our application we use std::map to store (key, value) data and use serialization to store that data on disk. With this approach we are finding that the disk I/O is performance bottleneck and finding values using key is not very fast. I have come across LevelDB and thinking of using it. But I have some questions. LevelDB's documentation says its made for (string, string) key value pair. Does it mean that I can not use for custom key value pairs? It seems the difference between std::map and LevelDB is that LevelDB is persistent and std::map works in memory. So does it mean the disk I/O

Boost serialization polymorphic register(export) not working across files

守給你的承諾、 提交于 2019-12-03 00:48:20
I am using boost::serialization in my project. The project is large, and serializes my objects in several places. According to the documentation here , I should export my class with two separated step. BOOST_EXPORT_KEY() in .h file, witch contains the declaration. BOOST_EXPOET_IMPLEMENT() in .cpp file, witch contains the instantiation(definition) of the exporting. hier.h the class hierarchy, there are 3 classes in the hierarchy. /* B <---+--- D1 | +--- D2 */ #include <boost/serialization/base_object.hpp> class B { public: virtual ~B() {} template < typename Ar > void serialize(Ar& ar, const

boost::asio read n bytes from socket to streambuf

流过昼夜 提交于 2019-12-02 17:21:14
I have a serialized structure, which is being sent via socket. I need to read it in chunks, since one of its fields contains the size of the data remaining: I need to read first few bytes, find out the length and read the rest. This is what I have got: boost::asio::streambuf buffer; boost::system::error_code err_code; // here I need to read only first 16 bytes boost::asio::read(socket, buffer, err_code); std::istream is(&buffer); boost::archive::binary_iarchive ia(is); ia >> my_struct; I have taken a look at boost::asio::async_read(s, boost::asio::buffer(data, size), handler); but it can only