os/ossrv/ossrv_pub/boost_apis/boost/serialization/tracking.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
#ifndef BOOST_SERIALIZATION_TRACKING_HPP
sl@0
     2
#define BOOST_SERIALIZATION_TRACKING_HPP
sl@0
     3
sl@0
     4
// MS compatible compilers support #pragma once
sl@0
     5
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
sl@0
     6
# pragma once
sl@0
     7
#endif
sl@0
     8
sl@0
     9
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
sl@0
    10
// tracking.hpp:
sl@0
    11
sl@0
    12
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 
sl@0
    13
// Use, modification and distribution is subject to the Boost Software
sl@0
    14
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
sl@0
    15
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
    16
sl@0
    17
//  See http://www.boost.org for updates, documentation, and revision history.
sl@0
    18
sl@0
    19
#include <boost/config.hpp>
sl@0
    20
#include <boost/static_assert.hpp>
sl@0
    21
#include <boost/mpl/eval_if.hpp>
sl@0
    22
#include <boost/mpl/identity.hpp>
sl@0
    23
#include <boost/mpl/int.hpp>
sl@0
    24
#include <boost/mpl/equal_to.hpp>
sl@0
    25
#include <boost/mpl/greater.hpp>
sl@0
    26
#include <boost/mpl/integral_c_tag.hpp>
sl@0
    27
sl@0
    28
#include <boost/type_traits/is_base_and_derived.hpp>
sl@0
    29
#include <boost/type_traits/is_pointer.hpp>
sl@0
    30
#include <boost/serialization/level.hpp>
sl@0
    31
#include <boost/serialization/tracking_enum.hpp>
sl@0
    32
//#include <boost/serialization/traits.hpp>
sl@0
    33
sl@0
    34
namespace boost {
sl@0
    35
namespace serialization {
sl@0
    36
sl@0
    37
struct basic_traits;
sl@0
    38
sl@0
    39
// default tracking level
sl@0
    40
template<class T>
sl@0
    41
struct tracking_level {
sl@0
    42
    template<class U>
sl@0
    43
    struct traits_class_tracking {
sl@0
    44
        typedef BOOST_DEDUCED_TYPENAME U::tracking type;
sl@0
    45
    };
sl@0
    46
    typedef mpl::integral_c_tag tag;
sl@0
    47
    // note: at least one compiler complained w/o the full qualification
sl@0
    48
    // on basic traits below
sl@0
    49
    typedef
sl@0
    50
        BOOST_DEDUCED_TYPENAME mpl::eval_if<
sl@0
    51
            is_base_and_derived<boost::serialization::basic_traits, T>,
sl@0
    52
            traits_class_tracking<T>,
sl@0
    53
        //else
sl@0
    54
        BOOST_DEDUCED_TYPENAME mpl::eval_if<
sl@0
    55
            is_pointer<T>,
sl@0
    56
            // pointers are not tracked by default
sl@0
    57
            mpl::int_<track_never>,
sl@0
    58
        //else
sl@0
    59
        BOOST_DEDUCED_TYPENAME mpl::eval_if<
sl@0
    60
            // for primitives
sl@0
    61
            BOOST_DEDUCED_TYPENAME mpl::equal_to<
sl@0
    62
                implementation_level<T>,
sl@0
    63
                mpl::int_<primitive_type> 
sl@0
    64
            >,
sl@0
    65
            // is never
sl@0
    66
            mpl::int_<track_never>,
sl@0
    67
            // otherwise its selective
sl@0
    68
            mpl::int_<track_selectivly>
sl@0
    69
    >  > >::type type;
sl@0
    70
    BOOST_STATIC_CONSTANT(int, value = tracking_level::type::value);
sl@0
    71
};
sl@0
    72
sl@0
    73
sl@0
    74
template<class T, enum tracking_type L>
sl@0
    75
inline bool operator>=(tracking_level<T> t, enum tracking_type l)
sl@0
    76
{
sl@0
    77
    return t.value >= (int)l;
sl@0
    78
}
sl@0
    79
sl@0
    80
} // namespace serialization
sl@0
    81
} // namespace boost
sl@0
    82
sl@0
    83
sl@0
    84
// The STATIC_ASSERT is prevents one from setting tracking for a primitive type.  
sl@0
    85
// This almost HAS to be an error.  Doing this will effect serialization of all 
sl@0
    86
// char's in your program which is almost certainly what you don't want to do.  
sl@0
    87
// If you want to track all instances of a given primitive type, You'll have to 
sl@0
    88
// wrap it in your own type so its not a primitive anymore.  Then it will compile
sl@0
    89
// without problem.
sl@0
    90
#define BOOST_CLASS_TRACKING(T, E)           \
sl@0
    91
namespace boost {                            \
sl@0
    92
namespace serialization {                    \
sl@0
    93
template<>                                   \
sl@0
    94
struct tracking_level< T >                   \
sl@0
    95
{                                            \
sl@0
    96
    typedef mpl::integral_c_tag tag;         \
sl@0
    97
    typedef mpl::int_< E> type;              \
sl@0
    98
    BOOST_STATIC_CONSTANT(                   \
sl@0
    99
        int,                                 \
sl@0
   100
        value = tracking_level::type::value  \
sl@0
   101
    );                                       \
sl@0
   102
    /* tracking for a class  */              \
sl@0
   103
    BOOST_STATIC_ASSERT((                    \
sl@0
   104
        mpl::greater<                        \
sl@0
   105
            /* that is a prmitive */         \
sl@0
   106
            implementation_level< T >,       \
sl@0
   107
            mpl::int_<primitive_type>        \
sl@0
   108
        >::value                             \
sl@0
   109
    ));                                      \
sl@0
   110
};                                           \
sl@0
   111
}}
sl@0
   112
sl@0
   113
#endif // BOOST_SERIALIZATION_TRACKING_HPP