Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2004-12-03 18:28:10


> Does 'just use' mean that one would now need to replace all occurrences of
> float* data members with tracked_float*'s? As in:
>

All the ones you want to serialize as a pointer.

I expect there is another method which is less intrusive, but I would have
to think about it.

Robert Ramey

"Jeff Flinn" <TriumphSprint2000_at_[hidden]> wrote in message
news:coqq3a$us7$1_at_sea.gmane.org...
>
> "Robert Ramey" <ramey_at_[hidden]> wrote in message
> news:coqoda$2t4$1_at_sea.gmane.org...
> > OK
> >
> > Heres the short explanation using float as an example:
> >
> > Its not a great idea to set the tracking trait for float to tracking
> because
> > you'll end up tracking ALL the floats int the archive.
> >
> > So you make a very small class that just contains a float. That as
> wrapper
> > class. This is to function just like a float except that it has a
> different
> > class. So it will have the default serialization trace assigned since
its
> > not a primitive. This means it will be tracked by default.
> >
> > struct tracked_float {
> > float m_float; // the real data
> > template<class Archive>
> > void serialize(Archive &ar, unsigned int version){
> > ar & m_float;
> > }
> > // casting operators - not compiled
> > float operator float () const {
> > return m_float;
> > }
> > float & operator float() {
> > return m_float;
> > }
> > };
> >
> > Now just use tracked_float for those floats you want to serialize
through
> a
>
> Does 'just use' mean that one would now need to replace all occurrences of
> float* data members with tracked_float*'s? As in:
>
> class with_float_ptr
> {
> tracked_float* m_tracked_float_ptr;
>
> ...
>
> template<class Archive>
> void serialize(Archive &ar, const unsigned int version )
> {
> ar & m_tracked_float_ptr;
> }
>
> };
>
> Or is there a less intrusive manner? I'm just curious, as there are no raw
> pointers in anything that I've yet needed to serialize.
>
> > pointer and just float for other float variables.
> >
> > This is more or less equivalent to using
> >
> > BOOST_STRONG_TYPEDEF(tracked_float, float)
> >
> > template<class Archive>
> > void serialize(Archive &ar, tracked_float & tf){
> > ar & tf.m_float;
> > }
> >
> > I don't know if that helps - but there it is.
>
> Jeff


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