1 #ifndef BOOST_SERIALIZATION_TRACKING_HPP
2 #define BOOST_SERIALIZATION_TRACKING_HPP
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
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)
17 // See http://www.boost.org for updates, documentation, and revision history.
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>
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>
35 namespace serialization {
39 // default tracking level
41 struct tracking_level {
43 struct traits_class_tracking {
44 typedef BOOST_DEDUCED_TYPENAME U::tracking type;
46 typedef mpl::integral_c_tag tag;
47 // note: at least one compiler complained w/o the full qualification
48 // on basic traits below
50 BOOST_DEDUCED_TYPENAME mpl::eval_if<
51 is_base_and_derived<boost::serialization::basic_traits, T>,
52 traits_class_tracking<T>,
54 BOOST_DEDUCED_TYPENAME mpl::eval_if<
56 // pointers are not tracked by default
57 mpl::int_<track_never>,
59 BOOST_DEDUCED_TYPENAME mpl::eval_if<
61 BOOST_DEDUCED_TYPENAME mpl::equal_to<
62 implementation_level<T>,
63 mpl::int_<primitive_type>
66 mpl::int_<track_never>,
67 // otherwise its selective
68 mpl::int_<track_selectivly>
70 BOOST_STATIC_CONSTANT(int, value = tracking_level::type::value);
74 template<class T, enum tracking_type L>
75 inline bool operator>=(tracking_level<T> t, enum tracking_type l)
77 return t.value >= (int)l;
80 } // namespace serialization
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
90 #define BOOST_CLASS_TRACKING(T, E) \
92 namespace serialization { \
94 struct tracking_level< T > \
96 typedef mpl::integral_c_tag tag; \
97 typedef mpl::int_< E> type; \
98 BOOST_STATIC_CONSTANT( \
100 value = tracking_level::type::value \
102 /* tracking for a class */ \
103 BOOST_STATIC_ASSERT(( \
105 /* that is a prmitive */ \
106 implementation_level< T >, \
107 mpl::int_<primitive_type> \
113 #endif // BOOST_SERIALIZATION_TRACKING_HPP