1 #ifndef BOOST_ARCHIVE_DETAIL_CHECK_HPP
2 #define BOOST_ARCHIVE_DETAIL_CHECK_HPP
4 // MS compatible compilers support #pragma once
7 #pragma inline_depth(511)
8 #pragma inline_recursion(on)
11 #if defined(__MWERKS__)
12 #pragma inline_depth(511)
15 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
16 // check.hpp: interface for serialization system.
18 // (C) Copyright 2009 Robert Ramey - http://www.rrsd.com .
19 // Use, modification and distribution is subject to the Boost Software
20 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
21 // http://www.boost.org/LICENSE_1_0.txt)
23 // See http://www.boost.org for updates, documentation, and revision history.
25 #include <boost/config.hpp>
27 #include <boost/static_assert.hpp>
28 #include <boost/type_traits/is_const.hpp>
30 #include <boost/mpl/eval_if.hpp>
31 #include <boost/mpl/or.hpp>
32 #include <boost/mpl/equal_to.hpp>
33 #include <boost/mpl/int.hpp>
34 #include <boost/mpl/not.hpp>
35 #include <boost/mpl/greater.hpp>
36 #include <boost/mpl/assert.hpp>
38 #include <boost/serialization/static_warning.hpp>
39 #include <boost/serialization/version.hpp>
40 #include <boost/serialization/level.hpp>
41 #include <boost/serialization/tracking.hpp>
42 #include <boost/serialization/wrapper.hpp>
51 inline void check_object_level(){
53 typename mpl::greater_equal<
54 serialization::implementation_level< T >,
55 mpl::int_<serialization::primitive_type>
58 // trap attempts to serialize objects marked
60 BOOST_STATIC_ASSERT(typex::value);
64 inline void check_object_versioning(){
67 typename mpl::greater<
68 serialization::implementation_level< T >,
69 mpl::int_<serialization::object_serializable>
71 typename mpl::equal_to<
72 serialization::version< T >,
76 // trap attempts to serialize with objects that don't
77 // save class information in the archive with versioning.
78 BOOST_STATIC_ASSERT(typex::value);
82 inline void check_object_tracking(){
83 // presume it has already been determined that
85 BOOST_STATIC_ASSERT(! boost::is_const< T >::value);
86 typedef typename mpl::equal_to<
87 serialization::tracking_level< T >,
88 mpl::int_<serialization::track_never>
90 // saving an non-const object of a type not marked "track_never)
92 // may be an indicator of an error usage of the
93 // serialization library and should be double checked.
94 // See documentation on object tracking. Also, see the
95 // "rationale" section of the documenation
96 // for motivation for this checking.
98 BOOST_STATIC_WARNING(typex::value);
101 // checks for pointers
104 inline void check_pointer_level(){
105 // we should only invoke this once we KNOW that T
106 // has been used as a pointer!!
109 typename mpl::greater<
110 serialization::implementation_level< T >,
111 mpl::int_<serialization::object_serializable>
114 typename mpl::equal_to<
115 serialization::tracking_level< T >,
116 mpl::int_<serialization::track_selectively>
120 // Address the following when serializing to a pointer:
122 // a) This type doesn't save class information in the
123 // archive. That is, the serialization trait implementation
124 // level <= object_serializable.
125 // b) Tracking for this type is set to "track selectively"
127 // in this case, indication that an object is tracked is
128 // not stored in the archive itself - see level == object_serializable
129 // but rather the existence of the operation ar >> T * is used to
130 // infer that an object of this type should be tracked. So, if
131 // you save via a pointer but don't load via a pointer the operation
132 // will fail on load without given any valid reason for the failure.
134 // So if your program traps here, consider changing the
135 // tracking or implementation level traits - or not
136 // serializing via a pointer.
137 BOOST_STATIC_WARNING(typex::value);
141 void inline check_pointer_tracking(){
142 typedef typename mpl::greater<
143 serialization::tracking_level< T >,
144 mpl::int_<serialization::track_never>
146 // serializing an object of a type marked "track_never" through a pointer
147 // could result in creating more objects than were saved!
148 BOOST_STATIC_WARNING(typex::value);
152 inline void check_const_loading(){
155 typename boost::serialization::is_wrapper< T >,
157 typename boost::is_const< T >
160 // cannot load data into a "const" object unless it's a
161 // wrapper around some other non-const object.
162 BOOST_STATIC_ASSERT(typex::value);
169 #endif // BOOST_ARCHIVE_DETAIL_CHECK_HPP