[Serialization]Serialization of nested stl object

Hi, all A member of a target class, where one STL object (map) includes another (set), prevent the code from being built properly and the error message urges me to implement *serialize* method for pair<string*, set<unsigned>>. What is the typical way of implementing serialization using boost for this kind of data structures? * Code snippet class B { … map<const string*, set<unsigned> > lines; .. template<class Archive> void serialize (Archive & ar, const unsigned int version) { ar & lines; … * Build error message /opt/local/include/boost/serialization/access.hpp:118: error: ‘class std::map<const std::string*, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> >, std::less<const std::string*>, std::allocator<std::pair<const std::string* const, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> > > > >’ has no member named ‘serialize’ Thanks for your help in advance, /Kangkook

Hi Kangkook, For all stdlib classes Boost.Serialization can deal with, there is a proper header to include. Are you including all necessary ones? Please make a test case and show us. Also, is really a const string* in your snippet? Regards, Júlio. 2011/9/20 Kangkook Jee <aixer77@gmail.com>
Hi, all
A member of a target class, where one STL object (map) includes another (set), prevent the code from being built properly and the error message urges me to implement *serialize* method for pair<string*, set<unsigned>>.
What is the typical way of implementing serialization using boost for this kind of data structures?
* Code snippet
class B { … map<const string*, set<unsigned> > lines; .. template<class Archive> void serialize (Archive & ar, const unsigned int version) { ar & lines; …
* Build error message
/opt/local/include/boost/serialization/access.hpp:118: error: ‘class std::map<const std::string*, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> >, std::less<const std::string*>, std::allocator<std::pair<const std::string* const, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> > > > >’ has no member named ‘serialize’
Thanks for your help in advance,
/Kangkook
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Hi, Julio Thanks for your prompt reply! On Sep 20, 2011, at 5:02 PM, Júlio Hoffimann wrote:
Hi Kangkook,
For all stdlib classes Boost.Serialization can deal with, there is a proper header to include. Are you including all necessary ones?
Initially, I missed to include <… map.hpp> but after adding the line. It shows somewhat different error message /opt/local/include/boost/serialization/access.hpp:118: error: ‘struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >’ has no member named ‘serialize’ and this seems to be related to the member of "const string*".
Please make a test case and show us. Also, is really a const string* in your snippet?
What I'm doing is adding serialization functionality for someone else's code. This member is from the code. Do you think boost serialization isn't supporting such data type? Thanks again your help! Regards, Kangkook
Regards, Júlio.
2011/9/20 Kangkook Jee <aixer77@gmail.com> Hi, all
A member of a target class, where one STL object (map) includes another (set), prevent the code from being built properly and the error message urges me to implement *serialize* method for pair<string*, set<unsigned>>.
What is the typical way of implementing serialization using boost for this kind of data structures?
* Code snippet
class B { … map<const string*, set<unsigned> > lines; .. template<class Archive> void serialize (Archive & ar, const unsigned int version) { ar & lines; …
* Build error message
/opt/local/include/boost/serialization/access.hpp:118: error: ‘class std::map<const std::string*, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> >, std::less<const std::string*>, std::allocator<std::pair<const std::string* const, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> > > > >’ has no member named ‘serialize’
Thanks for your help in advance,
/Kangkook
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

The following is the code snippet that wouldn't get compiled. #include <iostream> #include <fstream> #include <map> #include <string> #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> #include <boost/serialization/map.hpp> #include <boost/serialization/set.hpp> #include <boost/serialization/string.hpp> using namespace std; class B { //private attributes map<const string* , set<unsigned> > lines; //serialization friend class boost::serialization::access; template<class Archive> void serialize (Archive & ar, const unsigned int version) { ar & lines; } public: B() {} }; main (int argc, char* argv[]) { string fname(argv[1]); B b0; std::ofstream ofs (fname.c_str()); boost::archive::text_oarchive oa(ofs); oa << b0; ofs.close(); std::ifstream ifs(fname.c_str()); boost::archive::text_iarchive ia(ifs); ia >> b0; ifs.close(); return 0; } On Sep 20, 2011, at 5:02 PM, Júlio Hoffimann wrote:
Hi Kangkook,
For all stdlib classes Boost.Serialization can deal with, there is a proper header to include. Are you including all necessary ones?
Please make a test case and show us. Also, is really a const string* in your snippet?
Regards, Júlio.
2011/9/20 Kangkook Jee <aixer77@gmail.com> Hi, all
A member of a target class, where one STL object (map) includes another (set), prevent the code from being built properly and the error message urges me to implement *serialize* method for pair<string*, set<unsigned>>.
What is the typical way of implementing serialization using boost for this kind of data structures?
* Code snippet
class B { … map<const string*, set<unsigned> > lines; .. template<class Archive> void serialize (Archive & ar, const unsigned int version) { ar & lines; …
* Build error message
/opt/local/include/boost/serialization/access.hpp:118: error: ‘class std::map<const std::string*, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> >, std::less<const std::string*>, std::allocator<std::pair<const std::string* const, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int> > > > >’ has no member named ‘serialize’
Thanks for your help in advance,
/Kangkook
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Hi Kangkook, By removing the pointer in const string*, the code compiles. You have to investigate how Boost.Serialization handles pointers to stdlib classes: http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/index.html I never tried to serialize a string* nor any pointer to a stdlib class before. Although i know it's possible to use pointers for base classes polymorphically. Serializing a string* shouldn't be a problem, i guess. Regards, Júlio. 2011/9/20 Kangkook Jee <aixer77@gmail.com>
The following is the code snippet that wouldn't get compiled.
#include <iostream> #include <fstream> #include <map> #include <string>
#include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/map.hpp> #include <boost/serialization/set.hpp> #include <boost/serialization/string.hpp>
using namespace std;
class B { //private attributes map<const string* , set<unsigned> > lines;
//serialization friend class boost::serialization::access;
template<class Archive> void serialize (Archive & ar, const unsigned int version) { ar & lines; }
public: B() {} };
main (int argc, char* argv[]) {
string fname(argv[1]);
B b0;
std::ofstream ofs (fname.c_str()); boost::archive::text_oarchive oa(ofs); oa << b0; ofs.close();
std::ifstream ifs(fname.c_str()); boost::archive::text_iarchive ia(ifs); ia >> b0; ifs.close();
return 0; }
participants (2)
-
Júlio Hoffimann
-
Kangkook Jee