Boost logo

Boost Users :

Subject: Re: [Boost-users] Serialization problem with cyclic references (pointers)
From: kwanti (ngkwanti_at_[hidden])
Date: 2013-11-29 12:20:27


How about this?

class A
{
public:
    A()
        {
                parent = nullptr;
                someInt = 0;
        }

    BOOST_SERIALIZATION_SPLIT_MEMBER()

    template <class Archive>
    void save(Archive& archive, const unsigned int version) const
    {
        archive << someInt;
        archive << children;
    }

    template <class Archive>
    void load(Archive& archive, const unsigned int version)
    {
        archive >> someInt;
        archive >> children;
        for( std::vector<A*>::iterator iter = children.begin(); iter !=
children.end(); ++iter)
        {
            (*iter)->parent = this;
        }
    }

    int someInt;
    A* parent;
    std::vector<A*> children;
};

You will serialize the whole tree starting from the root node with this.

--
View this message in context: http://boost.2283326.n4.nabble.com/Serialization-problem-with-cyclic-references-pointers-tp4655477p4655584.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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