Intrusive and External Serialization
The simplest and most efficient way to serialize your classes is intrusive serialization, where you build serialization directly into your objects. Deriving from a single root class is not required.
For existing classes that you cannot modify, you can implement external serialization. This kind of serialization uses pseudo-polymorphism to add polymorphic streaming operators to a preexisting class hierarchy.
Intrusive serialization uses a direct call to the
streamContents() virtual member function. It also gives the
streamContents() function direct access to private data members, which avoids the possible side effects or overhead of using public accessor functions.
External serialization uses a hash table to locate its
streamContents() function.
The Serialization package includes macros for both styles of serialization. See
Using the Stream Contents Macros.