Boost logo

Boost Users :

Subject: [Boost-users] Serialization: delayed loading of vertexes of graph/tree
From: Moritz Moeller (boost_at_[hidden])
Date: 2008-10-03 01:34:00


Sorry for the n00b question, but I'm totally new to the use of sth. like
boost::serialization. I always wrote all this stuff 'by hand' before. :)

I have a tree (AABB tree, to be precise -- no cycles and no joins) that
I have serialized (I wrote this one 'by hand', i.e. I don't use the
boost graph library).
This works great if I need to save and/or load the entire tree at once.

But actually, when I load it, I want to be able to explicitly trigger
loading of the two sub-vertexes of each vertex in the tree. I.e. my
serialization code for a vertex of the tree currently looks like this:

   template< typename _archive >
   void serialze( typename _archive& ar, const unsigned version )
   {
     ...

     // data
     ar & _data;

     // sub-vertexes aka children
     ar & _child[ 0 ];
     ar & _child[ 1 ];
   }

Now what I imagine is that I split this into save() and load(). My
save() would look exactly like the above serialize(), but my load()
would also need to be split into two parts, one that is invoked
automatically, when I load the object via operator >> and the other one,
which I call explicitly later.

   template< typename _archive >
   void load( typename _archive& ar, const unsigned version )
   {
     ...

     // data
     ar & _data;
   }

   template< typename _archive >
   void loadChildren( typename _archive& ar, const unsigned version )
     // sub-vertexes aka children
     ar & _child[ 0 ];
     ar & _child[ 1 ];
   }

I have no idea if this is the right approach and if so, if I can just
call loadChildren() with the resp. archive?
I imagine not, since I can not guarantee that the vertexes in the tree
will be visited in the same order as they were during invocation of save().
Quite to the contrary, it is highly unlikely that they will ever be
visited in that order.
What I can guarantee though is that each cell's parent has been visited
by the time I need to load it. I.e. the tree is always restored from the
root up, but I can't guarantee which path along the edges the program
will walk when doing so.

So am I back to writing this all 'by hand' in this case or is there some
mechanisms in boost::serialization that I could exploit here?

Cheers,

Moritz


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