Boost logo

Boost :

Subject: [boost] BOOST_CLASS_EXPORT in C++
From: Eric Maes (emaes_at_[hidden])
Date: 2011-07-26 10:47:36


Hello all,

I am new to the boost community and libraries and need some help. I am
taking over a small project which uses boost serialization. We are having
trouble using the BOOST_CLASS_EXPORT macro with version 1.39. We are in the
process of upgrading to v1.47, but have not yet complete the transition on
our other supporting DLLs.

My question is this: When we include the macro in our CPP file, it builds
ok and appears to be ready to rock, however when we attempt to serialze the
object, an exception is thrown. after stepping deeply, we see that the
derived class load_construct_data and save_construct_data methods are not
getting called. We have followed the documentation and it appears we have
it implemented properly. Shown here are code snippets of what we are
doing...

When the macro use was in the HPP files, the serialization worked, but then
an exception was thrown when the application ends. Either way, there is an
issue. From what I can tell in boost docs, the macro use needs to be in the
CPP and not in the HPP

If anyone can give assistance that would be great. I am so new to Boost that
I'm not sure I am using the right nomanclature to describe what is occuring.
Any help that I can get will be much appreciated.

Eric
emaes_at_[hidden]

// ************ derived class (Calculator) load/save definition ********* //
                template
                inline void save_construct_data (Archive& ar, const LpsTktMDO::Calculator*
t, const unsigned int file_version)
                {
                        // save data required to construct instance
                        Lps::CharString name;
                        Lps::CharString expression;
                        name=t->getName ();
                        expression=t->getExpression ();
                        ar << boost::serialization::make_nvp ("name", name);
                        ar << boost::serialization::make_nvp ("expression", expression);
                }

                //!
                //! Serialization method for loading a Calculator object
                //!
            //! \return None
                //!
                template
                inline void load_construct_data (Archive& ar, LpsTktMDO::Calculator* t,
const unsigned int file_version)
                {
                        // retrieve data from archive required to construct new instance
                        Lps::CharString name;
                        Lps::CharString expression;
                        ar >> boost::serialization::make_nvp ("name", name);
                        ar >> boost::serialization::make_nvp ("expression", expression);
                        // invoke inplace constructor to initialize instance of my_class
                        ::new(t)LpsTktMDO::Calculator (name, expression);
                }

// ************ base class (Function) serialize definition ********* //
                template
                void serialize (Archive & ar, const unsigned int version)
                {
                        ar & BOOST_SERIALIZATION_NVP (theNameM);
                        ar & BOOST_SERIALIZATION_NVP (thePmmIdM);
                        ar & BOOST_SERIALIZATION_NVP (theDataMgrM);
                };

// ************ call to serialize the map of calculator/function objects
(which is a member of a PreDef object) ********* //
                template
                void serialize (Archive & ar, const unsigned int version)
                {
                        ar & BOOST_SERIALIZATION_NVP (theDesignVariablesM); // <<-------- this
works
                        ar & BOOST_SERIALIZATION_NVP (theVariablesM); // <<-------- this
works
                        ar & BOOST_SERIALIZATION_NVP (theFunctionsM); // <<-------- this
call issues the exception!
                        ar & BOOST_SERIALIZATION_NVP (theDataMgrM); // <<-------- this
works
                };

// ************ call to serialize the PreDef object ********* //
        BOOST_CHECK_NO_THROW(theOa << BOOST_SERIALIZATION_NVP(thePreDefM));
        
        
                        

--
View this message in context: http://boost.2283326.n4.nabble.com/BOOST-CLASS-EXPORT-in-C-tp3696005p3696005.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk