Namespaces for Intrusive Serialization?
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). 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) { ar& var1; ar& var2; ar& var3; } }//serialization }//boost which implies that serialize() *DOES* need to be namespace qualified. So, what's really needed? Merrill
"Merrill Cornish"
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
The concept of namespace isn't really applicable to member functions. Member functions are invoked the syntax. object.member_function(...) The member function will be invoked regardless of the namespace the object might have been delcared in. non-member functions behave according to namespace rules as you expect. Robert Ramey Merrill Cornish wrote:
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).
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) { ar& var1; ar& var2; ar& var3; }
}//serialization }//boost
which implies that serialize() *DOES* need to be namespace qualified.
So, what's really needed?
Merrill
participants (3)
-
Jeff Flinn
-
Merrill Cornish
-
Robert Ramey