|
Boost : |
From: Robert Ramey (ramey_at_[hidden])
Date: 2008-02-03 14:00:35
I've spent a tiny amount of time looking over the flyweight documentation
and some code and I have a couple minor observations along with a really
dumb question.
a) when I see boost::flyweight::flyweights it confuses me. I suppose its no
big deal.
b) I'm curious about the serialization implementation. Why didn't you
choose just to serialize the factory? This seems to me the most obvious
implementation and I wonder why you didn't feel it was a good choice.
template<
class Archive,
typename T,typename Arg1,typename Arg2,typename Arg3
>
void serialize(
Archive& ar,const ::boost::flyweights::flyweight<T,Arg1,Arg2,Arg3>& f,
const unsigned int version)
{
typedef ::boost::flyweights::flyweight<T,Arg1,Arg2,Arg3> flyweight;
ar & flyweight::factory(); // serialization tracking guarentees only one
copy
ar & f.h; // serialization tracking optimizes
down to an integer object id
}
This might not be a good idea if flyweight reference count isn't used. So
another idea might be:
template<
class Archive,
typename T,typename Arg1,typename Arg2,typename Arg3
>
void save(
Archive& ar,const ::boost::flyweights::flyweight<T,Arg1,Arg2,Arg3>& f,
const unsigned int version)
{
typedef ::boost::flyweights::flyweight<T,Arg1,Arg2,Arg3> flyweight;
ar << f.h; // serialization tracking optimizes
down to an integer object id
}
template<
class Archive,
typename T,typename Arg1,typename Arg2,typename Arg3
>
void load(
Archive& ar,const ::boost::flyweights::flyweight<T,Arg1,Arg2,Arg3>& f,
const unsigned int version)
{
typedef ::boost::flyweights::flyweight<T,Arg1,Arg2,Arg3> flyweight;
T t;
ar >> t; // serialization tracking optimizes
down to an integer object id
f.factory.insert(t); // or something along those lines
//fix up object address of t - off hand I don't remember the syntax
}
In short, I don't see why a "helper" is required.
Robert Ramey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk