|
SerializationCode Structure |
namespace
of classes and templates is synchronized
with the directory in which the file is found. For example, the class declaration
boost::archive::text_oarchive
is included with the following declaration
#include <boost/archive/text_oarchive.hpp>
By convention these header files are named: boost/serialization/xxx.hpp where xxx is the name of the header file which contains the type to be serialized. For example, the declaration
#include <boost/serialization/list.hpp>
includes the code to implement serialization of the STL
std::list
type. While
#include <boost/serialization/shared_ptr.hpp>
includes code to implement serialization of the BOOST boost::shared_ptr
type.
Note that including the serialization header for a type automatically includes the
appropriate header of the type to be serialized.
As of this writing, the library includes templates of all STL library templates as well
as templates for boost::optional
,
boost::shared_ptr
, and
boost::scoped_ptr
.
Presumably, this list will expand with the passage of time.
class_id_type
and others to
record information in archives that is required to reconstruct the original
data structure. These are handled exactly as any other serializable type.
That is, they can be handled as simple primitives such as they are in simple
text files, or with special code as they are in xml archives.
basic_xml_oarchive.hpp
includes code to guarantee that any object not attached to a name will
trap during compile time. On the other hand, basic_text_oarchive.hpp
contains code to strip out and ingore any names attached to objects.
The following discussion is based on the class diagram.
save_override
in the most derived
archive class.
save_override
is declared and implemented in each class in
the archive hierarchy.
template
void save_override(T & t, BOOST_PFTO int){
// All for otherwise unhandled types are forwarded to the base class.
// This emulates behavior for function overloading.
this->base::save_override(t, 0);
}
void save_override(const some_type & t, int){
// any special handling for some type
// this will usually entail forwarding some other operation
// in the most derived class.
this->This()->...
// or in one of its parents basic_text_oprimitive
this->This()->save(static_cast<int>(t));
}
... // other special type handling
Note the usage of
Partial Function Template Ordering
to permit the correct save implementation to be selected.
The trade offs related to library implementation via pre-compiled code and templated headers are well known. This library uses both. It uses templated headers to generate code to serialize user and primitive types and it uses pre-compiled library code for that part of the code which only depends upon the archive type. Building of the library generates and compiles code for all archives implemented.
This is a ripe topic in itself. It's touched upon by the boost iterator libraries, View Template Library, and others.
The code for these iterators is really independent of this library. But since it hasn't been and probably won't be reviewed outside of this context. I've left it in a directory local to the serialization library: boost/archive/iterators. These iterators are described in Dataflow Iterators.
© Copyright Robert Ramey 2002-2004. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)