epoc32/include/stdapis/boost/serialization/nvp.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/serialization/nvp.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,142 @@
     1.4 +#ifndef BOOST_SERIALIZATION_NVP_HPP
     1.5 +#define BOOST_SERIALIZATION_NVP_HPP
     1.6 +
     1.7 +// MS compatible compilers support #pragma once
     1.8 +#if defined(_MSC_VER) && (_MSC_VER >= 1020)
     1.9 +# pragma once
    1.10 +#endif
    1.11 +
    1.12 +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
    1.13 +// nvp.hpp: interface for serialization system.
    1.14 +
    1.15 +// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 
    1.16 +// Use, modification and distribution is subject to the Boost Software
    1.17 +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    1.18 +// http://www.boost.org/LICENSE_1_0.txt)
    1.19 +
    1.20 +//  See http://www.boost.org for updates, documentation, and revision history.
    1.21 +
    1.22 +#include <utility>
    1.23 +
    1.24 +#include <boost/config.hpp>
    1.25 +#include <boost/detail/workaround.hpp>
    1.26 +// supress noise
    1.27 +#if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
    1.28 +# pragma warning (disable : 4786) // too long name, harmless warning
    1.29 +#endif
    1.30 +
    1.31 +#include <boost/mpl/integral_c.hpp>
    1.32 +#include <boost/mpl/integral_c_tag.hpp>
    1.33 +
    1.34 +#include <boost/serialization/level.hpp>
    1.35 +#include <boost/serialization/tracking.hpp>
    1.36 +#include <boost/serialization/split_member.hpp>
    1.37 +#include <boost/serialization/base_object.hpp>
    1.38 +#include <boost/serialization/traits.hpp>
    1.39 +
    1.40 +namespace boost {
    1.41 +namespace serialization {
    1.42 +
    1.43 +template<class T>
    1.44 +struct nvp : 
    1.45 +    public std::pair<const char *, T *>,
    1.46 +    public traits<nvp<T>, object_serializable, track_never>
    1.47 +{
    1.48 +    explicit nvp(const char * name, T & t) :
    1.49 +        // note: redundant cast works around borland issue
    1.50 +        std::pair<const char *, T *>(name, (T*)(& t))
    1.51 +    {}
    1.52 +    nvp(const nvp & rhs) : 
    1.53 +        // note: redundant cast works around borland issue
    1.54 +        std::pair<const char *, T *>(rhs.first, (T*)rhs.second)
    1.55 +    {}
    1.56 +
    1.57 +    const char * name() const {
    1.58 +        return this->first;
    1.59 +    }
    1.60 +    T & value() const {
    1.61 +        return *(this->second);
    1.62 +    }
    1.63 +
    1.64 +    const T & const_value() const {
    1.65 +        return *(this->second);
    1.66 +    }
    1.67 +
    1.68 +    // True64 compiler complains with a warning about the use of
    1.69 +    // the name "Archive" hiding some higher level usage.  I'm sure this
    1.70 +    // is an error but I want to accomodated as it generates a long warning
    1.71 +    // listing and might be related to a lot of test failures.
    1.72 +    // default treatment for name-value pairs. The name is
    1.73 +    // just discarded and only the value is serialized. 
    1.74 +    template<class Archivex>
    1.75 +    void save(
    1.76 +        Archivex & ar, 
    1.77 +        const unsigned int /* file_version */
    1.78 +    ) const {
    1.79 +        // CodeWarrior 8.x can't seem to resolve the << op for a rhs of "const T *"
    1.80 +        ar.operator<<(const_value());
    1.81 +    }
    1.82 +    template<class Archivex>
    1.83 +    void load(
    1.84 +        Archivex & ar, 
    1.85 +        const unsigned int /* file_version */
    1.86 +    ){
    1.87 +        // CodeWarrior 8.x can't seem to resolve the >> op for a rhs of "const T *"
    1.88 +        ar.operator>>(value());
    1.89 +    }
    1.90 +    BOOST_SERIALIZATION_SPLIT_MEMBER()
    1.91 +};
    1.92 +
    1.93 +template<class T>
    1.94 +inline
    1.95 +#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
    1.96 +const
    1.97 +#endif
    1.98 +nvp<T> make_nvp(const char * name, T & t){
    1.99 +    return nvp<T>(name, t);
   1.100 +}
   1.101 +
   1.102 +// to maintain efficiency and portability, we want to assign
   1.103 +// specific serialization traits to all instances of this wrappers.
   1.104 +// we can't strait forward method below as it depends upon
   1.105 +// Partial Template Specialization and doing so would mean that wrappers
   1.106 +// wouldn't be treated the same on different platforms.  This would
   1.107 +// break archive portability. Leave this here as reminder not to use it !!!
   1.108 +#if 0 // #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
   1.109 +
   1.110 +template <class T>
   1.111 +struct implementation_level<nvp<T> >
   1.112 +{
   1.113 +    typedef mpl::integral_c_tag tag;
   1.114 +    typedef mpl::int_<object_serializable> type;
   1.115 +    BOOST_STATIC_CONSTANT(int, value = implementation_level::type::value);
   1.116 +};
   1.117 +
   1.118 +// nvp objects are generally created on the stack and are never tracked
   1.119 +template<class T>
   1.120 +struct tracking_level<nvp<T> >
   1.121 +{
   1.122 +    typedef mpl::integral_c_tag tag;
   1.123 +    typedef mpl::int_<track_never> type;
   1.124 +    BOOST_STATIC_CONSTANT(int, value = tracking_level::type::value);
   1.125 +};
   1.126 +
   1.127 +#endif
   1.128 +
   1.129 +} // seralization
   1.130 +} // boost
   1.131 +
   1.132 +#include <boost/preprocessor/stringize.hpp>
   1.133 +
   1.134 +#define BOOST_SERIALIZATION_NVP(name)                              \
   1.135 +    boost::serialization::make_nvp(BOOST_PP_STRINGIZE(name), name)
   1.136 +/**/
   1.137 +
   1.138 +#define BOOST_SERIALIZATION_BASE_OBJECT_NVP(name)                  \
   1.139 +    boost::serialization::make_nvp(                                \
   1.140 +        BOOST_PP_STRINGIZE(name),                                  \
   1.141 +        boost::serialization::base_object<name >(*this)            \
   1.142 +    )
   1.143 +/**/
   1.144 +
   1.145 +#endif // BOOST_SERIALIZATION_NVP_HPP