Boost logo

Boost Users :

Subject: [Boost-users] [Q] reading back serialized Collection of shared_ptr
From: V S P (toreason_at_[hidden])
Date: 2009-06-19 16:18:33


I made may be a little more headways since my previous question

and now have an xml archive that appears to 'denote' the shared pointers
(see below)

To do this I found and used boost template function specifically for
shared pointers

-- a data member of myclass inheritin from std::multiset
-- TRow is the Value type of the multiset that implements 'serialize'
method

--
--
struct
{
   template <typename Archive>
   void serialize (Archive& ar, const unsigned int version)const
   {
     for(tThisClassConstIterator it=this->begin();
         it!=this->end(); ++it)
     {
       boost::serialization::save<Archive,typename
       TRow>(ar,*it,version);
     }
}
tTEST_TB3
now however I do not understand how to 'deserialize this'
The basic call to 
void load_table (tTEST_TB3& t, const char * filename)
{
    // open the archive
      std::ifstream ifs(filename);
      assert(ifs.good());
      boost::archive::xml_iarchive ia(ifs);
    
      ia >> BOOST_SERIALIZATION_NVP(t);
}
does not even compile, I suspect it is because
when this 'serialize' function on tTEST_TB3 is called, now
the 
       boost::serialization::save<Archive,typename
       TRow>(ar,*it,version);
is NOT valid, because the ar is of type iarchive, and save function
on the shared_ptr is not defined for 'iarchive', only for oarchive.
So there is another function in the same boost header file
( #include <boost/serialization/shared_ptr.hpp> )
that defines a 'load' function for the shared ptr
However -- what I do not undestand is how to invoke this function
it seems like I have to iterate through every entry in the archive
and then call load to read it into a shared ptr?
That seems to be contrary to all the other mechanism supported by 
the Serialization library.
The basic examples just say that I can take a container and just shift
it in
(or out) of Archiver -- but that does not work if the container is of
shared pointers.
That's why I went the route of iterating through every element of the
container to
serialize, and not do not undestand how to load it back.
So I need some help
(I can provide the complete example if needed)
thank you in advance
----------
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="5">
<t class_id="0" tracking_level="0" version="0">
	<px class_id="1" tracking_level="1" version="0" object_id="_0">
		<otrq_prov_id>1245439719</otrq_prov_id>
		<clnt_dbid>1245439719</clnt_dbid>
		<mydate>6/19/2009 15:28:39</mydate>
		<amount>33222112121.212000</amount>
	</px>
	<px class_id_reference="1" object_id="_1">
		<otrq_prov_id>1245439719</otrq_prov_id>
		<clnt_dbid>1245439719</clnt_dbid>
		<mydate>6/19/2009 15:28:39</mydate>
		<amount>33222112121.212000</amount>
	</px>
	<px class_id_reference="1" object_id="_2">
		<otrq_prov_id>1245439719</otrq_prov_id>
		<clnt_dbid>1245439719</clnt_dbid>
		<mydate>6/19/2009 15:28:39</mydate>
		<amount>33222112121.212000</amount>
	</px>
	<px class_id_reference="1" object_id="_3">
		<otrq_prov_id>1245439719</otrq_prov_id>
		<clnt_dbid>1245439719</clnt_dbid>
		<mydate>6/19/2009 15:28:39</mydate>
		<amount>33222112121.212000</amount>
	</px>
	<px class_id_reference="1" object_id="_4">
		<otrq_prov_id>1245439719</otrq_prov_id>
		<clnt_dbid>1245439719</clnt_dbid>
		<mydate>6/19/2009 15:28:39</mydate>
		<amount>33222112121.212000</amount>
	</px>
	<px class_id_reference="1" object_id="_5">
		<otrq_prov_id>1245439719</otrq_prov_id>
		<clnt_dbid>1245439719</clnt_dbid>
		<mydate>6/19/2009 15:28:39</mydate>
		<amount>33222112121.212000</amount>
	</px>
	<px class_id_reference="1" object_id="_6">
		<otrq_prov_id>1245439719</otrq_prov_id>
		<clnt_dbid>1245439719</clnt_dbid>
		<mydate>6/19/2009 15:28:39</mydate>
		<amount>33222112121.212000</amount>
	</px>
	<px class_id_reference="1" object_id="_7">
		<otrq_prov_id>1245439719</otrq_prov_id>
		<clnt_dbid>1245439719</clnt_dbid>
		<mydate>6/19/2009 15:28:39</mydate>
		<amount>33222112121.212000</amount>
	</px>
	<px class_id_reference="1" object_id="_8">
		<otrq_prov_id>1245439719</otrq_prov_id>
		<clnt_dbid>1245439719</clnt_dbid>
		<mydate>6/19/2009 15:28:39</mydate>
		<amount>33222112121.212000</amount>
	</px>
	<px class_id_reference="1" object_id="_9">
		<otrq_prov_id>1245439719</otrq_prov_id>
		<clnt_dbid>1245439719</clnt_dbid>
		<mydate>6/19/2009 15:28:39</mydate>
		<amount>33222112121.212000</amount>
	</px>
</t>
</boost_serialization>
-- 
  V S P
  toreason_at_[hidden]
-- 
http://www.fastmail.fm - Send your email first class

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