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