Try deriving form text_iarchive_impl.  Note that a comment in text_iarchive.hpp explicitly states that it shouldn't be derived from.  For an example on how to derive from an existing archive look at demo_fast_archive and review the section of the manual which discusses this topic.
 
Robert Ramey
"Haskins, Gregory" <ghaskins@enterasys.com> wrote in message news:5CFCA4B6F572E74384A26FBA61CAE837018A5D34@MAANDMBX1.ets.enterasys.com...
I posted this earlier, but I don't think it went through all the way.  I apologize if this is a duplicate:
 
--------------------------------------------------------------------------------------------
 
Hi All,
  Boost newbie here:  I am having problems with getting serialization to work
with my app.  I have a top-level "environment" context that objects in my app
need to be associated with.  I thought about various ways to accomplish this
and I thought the best way might be to derive an Archive class that maintains a
reference to the context and use custom save_construct_data/load_construct_data
overrides.
 
However, I am hitting a snag and I don't quite understand what is happening.  I
derive an input and output archive from text_iarchive/text_oarchive
respectively and I use this archive context.  However I get the following
error in compilation:
 
db.hh: In function `void boost::serialization::load_construct_data(Archive&,
   FlatFileDb::Db*, unsigned int) [with Archive =
   boost::archive::text_iarchive]':
/ccase/cca/vendor/boost/boost/serialization/serialization.hpp:170: 
instantiated from `void boost::serialization::load_construct_data_adl(Archive&,
 T*, unsigned int)
[with Archive = boost::archive::text_iarchive, T = FlatFileDb::Db]'
/ccase/cca/vendor/boost/boost/archive/detail/iserializer.hpp:303:  instantiated
from `void boost::archive::detail::pointer_iserializer<T,
Archive>::load_object_ptr(boost::archive::detail::basic_iarchive&, void*&,
unsigned int) const [with T = FlatFileDb::Db, Archive =
boost::archive::text_iarchive]'
/ccase/cca/vendor/boost/boost/archive/detail/iserializer.hpp:209:  
instantiated from here
db.hh:84: error: 'class boost::archive::text_iarchive' has no member named '
   m_env'
 
Somehow the system is assigning <class Archive> to 'class
boost::archive::text_iarchive' even though I am creating the archive as
something derived from text_iarchive.  The weird thing is that this happens
even if I comment out the code the invokes the actual archiving.  Its almost
like there is some default value of Archive that gets assigned once I include
the text_iarchive.hpp file.  Any ideas on how to stop this from happening? 
Is there a better way to accomplish my goal?
 
Thanks in advance!
-Greg
 
PS: Here are some code snippets of what I am doing.
 

I have a header file called "archive.hh" with
 
-----------------------------------------------------------
 
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
 
namespace FlatFileDb
{
    class Env;
 
    class OArchive : public boost::archive::text_oarchive_impl<OArchive>
    {
    public:
       
        OArchive(Env &env, std::ostream & os, unsigned int flags = 0) :
            boost::archive::text_oarchive_impl<OArchive>(os, flags), m_env(env)
            {}
        ~OArchive(){}
       
        Env &m_env;
    }; 
 
    class IArchive : public boost::archive::text_iarchive_impl<IArchive>
    {
    public:
       
        IArchive(Env &env, std::istream & is, unsigned int flags = 0) :
            boost::archive::text_iarchive_impl<IArchive>(is, flags), m_env(env)
            {}
        ~IArchive(){}
       
        Env &m_env;
    };
};
 
--------------------------------------------------
 
and then I have another header file (db.hh) with:
 
--------------------------------------------------
 
<.../snip...>
 
namespace boost { namespace serialization {
template<class Archive>
inline void save_construct_data(
    Archive & ar, const FlatFileDb::Db *t, const unsigned int file_version
){
    // save data required to construct instance
    ar << t->m_name;
}
 
template<class Archive>
inline void load_construct_data(
    Archive & ar, FlatFileDb::Db* t, const unsigned int file_version
){
    // retrieve data from archive required to construct new instance
    std::string name;
    ar >> name;
    // invoke inplace constructor to initialize instance of my_class
    ::new(t)FlatFileDb::Db(ar.m_env, name);  <-- !!! blows up here !!!y
}
}} // namespace ...


_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users