questions concerning optional + date_time + serialize

Hi All! I've got few questions concerning the date_time, optional and serialization libs (1.32) and how they work together. I'm trying to serialize a optional<posix_time::time_duration> using a binary Archive. Unfortunately the extraction code fails to compile. This is because the optional<T> requires T to have a default constructor, when extraction from an archive (see code take from optional.hpp below). I changed the code ( see blow) to work around this. I know that is neither efficient (heap usage) nor exception safe but it works for me. Also it requires operator=. But ptime has got this. Does any body have more advanced suggestions to solve this? Another thing is that I'm unable to serialize not_a_date_time ptimes. The extractions fails here. I'm using the binary archive. Is that supported? The documentation of date time only states compatibility with text and XML archive... Any hints are greatly appreciated and thanks in advance. kind regards Alex template<class Archive, class T> void save( Archive & ar, const boost::optional<T> & t, const unsigned int /*version*/ ){ bool tflag = t; ar << boost::serialization::make_nvp("initialized", tflag); if (tflag) //ar << boost::serialization::make_nvp("value", &(*t)); ar << &(*t); } template<class Archive, class T> void load( Archive & ar, boost::optional<T> & t, const unsigned int /*version*/ ){ bool tflag; ar >> boost::serialization::make_nvp("initialized", tflag); if (tflag){ T* p; ar >> p;// boost::serialization::make_nvp("value", p); t.reset(*p); //T aux; //ar >> boost::serialization::make_nvp("value", aux); //t.reset(aux); delete p; } else { t.reset(); } }

On Fri, 29 Jul 2005 15:21:38 +0200, Jasper, Alexander wrote
... Another thing is that I'm unable to serialize not_a_date_time ptimes. The extractions fails here. I'm using the binary archive. Is that supported? The documentation of date time only states compatibility with text and XML archive...
There was a recent (jun 21) bug-fix in date-time that was preventing correct serialization of special values -- even with text archives -- so it's likely that's what you are seeing. I haven't tried the binary archive, but there's no reason it shouldn't work. I believe you should be able to just pickup the latest version of gregorian/greg_serialize.hpp and posix_time/time_serialize.hpp to try it out. Jeff
participants (2)
-
Jasper, Alexander
-
Jeff Garland