Chris@16: #ifndef BOOST_SERIALIZATION_SERIALIZATION_HPP Chris@16: #define BOOST_SERIALIZATION_SERIALIZATION_HPP Chris@16: Chris@16: // MS compatible compilers support #pragma once Chris@101: #if defined(_MSC_VER) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@101: #if defined(_MSC_VER) Chris@16: # pragma warning (disable : 4675) // suppress ADL warning Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 Chris@16: // serialization.hpp: interface for serialization system. Chris@16: Chris@16: // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // See http://www.boost.org for updates, documentation, and revision history. Chris@16: Chris@16: ////////////////////////////////////////////////////////////////////// Chris@16: // public interface to serialization. Chris@16: Chris@16: ///////////////////////////////////////////////////////////////////////////// Chris@16: // layer 0 - intrusive verison Chris@16: // declared and implemented for each user defined class to be serialized Chris@16: // Chris@16: // template Chris@16: // serialize(Archive &ar, const unsigned int file_version){ Chris@16: // ar & base_object(*this) & member1 & member2 ... ; Chris@16: // } Chris@16: Chris@16: ///////////////////////////////////////////////////////////////////////////// Chris@16: // layer 1 - layer that routes member access through the access class. Chris@16: // this is what permits us to grant access to private class member functions Chris@16: // by specifying friend class boost::serialization::access Chris@16: Chris@16: #include Chris@16: Chris@16: ///////////////////////////////////////////////////////////////////////////// Chris@16: // layer 2 - default implementation of non-intrusive serialization. Chris@16: // Chris@16: // note the usage of function overloading to compensate that C++ does not Chris@16: // currently support Partial Template Specialization for function templates Chris@16: // We have declared the version number as "const unsigned long". Chris@16: // Overriding templates for specific data types should declare the version Chris@16: // number as "const unsigned int". Template matching will first be applied Chris@16: // to functions with the same version types - that is the overloads. Chris@16: // If there is no declared function prototype that matches, the second argument Chris@16: // will be converted to "const unsigned long" and a match will be made with Chris@16: // one of the default template functions below. Chris@16: Chris@16: namespace boost { Chris@16: namespace serialization { Chris@16: Chris@16: BOOST_STRONG_TYPEDEF(unsigned int, version_type) Chris@16: Chris@16: // default implementation - call the member function "serialize" Chris@16: template Chris@16: inline void serialize( Chris@16: Archive & ar, T & t, const BOOST_PFTO unsigned int file_version Chris@16: ){ Chris@16: access::serialize(ar, t, static_cast(file_version)); Chris@16: } Chris@16: Chris@16: // save data required for construction Chris@16: template Chris@16: inline void save_construct_data( Chris@16: Archive & /*ar*/, Chris@16: const T * /*t*/, Chris@16: const BOOST_PFTO unsigned int /*file_version */ Chris@16: ){ Chris@16: // default is to save no data because default constructor Chris@16: // requires no arguments. Chris@16: } Chris@16: Chris@16: // load data required for construction and invoke constructor in place Chris@16: template Chris@16: inline void load_construct_data( Chris@16: Archive & /*ar*/, Chris@16: T * t, Chris@16: const BOOST_PFTO unsigned int /*file_version*/ Chris@16: ){ Chris@16: // default just uses the default constructor. going Chris@16: // through access permits usage of otherwise private default Chris@16: // constructor Chris@16: access::construct(t); Chris@16: } Chris@16: Chris@16: ///////////////////////////////////////////////////////////////////////////// Chris@16: // layer 3 - move call into serialization namespace so that ADL will function Chris@16: // in the manner we desire. Chris@16: // Chris@16: // on compilers which don't implement ADL. only the current namespace Chris@16: // i.e. boost::serialization will be searched. Chris@16: // Chris@16: // on compilers which DO implement ADL Chris@16: // serialize overrides can be in any of the following Chris@16: // Chris@16: // 1) same namepace as Archive Chris@16: // 2) same namespace as T Chris@16: // 3) boost::serialization Chris@16: // Chris@16: // Due to Martin Ecker Chris@16: Chris@16: template Chris@16: inline void serialize_adl( Chris@16: Archive & ar, Chris@16: T & t, Chris@16: const unsigned int file_version Chris@16: ){ Chris@16: // note usage of function overloading to delay final resolution Chris@16: // until the point of instantiation. This works around the two-phase Chris@16: // lookup "feature" which inhibits redefintion of a default function Chris@16: // template implementation. Due to Robert Ramey Chris@16: // Chris@16: // Note that this trick generates problems for compiles which don't support Chris@16: // PFTO, suppress it here. As far as we know, there are no compilers Chris@16: // which fail to support PFTO while supporting two-phase lookup. Chris@16: #if ! defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) Chris@16: const version_type v(file_version); Chris@16: serialize(ar, t, v); Chris@16: #else Chris@16: serialize(ar, t, file_version); Chris@16: #endif Chris@16: } Chris@16: Chris@16: template Chris@16: inline void save_construct_data_adl( Chris@16: Archive & ar, Chris@16: const T * t, Chris@16: const unsigned int file_version Chris@16: ){ Chris@16: // see above Chris@16: #if ! defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) Chris@16: const version_type v(file_version); Chris@16: save_construct_data(ar, t, v); Chris@16: #else Chris@16: save_construct_data(ar, t, file_version); Chris@16: #endif Chris@16: } Chris@16: Chris@16: template Chris@16: inline void load_construct_data_adl( Chris@16: Archive & ar, Chris@16: T * t, Chris@16: const unsigned int file_version Chris@16: ){ Chris@16: // see above comment Chris@16: #if ! defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) Chris@16: const version_type v(file_version); Chris@16: load_construct_data(ar, t, v); Chris@16: #else Chris@16: load_construct_data(ar, t, file_version); Chris@16: #endif Chris@16: } Chris@16: Chris@16: } // namespace serialization Chris@16: } // namespace boost Chris@16: Chris@16: #endif //BOOST_SERIALIZATION_SERIALIZATION_HPP