
I had the same problem, where I did not want a particular serialized
object to be tracked. It happened when I serialize an object that is
created on the stack and the class is usually tracked but I don't want the
instance on the stack to be tracked.
I've done a little template class that directly calls the serialize method
of the target class, and it works well...
template<typename T>
struct NoTracking : public T, public wrapper_traits<
NoTracking<T>,
object_class_info,
track_never,
version<T>::value >
{
NoTracking() : T() { }
template<typename T0>
NoTracking(const T0& t0) : T(t0) { }
template
Stefan Strasser wrote:
Am 30.03.2013 19:03, schrieb Robert Ramey:
is there a solution to this? is there a serialization wrapper that says "don't track this type just because of this pointer"?
so you want "don't track this particular save - but leave others as normal" Try something like
class A ....
class UntrackedA : public A { ... };
BOOST_SERIALIZATION_TRACK(UntrackedA, track_never);
interesting idea. does this eventually track the object if the base class of UntrackedA is track_selectively and saved through a pointer anywhere else?
for example, an object graph that stores a pointer to its own root (through intermediaries in practice):
class A{ //tracking level: selectively void serialize(...){ ar & a; } A *a; //==this };
class UntrackedA : A{ //tracking level: never void serialize(...){ ar & base_object<A>(*this); } }
void save(UntrackedA *a){ ar << a; }
is "a" serialized twice, or tracked because of track_selectively and the pointer serialization in A::serialize?
lol - I didn't think about this when I responded though I'm sure I did it when I made the code. I'm going to speculate since it's easier than doing any work.
class UntrackedA : public A { // instead of this: void serialize(Archive & ar, unsigned int file_version){ boost::serialization:base_object<A>(*this); } // consider this void serialize(Archive & ar, unsigned int file_version){ ar & m_a; // where m_a is a member of a ar & m_b; // other member of a etc ... } ...
better yet try this: class UntrackedA : public A { }; just use the base class implementation of serialize function via inheritance Robert Ramey
Robert Ramey
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users