Chris@16: #ifndef BOOST_SERIALIZATION_NVP_HPP Chris@16: #define BOOST_SERIALIZATION_NVP_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@16: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 Chris@16: // nvp.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: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace serialization { Chris@16: Chris@16: template Chris@16: struct nvp : Chris@16: public std::pair, Chris@16: public wrapper_traits > Chris@16: { Chris@16: explicit nvp(const char * name_, T & t) : Chris@16: // note: redundant cast works around borland issue Chris@16: // note: added _ to suppress useless gcc warning Chris@16: std::pair(name_, (T*)(& t)) Chris@16: {} Chris@16: nvp(const nvp & rhs) : Chris@16: // note: redundant cast works around borland issue Chris@16: std::pair(rhs.first, (T*)rhs.second) Chris@16: {} Chris@16: Chris@16: const char * name() const { Chris@16: return this->first; Chris@16: } Chris@16: T & value() const { Chris@16: return *(this->second); Chris@16: } Chris@16: Chris@16: const T & const_value() const { Chris@16: return *(this->second); Chris@16: } Chris@16: Chris@16: // True64 compiler complains with a warning about the use of Chris@16: // the name "Archive" hiding some higher level usage. I'm sure this Chris@16: // is an error but I want to accomodated as it generates a long warning Chris@16: // listing and might be related to a lot of test failures. Chris@16: // default treatment for name-value pairs. The name is Chris@16: // just discarded and only the value is serialized. Chris@16: template Chris@16: void save( Chris@16: Archivex & ar, Chris@16: const unsigned int /* file_version */ Chris@16: ) const { Chris@16: // CodeWarrior 8.x can't seem to resolve the << op for a rhs of "const T *" Chris@16: ar.operator<<(const_value()); Chris@16: } Chris@16: template Chris@16: void load( Chris@16: Archivex & ar, Chris@16: const unsigned int /* file_version */ Chris@16: ){ Chris@16: // CodeWarrior 8.x can't seem to resolve the >> op for a rhs of "const T *" Chris@16: ar.operator>>(value()); Chris@16: } Chris@16: BOOST_SERIALIZATION_SPLIT_MEMBER() Chris@16: }; Chris@16: Chris@16: template Chris@16: inline Chris@16: #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING Chris@16: const Chris@16: #endif Chris@16: nvp< T > make_nvp(const char * name, T & t){ Chris@16: return nvp< T >(name, t); Chris@16: } Chris@16: Chris@16: // to maintain efficiency and portability, we want to assign Chris@16: // specific serialization traits to all instances of this wrappers. Chris@16: // we can't strait forward method below as it depends upon Chris@16: // Partial Template Specialization and doing so would mean that wrappers Chris@16: // wouldn't be treated the same on different platforms. This would Chris@16: // break archive portability. Leave this here as reminder not to use it !!! Chris@16: Chris@16: template Chris@16: struct implementation_level > Chris@16: { Chris@16: typedef mpl::integral_c_tag tag; Chris@16: typedef mpl::int_ type; Chris@16: BOOST_STATIC_CONSTANT(int, value = implementation_level::type::value); Chris@16: }; Chris@16: Chris@16: // nvp objects are generally created on the stack and are never tracked Chris@16: template Chris@16: struct tracking_level > Chris@16: { Chris@16: typedef mpl::integral_c_tag tag; Chris@16: typedef mpl::int_ type; Chris@16: BOOST_STATIC_CONSTANT(int, value = tracking_level::type::value); Chris@16: }; Chris@16: Chris@16: Chris@16: } // seralization Chris@16: } // boost Chris@16: Chris@16: #include Chris@16: Chris@16: #define BOOST_SERIALIZATION_NVP(name) \ Chris@16: boost::serialization::make_nvp(BOOST_PP_STRINGIZE(name), name) Chris@16: /**/ Chris@16: Chris@16: #define BOOST_SERIALIZATION_BASE_OBJECT_NVP(name) \ Chris@16: boost::serialization::make_nvp( \ Chris@16: BOOST_PP_STRINGIZE(name), \ Chris@16: boost::serialization::base_object(*this) \ Chris@16: ) Chris@16: /**/ Chris@16: Chris@16: #endif // BOOST_SERIALIZATION_NVP_HPP