williamr@2: #ifndef BOOST_SERIALIZATION_NVP_HPP williamr@2: #define BOOST_SERIALIZATION_NVP_HPP williamr@2: williamr@2: // MS compatible compilers support #pragma once williamr@2: #if defined(_MSC_VER) && (_MSC_VER >= 1020) williamr@2: # pragma once williamr@2: #endif williamr@2: williamr@2: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 williamr@2: // nvp.hpp: interface for serialization system. williamr@2: williamr@2: // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . williamr@2: // Use, modification and distribution is subject to the Boost Software williamr@2: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at williamr@2: // http://www.boost.org/LICENSE_1_0.txt) williamr@2: williamr@2: // See http://www.boost.org for updates, documentation, and revision history. williamr@2: williamr@2: #include williamr@2: williamr@2: #include williamr@2: #include williamr@2: // supress noise williamr@2: #if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) williamr@2: # pragma warning (disable : 4786) // too long name, harmless warning williamr@2: #endif williamr@2: williamr@2: #include williamr@2: #include williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: namespace boost { williamr@2: namespace serialization { williamr@2: williamr@2: template williamr@2: struct nvp : williamr@2: public std::pair, williamr@2: public traits, object_serializable, track_never> williamr@2: { williamr@2: explicit nvp(const char * name, T & t) : williamr@2: // note: redundant cast works around borland issue williamr@2: std::pair(name, (T*)(& t)) williamr@2: {} williamr@2: nvp(const nvp & rhs) : williamr@2: // note: redundant cast works around borland issue williamr@2: std::pair(rhs.first, (T*)rhs.second) williamr@2: {} williamr@2: williamr@2: const char * name() const { williamr@2: return this->first; williamr@2: } williamr@2: T & value() const { williamr@2: return *(this->second); williamr@2: } williamr@2: williamr@2: const T & const_value() const { williamr@2: return *(this->second); williamr@2: } williamr@2: williamr@2: // True64 compiler complains with a warning about the use of williamr@2: // the name "Archive" hiding some higher level usage. I'm sure this williamr@2: // is an error but I want to accomodated as it generates a long warning williamr@2: // listing and might be related to a lot of test failures. williamr@2: // default treatment for name-value pairs. The name is williamr@2: // just discarded and only the value is serialized. williamr@2: template williamr@2: void save( williamr@2: Archivex & ar, williamr@2: const unsigned int /* file_version */ williamr@2: ) const { williamr@2: // CodeWarrior 8.x can't seem to resolve the << op for a rhs of "const T *" williamr@2: ar.operator<<(const_value()); williamr@2: } williamr@2: template williamr@2: void load( williamr@2: Archivex & ar, williamr@2: const unsigned int /* file_version */ williamr@2: ){ williamr@2: // CodeWarrior 8.x can't seem to resolve the >> op for a rhs of "const T *" williamr@2: ar.operator>>(value()); williamr@2: } williamr@2: BOOST_SERIALIZATION_SPLIT_MEMBER() williamr@2: }; williamr@2: williamr@2: template williamr@2: inline williamr@2: #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING williamr@2: const williamr@2: #endif williamr@2: nvp make_nvp(const char * name, T & t){ williamr@2: return nvp(name, t); williamr@2: } williamr@2: williamr@2: // to maintain efficiency and portability, we want to assign williamr@2: // specific serialization traits to all instances of this wrappers. williamr@2: // we can't strait forward method below as it depends upon williamr@2: // Partial Template Specialization and doing so would mean that wrappers williamr@2: // wouldn't be treated the same on different platforms. This would williamr@2: // break archive portability. Leave this here as reminder not to use it !!! williamr@2: #if 0 // #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION williamr@2: williamr@2: template williamr@2: struct implementation_level > williamr@2: { williamr@2: typedef mpl::integral_c_tag tag; williamr@2: typedef mpl::int_ type; williamr@2: BOOST_STATIC_CONSTANT(int, value = implementation_level::type::value); williamr@2: }; williamr@2: williamr@2: // nvp objects are generally created on the stack and are never tracked williamr@2: template williamr@2: struct tracking_level > williamr@2: { williamr@2: typedef mpl::integral_c_tag tag; williamr@2: typedef mpl::int_ type; williamr@2: BOOST_STATIC_CONSTANT(int, value = tracking_level::type::value); williamr@2: }; williamr@2: williamr@2: #endif williamr@2: williamr@2: } // seralization williamr@2: } // boost williamr@2: williamr@2: #include williamr@2: williamr@2: #define BOOST_SERIALIZATION_NVP(name) \ williamr@2: boost::serialization::make_nvp(BOOST_PP_STRINGIZE(name), name) williamr@2: /**/ williamr@2: williamr@2: #define BOOST_SERIALIZATION_BASE_OBJECT_NVP(name) \ williamr@2: boost::serialization::make_nvp( \ williamr@2: BOOST_PP_STRINGIZE(name), \ williamr@2: boost::serialization::base_object(*this) \ williamr@2: ) williamr@2: /**/ williamr@2: williamr@2: #endif // BOOST_SERIALIZATION_NVP_HPP