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) && (_MSC_VER >= 1020)
|
---|
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/traits.hpp>
|
---|
31 | #include <boost/serialization/level.hpp>
|
---|
32 | #include <boost/serialization/tracking_enum.hpp>
|
---|
33 |
|
---|
34 | namespace boost {
|
---|
35 | namespace serialization {
|
---|
36 |
|
---|
37 | // default tracking level
|
---|
38 | template<class T>
|
---|
39 | struct tracking_level {
|
---|
40 | template<class U>
|
---|
41 | struct traits_class_tracking {
|
---|
42 | typedef BOOST_DEDUCED_TYPENAME U::tracking type;
|
---|
43 | };
|
---|
44 | typedef mpl::integral_c_tag tag;
|
---|
45 | typedef
|
---|
46 | BOOST_DEDUCED_TYPENAME mpl::eval_if<
|
---|
47 | is_base_and_derived<basic_traits, T>,
|
---|
48 | traits_class_tracking<T>,
|
---|
49 | //else
|
---|
50 | BOOST_DEDUCED_TYPENAME mpl::eval_if<
|
---|
51 | is_pointer<T>,
|
---|
52 | // pointers are not tracked by default
|
---|
53 | mpl::int_<track_never>,
|
---|
54 | //else
|
---|
55 | BOOST_DEDUCED_TYPENAME mpl::eval_if<
|
---|
56 | // for primitives
|
---|
57 | BOOST_DEDUCED_TYPENAME mpl::equal_to<
|
---|
58 | implementation_level<T>,
|
---|
59 | mpl::int_<primitive_type>
|
---|
60 | >,
|
---|
61 | // is never
|
---|
62 | mpl::int_<track_never>,
|
---|
63 | // otherwise its selective
|
---|
64 | mpl::int_<track_selectivly>
|
---|
65 | > > >::type type;
|
---|
66 | BOOST_STATIC_CONSTANT(int, value = tracking_level::type::value);
|
---|
67 | };
|
---|
68 |
|
---|
69 |
|
---|
70 | template<class T, enum tracking_type L>
|
---|
71 | inline bool operator>=(tracking_level<T> t, enum tracking_type l)
|
---|
72 | {
|
---|
73 | return t.value >= (int)l;
|
---|
74 | }
|
---|
75 |
|
---|
76 | } // namespace serialization
|
---|
77 | } // namespace boost
|
---|
78 |
|
---|
79 |
|
---|
80 | // The STATIC_ASSERT is prevents one from setting tracking for a primitive type.
|
---|
81 | // This almost HAS to be an error. Doing this will effect serialization of all
|
---|
82 | // char's in your program which is almost certainly what you don't want to do.
|
---|
83 | // If you want to track all instances of a given primitive type, You'll have to
|
---|
84 | // wrap it in your own type so its not a primitive anymore. Then it will compile
|
---|
85 | // without problem.
|
---|
86 | #define BOOST_CLASS_TRACKING(T, E) \
|
---|
87 | namespace boost { \
|
---|
88 | namespace serialization { \
|
---|
89 | template<> \
|
---|
90 | struct tracking_level< T > \
|
---|
91 | { \
|
---|
92 | typedef mpl::integral_c_tag tag; \
|
---|
93 | typedef mpl::int_< E> type; \
|
---|
94 | BOOST_STATIC_CONSTANT( \
|
---|
95 | int, \
|
---|
96 | value = tracking_level::type::value \
|
---|
97 | ); \
|
---|
98 | /* tracking for a class */ \
|
---|
99 | BOOST_STATIC_ASSERT(( \
|
---|
100 | mpl::greater< \
|
---|
101 | /* that is a prmitive */ \
|
---|
102 | implementation_level< T >, \
|
---|
103 | mpl::int_<primitive_type> \
|
---|
104 | >::value \
|
---|
105 | )); \
|
---|
106 | }; \
|
---|
107 | }}
|
---|
108 |
|
---|
109 | #endif // BOOST_SERIALIZATION_TRACKING_HPP
|
---|