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

source code of boost/boost/serialization/tracking.hpp