|
Boost Users : |
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2005-11-11 12:35:03
"Merrill Cornish" <merrill.cornish_at_[hidden]> wrote in message
news:30546930.1131727463268.JavaMail.root_at_elwamui-norfolk.atl.sa.earthlink.net...
> In the Serialization tutorial, and example is given of the "intrusive"
> method that looks like this:
>
> private:
> friend class boost::serialization::access;
> template<class Archive>
> void serialize(Archive& ar, const unsigned int version)
> {
> ar& var1;
> ar& var2;
> ar& var3;
> }
>
> There is full namespace qualification on "access" but nothing on
> "serialize()". It appears that serialize() would be in whatever the
> prevailing application namespace is (which might not be std).
The above is a member function declaration(with inlined body). Hence it's at
class scope, which is definitely not in the std namespace scope. Intrusive
means that you have access to your class declaration and are able to modify
it to support serialization.
> Later in the tutorial there is an example of the "non-intrusive" method
> that
> looks like this"
>
> namespace boost {
> namespace serialization {
>
> template<class Archive>
> void serialize(Archive& ar, const unsigned int version)
I think you had a cut/paste error here. The actual function signature is:
void serialize(Archive & ar, gps_position & g, const unsigned int
version)
> {
> ar& var1;
> ar& var2;
> ar& var3;
> }
>
> }//serialization
> }//boost
>
> which implies that serialize() *DOES* need to be namespace qualified.
With the above, you are providing a non-member function serialize overload
for your data type without modifying the class definition. That overload is
declared within the boost::serialization namespace.
> So, what's really needed?
Use intrusive when you need to access non public data and/or function
members to carry out serialization. Use non-intrusive when you can serialize
via the data type's public interface.
Jeff Flinn
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