c++ - How to serialize a CString using boost -


i'm trying use boost::serialization replace 1 part of existing project implements own methods serialization not good. however, i'm facing problems because application uses mfc. tried serialize cstring follows

template<class archive> void save(archive & ar, cstring & s, const unsigned int version) {     using boost::serialization::make_nvp;   const std::basic_string<tchar> ss((lpctstr)s);   ar & make_nvp("string", ss); } template<class archive> void load(archive & ar, cstring & s, const unsigned int version) {     using boost::serialization::make_nvp;   std::string ss;   ar & make_nvp("string",ss);   s = ss.c_str; } 

but i'm getting errors

boost_1_45_0\boost\serialization\access.hpp(118): error c2039: 'serialize' : not member of 'atl::cstringt'

in access.hpp says

// note: if compile time error here // message like: // cannot convert parameter 1 <file type 1> <file type 2 &> // possible cause class t contains  // serialize function - serialize function isn't  // template , corresponds file type different // class archive.  resolve this, don't include // archive type other serialization // function defined!!! 

so imagine cstring has serialization due mfc.

now i'm wondering, can do? there workaround? i'm trying avoid redefinition of cstrings std:string because there many of them, implies re entire project.

also, want serialize carray i'm getting same type of error, serialize not member of carray.

edit: the cstring problem fixed adding

template<class archive> inline void serialize(archive & ar, cstring & s, const unsigned int file_version) {     split_free(ar, s, file_version);  } 

i don't know why macro doesn't work. however, i'm still facing problems carray. tried simple solution

ar & make_nvp("carray",mycarray);  

but doesn't create xml. , tried iterate on array this

for(int i=0; < mycarray.getcount(); i++) {   myclass* m = (myclass*) mycarray.getat(i);         ar & boost_serialization_nvp(m); } 

but isn't calling serialization of class. there straight forward way serialize arrays std::vector or std::list in boost examples?

you can use save , load if working class can add boost_serialization_split_member() definition of. since can't string, need implement boost serialization in terms of serialize method:

template<class archive> void serialize(archive & ar, cstring & s, const unsigned int version) {     std::string ss(s);     ar & ss;     s = ss.c_str; } 

this less efficient, should @ least compile.

edit: actually, can split free function, need add along save , load functions:

#include <boost/serialization/split_free.hpp>  template<class archive> inline void serialize(archive & ar, cstring & s, const unsigned int file_version) {     split_free(ar, s, file_version);  } 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -