[serialization] STATIC_ASSERTION_FAILURE on archive load

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[serialization] STATIC_ASSERTION_FAILURE on archive load

Scott-94
I've read over the compile time trap section of the docs, but I still can't
get my serialization code to compile.  The code to save my std::map
compiles, but the code to load the map asserts on the compile.  As far as I
can tell, I'm not doing anything wrong (save with const ref, load with
non-const ref).  

I will try to summarize my serialization code below:

#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/map.hpp>
#include <boost/serialization/access.hpp>


struct DLL_EXPORT Node
{
        friend class boost::serialization::access;
        unsigned int handle;  // handle of current object
        std::string  name;    // name of object
        std::string  value;   // optional value of object

        template <typename Archive>
        void serialize(Archive& ar, const unsigned int version)
        {
                ar & handle;
                ar & name;
                ar & value;
        }
};


class DLL_EXPORT Manager
{
        // manager node adds a few extra things used in management of each
object
        struct ManagerNode : public Node
        {
                friend class boost::serialization::access;
        private:
                template <typename Archive>
                void serialize(Archive& ar, const unsigned int version)
                {
                        // serialize base class information
                        ar & boost::serialization::base_object <Node>
(*this);
                }
        };

        NodeMap * _nodes;

        // this method compiles fine
        void save(const std::string & filename)
        {
                std::ofstream outFile;
                outFile.open(filename.c_str(), std::ios::binary);
                boost::archive::text_oarchive archiveFile(outFile);

                const NodeMap * const n = _nodes;
                archiveFile << *n;
        }

        // fails on compile with STATIC_ASSERTION_FAILURE
        void load(const std::string & filename)
        {
                std::ifstream inFile;
                inFile.open(filename.c_str(), std::ios::binary);
                boost::archive::text_iarchive archiveFile(inFile);
               
                _nodes->clear();
                archiveFile >> *_nodes;
        }
};


This is on Windows XP using Visual Studio 7.1.  The errors start like this:

..\API\inc\boost\archive\detail\iserializer.hpp(557) : error C2027: use of
undefined type 'boost::STATIC_ASSERTION_FAILURE<x>'
        with
        [
            x=false
        ]
        ..\API\inc\boost\archive\detail\iserializer.hpp(557) : see reference
to class template instantiation 'boost::STATIC_ASSERTION_FAILURE<x>' being
compiled
        with
        [
            x=false
        ]
        ..\API\inc\boost\archive\basic_text_iarchive.hpp(64) : see reference
to function template instantiation 'void
boost::archive::load<Archive,T>(Archive &,T &)' being compiled
        with
        [
            Archive=boost::archive::text_iarchive,
            T=const unsigned int
        ]
        ..\API\inc\boost\archive\text_iarchive.hpp(64) : see reference to
function template instantiation 'void
boost::archive::basic_text_iarchive<Archive>::load_override<T>(T &,int)'
being compiled
** snipped for brevity **



Any help would be greatly appreciated.

Scott

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [serialization] STATIC_ASSERTION_FAILURE on archiveload

Robert Ramey
I tried to compile your example and I had a couple of problems:

a) DLL_EXPORT wasn't defined - I defined it as nothing
b) NodeMap wasn't declared anywhere - I'm not sure what it should be
c)  The following statement is very suspicious:

    archiveFile >> *_nodes;

Since _nodes is declare as const *-  *_nodes is a const and can't be loaded.

Perhaps something similar to the following might be what you're looking for:

// this method compiles fine

void save(

const std::string & filename,

const std::map<Node *, std::less<Node *> > & nodes

){

std::ofstream outFile;

outFile.open(filename.c_str(), std::ios::binary);

boost::archive::text_oarchive archiveFile(outFile);

archiveFile << nodes;

}

// fails on compile with STATIC_ASSERTION_FAILURE

void load(

const std::string & filename,

std::map<Node *, std::less<Node *> > & nodes

){

std::ifstream inFile;

inFile.open(filename.c_str(), std::ios::binary);

boost::archive::text_iarchive archiveFile(inFile);

archiveFile >> nodes;

}

int main(){

std::map<Node *, std::less<Node *> > nodes;

save("name", nodes);

load("name", nodes);

}



Robert Ramey




cheesy4poofs wrote:

> I've read over the compile time trap section of the docs, but I still
> can't get my serialization code to compile.  The code to save my
> std::map compiles, but the code to load the map asserts on the
> compile.  As far as I can tell, I'm not doing anything wrong (save
> with const ref, load with non-const ref).
>
> I will try to summarize my serialization code below:
>
> #include <boost/archive/text_oarchive.hpp>
> #include <boost/archive/text_iarchive.hpp>
> #include <boost/serialization/map.hpp>
> #include <boost/serialization/access.hpp>
>
>
> struct DLL_EXPORT Node
> {
> friend class boost::serialization::access;
> unsigned int handle;  // handle of current object
> std::string  name;    // name of object
> std::string  value;   // optional value of object
>
> template <typename Archive>
> void serialize(Archive& ar, const unsigned int version)
> {
> ar & handle;
> ar & name;
> ar & value;
> }
> };
>
>
> class DLL_EXPORT Manager
> {
> // manager node adds a few extra things used in management of each
> object
> struct ManagerNode : public Node
> {
> friend class boost::serialization::access;
> private:
> template <typename Archive>
> void serialize(Archive& ar, const unsigned int version)
> {
> // serialize base class information
> ar & boost::serialization::base_object <Node>
> (*this);
> }
> };
>
> NodeMap * _nodes;
>
> // this method compiles fine
> void save(const std::string & filename)
> {
> std::ofstream outFile;
> outFile.open(filename.c_str(), std::ios::binary);
> boost::archive::text_oarchive archiveFile(outFile);
>
> const NodeMap * const n = _nodes;
> archiveFile << *n;
> }
>
> // fails on compile with STATIC_ASSERTION_FAILURE
> void load(const std::string & filename)
> {
> std::ifstream inFile;
> inFile.open(filename.c_str(), std::ios::binary);
> boost::archive::text_iarchive archiveFile(inFile);
>
> _nodes->clear();
> archiveFile >> *_nodes;
> }
> };
>
>
> This is on Windows XP using Visual Studio 7.1.  The errors start like
> this:
>
> ..\API\inc\boost\archive\detail\iserializer.hpp(557) : error C2027:
> use of undefined type 'boost::STATIC_ASSERTION_FAILURE<x>'
>        with
>        [
>            x=false
>        ]
>        ..\API\inc\boost\archive\detail\iserializer.hpp(557) : see
> reference to class template instantiation
> 'boost::STATIC_ASSERTION_FAILURE<x>' being compiled
>        with
>        [
>            x=false
>        ]
>        ..\API\inc\boost\archive\basic_text_iarchive.hpp(64) : see
> reference to function template instantiation 'void
> boost::archive::load<Archive,T>(Archive &,T &)' being compiled
>        with
>        [
>            Archive=boost::archive::text_iarchive,
>            T=const unsigned int
>        ]
>        ..\API\inc\boost\archive\text_iarchive.hpp(64) : see reference
> to function template instantiation 'void
> boost::archive::basic_text_iarchive<Archive>::load_override<T>(T
> &,int)' being compiled
> ** snipped for brevity **
>
>
>
> Any help would be greatly appreciated.
>
> Scott



_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users