Boost logo

Boost Users :

From: Olivier Destrebecq (olivierd_at_[hidden])
Date: 2006-04-24 15:44:56


I'm including serialization in my library and am running into problems.

One of my class include an std::auto_ptr <std::string>
I'm including
#include <boost/serialization/string.hpp> to handle the string
serialization

i downloaded the serialization example for an auto_ptr and modified
it to allow for XML serialization (see end of email).

But when i compile get the following error saying:
error: 'struct std::basic_string<char, std::char_traits<char>,
std::allocator<char> >' has no member named 'serialize'

If i replace the std::auto_ptr <std::string> with just std::string it
works, so i assume something is wrong with my auto_ptr code
Feel free to ask me more question or send me beginners advice as i'm
just beginning with BOOST.
Thanks

auto_ptrSerialization.hpp:

#include <list>
#include <memory>
#include <fstream>

#include <boost/config.hpp> // std::autoptr inteface wrong in dinkumware
#include <boost/detail/workaround.hpp>

#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/detail/workaround.hpp>

#include <boost/serialization/split_free.hpp>

namespace boost {
     namespace serialization {

         /////////////////////////////////////////////////////////////
         // implement serialization for auto_ptr<T>
         // note: this must be added to the boost namespace in order to
         // be called by the library
         template<class Archive, class T>
         inline void save(
                          Archive & ar,
                          const std::auto_ptr<T> &t,
                          const unsigned int file_version
                          ){
             // only the raw pointer has to be saved
             // the ref count is rebuilt automatically on load
             T *objectPtr = t.get();
             ar << BOOST_SERIALIZATION_NVP(objectPtr);
         }

         template<class Archive, class T>
         inline void load(
                          Archive & ar,
                          std::auto_ptr<T> &t,
                          const unsigned int file_version
                          ){
             T *objectPtr;
             ar >> BOOST_SERIALIZATION_NVP(objectPtr);
             // note that the reset automagically maintains the
reference count
#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
             t.release();
             t = std::auto_ptr<T>(objectPtr);
#else
             t.reset(objectPtr);
#endif
         }

         // split non-intrusive serialization function member into
separate
         // non intrusive save/load member functions
         template<class Archive, class T>
         inline void serialize(
                               Archive & ar,
                               std::auto_ptr<T> &t,
                               const unsigned int file_version
                               ){
             split_free(ar, t, file_version);
         }

     } // namespace serialization
} // namespace boost

Best,
Olivier Destrebecq
olivierd_at_[hidden]


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net