Serialization of heterogeneous sequence using shared_ptr<void>
Dear All, I'm trying to figure out if something like the below is possible with the serialization library. The idea is to serialize a heterogeneous sequence using shared_pointer<void>. thanks for any help Sean void hetero_sequence() { // create and open a character archive for output std::ofstream ofs("dictionary.pickle"); boost::archive::text_oarchive oa(ofs); std::deque<boost::shared_ptr<void> > sequence; sequence.push_back(boost::shared_ptr<string>(new string("random string"))); sequence.push_back(boost::shared_ptr<double>(new double(3.1415627))); sequence.push_back(boost::shared_ptr<bool>(new bool(false))); // write class instance to archive oa << sequence; // close archive ofs.close(); }
boost::variant serialization is implemented in the next version (1.32) that might work. If you want to make an implementation of boost::any serialization that might work too. In fact I think the way to go about this is to decide which of the above suits you best and if it doesn't implement serialization, do it yourself! Robert Ramey Sean Kelly wrote:
Dear All,
I'm trying to figure out if something like the below is possible with the serialization library. The idea is to serialize a heterogeneous sequence using shared_pointer<void>.
thanks for any help
Sean
void hetero_sequence() { // create and open a character archive for output std::ofstream ofs("dictionary.pickle"); boost::archive::text_oarchive oa(ofs);
std::deque<boost::shared_ptr<void> > sequence; sequence.push_back(boost::shared_ptr<string>(new string("random string"))); sequence.push_back(boost::shared_ptr<double>(new double(3.1415627))); sequence.push_back(boost::shared_ptr<bool>(new bool(false)));
// write class instance to archive oa << sequence; // close archive ofs.close(); }
Dear All, is there any reason to prefer (i.e is it safer) to prefer some_utility(boost::shared_ptr<Foo> ptr) to some_utility(boost::shared_ptr<Foo>& ptr) or even some_utility(Foo& ref) (shared ptr is derefed and passed in) The latter avoiding obviously avoids the increment/decrement of the ref_count. thanks Sean
On 6/10/05, Sean Kelly <sean.kelly@xilinx.com> wrote:
is there any reason to prefer (i.e is it safer) some_utility(boost::shared_ptr<Foo> ptr) to some_utility(boost::shared_ptr<Foo>& ptr) or even some_utility(Foo& ref) (shared ptr is derefed and passed in)
It depends on what some_utility needs to do with the object. See some Peter Dimov's reply to a similar question: http://article.gmane.org/gmane.comp.lib.boost.devel/113132 -- Caleb Epstein caleb dot epstein at gmail dot com
participants (3)
-
Caleb Epstein
-
Robert Ramey
-
Sean Kelly