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