1 #ifndef BOOST_ARCHIVE_BASIC_ARCHIVE_HPP
2 #define BOOST_ARCHIVE_BASIC_ARCHIVE_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 // basic_archive.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 #include <cstring> // count
19 #include <boost/assert.hpp>
20 #include <boost/config.hpp>
21 #include <boost/cstdint.hpp> // size_t
22 #include <boost/noncopyable.hpp>
23 #include <boost/integer_traits.hpp>
24 
25 #include <boost/archive/detail/auto_link_archive.hpp>
26 #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
27 
28 namespace boost {
29 namespace archive {
30 
31 #if defined(_MSC_VER)
32 #pragma warning( push )
33 #pragma warning( disable : 4244 4267 )
34 #endif
35 
36 /* NOTE : Warning  : Warning : Warning : Warning : Warning
37  * Don't ever changes this.  If you do, they previously created
38  * binary archives won't be readable !!!
39  */
40 class library_version_type {
41 private:
42     typedef uint_least16_t base_type;
43     base_type t;
44 public:
library_version_type()45     library_version_type(): t(0) {};
library_version_type(const unsigned int & t_)46     explicit library_version_type(const unsigned int & t_) : t(t_){
47         BOOST_ASSERT(t_ <= boost::integer_traits<base_type>::const_max);
48     }
library_version_type(const library_version_type & t_)49     library_version_type(const library_version_type & t_) :
50         t(t_.t)
51     {}
operator =(const library_version_type & rhs)52     library_version_type & operator=(const library_version_type & rhs){
53         t = rhs.t;
54         return *this;
55     }
56     // used for text output
operator base_type() const57     operator base_type () const {
58         return t;
59     }
60     // used for text input
operator base_type&()61     operator base_type & (){
62         return t;
63     }
operator ==(const library_version_type & rhs) const64     bool operator==(const library_version_type & rhs) const {
65         return t == rhs.t;
66     }
operator <(const library_version_type & rhs) const67     bool operator<(const library_version_type & rhs) const {
68         return t < rhs.t;
69     }
70 };
71 
72 BOOST_ARCHIVE_DECL library_version_type
73 BOOST_ARCHIVE_VERSION();
74 
75 class version_type {
76 private:
77     typedef uint_least32_t base_type;
78     base_type t;
79 public:
80     // should be private - but MPI fails if it's not!!!
version_type()81     version_type(): t(0) {};
version_type(const unsigned int & t_)82     explicit version_type(const unsigned int & t_) : t(t_){
83         BOOST_ASSERT(t_ <= boost::integer_traits<base_type>::const_max);
84     }
version_type(const version_type & t_)85     version_type(const version_type & t_) :
86         t(t_.t)
87     {}
operator =(const version_type & rhs)88     version_type & operator=(const version_type & rhs){
89         t = rhs.t;
90         return *this;
91     }
92     // used for text output
operator base_type() const93     operator base_type () const {
94         return t;
95     }
96     // used for text intput
operator base_type&()97     operator base_type  & (){
98         return t;
99     }
operator ==(const version_type & rhs) const100     bool operator==(const version_type & rhs) const {
101         return t == rhs.t;
102     }
operator <(const version_type & rhs) const103     bool operator<(const version_type & rhs) const {
104         return t < rhs.t;
105     }
106 };
107 
108 class class_id_type {
109 private:
110     typedef int_least16_t base_type;
111     base_type t;
112 public:
113     // should be private - but then can't use BOOST_STRONG_TYPE below
class_id_type()114     class_id_type() : t(0) {};
class_id_type(const int t_)115     explicit class_id_type(const int t_) : t(t_){
116         BOOST_ASSERT(t_ <= boost::integer_traits<base_type>::const_max);
117     }
class_id_type(const std::size_t t_)118     explicit class_id_type(const std::size_t t_) : t(t_){
119  //       BOOST_ASSERT(t_ <= boost::integer_traits<base_type>::const_max);
120     }
class_id_type(const class_id_type & t_)121     class_id_type(const class_id_type & t_) :
122         t(t_.t)
123     {}
operator =(const class_id_type & rhs)124     class_id_type & operator=(const class_id_type & rhs){
125         t = rhs.t;
126         return *this;
127     }
128 
129     // used for text output
operator base_type() const130     operator base_type () const {
131         return t;
132     }
133     // used for text input
operator base_type&()134     operator base_type &() {
135         return t;
136     }
operator ==(const class_id_type & rhs) const137     bool operator==(const class_id_type & rhs) const {
138         return t == rhs.t;
139     }
operator <(const class_id_type & rhs) const140     bool operator<(const class_id_type & rhs) const {
141         return t < rhs.t;
142     }
143 };
144 
145 #define NULL_POINTER_TAG boost::archive::class_id_type(-1)
146 
147 class object_id_type {
148 private:
149     typedef uint_least32_t base_type;
150     base_type t;
151 public:
object_id_type()152     object_id_type(): t(0) {};
153     // note: presumes that size_t >= unsigned int.
154     // use explicit cast to silence useless warning
object_id_type(const std::size_t & t_)155     explicit object_id_type(const std::size_t & t_) : t(static_cast<base_type>(t_)){
156         // make quadriple sure that we haven't lost any real integer
157         // precision
158         BOOST_ASSERT(t_ <= boost::integer_traits<base_type>::const_max);
159     }
object_id_type(const object_id_type & t_)160     object_id_type(const object_id_type & t_) :
161         t(t_.t)
162     {}
operator =(const object_id_type & rhs)163     object_id_type & operator=(const object_id_type & rhs){
164         t = rhs.t;
165         return *this;
166     }
167     // used for text output
operator base_type() const168     operator base_type () const {
169         return t;
170     }
171     // used for text input
operator base_type&()172     operator base_type & () {
173         return t;
174     }
operator ==(const object_id_type & rhs) const175     bool operator==(const object_id_type & rhs) const {
176         return t == rhs.t;
177     }
operator <(const object_id_type & rhs) const178     bool operator<(const object_id_type & rhs) const {
179         return t < rhs.t;
180     }
181 };
182 
183 #if defined(_MSC_VER)
184 #pragma warning( pop )
185 #endif
186 
187 struct tracking_type {
188     bool t;
tracking_typeboost::archive::tracking_type189     explicit tracking_type(const bool t_ = false)
190         : t(t_)
191     {};
tracking_typeboost::archive::tracking_type192     tracking_type(const tracking_type & t_)
193         : t(t_.t)
194     {}
operator boolboost::archive::tracking_type195     operator bool () const {
196         return t;
197     };
operator bool&boost::archive::tracking_type198     operator bool & () {
199         return t;
200     };
operator =boost::archive::tracking_type201     tracking_type & operator=(const bool t_){
202         t = t_;
203         return *this;
204     }
operator ==boost::archive::tracking_type205     bool operator==(const tracking_type & rhs) const {
206         return t == rhs.t;
207     }
operator ==boost::archive::tracking_type208     bool operator==(const bool & rhs) const {
209         return t == rhs;
210     }
operator =boost::archive::tracking_type211     tracking_type & operator=(const tracking_type & rhs){
212         t = rhs.t;
213         return *this;
214     }
215 };
216 
217 struct class_name_type :
218     private boost::noncopyable
219 {
220     char *t;
operator const char*&boost::archive::class_name_type221     operator const char * & () const {
222         return const_cast<const char * &>(t);
223     }
operator char*boost::archive::class_name_type224     operator char * () {
225         return t;
226     }
sizeboost::archive::class_name_type227     std::size_t size() const {
228         return std::strlen(t);
229     }
class_name_typeboost::archive::class_name_type230     explicit class_name_type(const char *key_)
231     : t(const_cast<char *>(key_)){}
class_name_typeboost::archive::class_name_type232     explicit class_name_type(char *key_)
233     : t(key_){}
operator =boost::archive::class_name_type234     class_name_type & operator=(const class_name_type & rhs){
235         t = rhs.t;
236         return *this;
237     }
238 };
239 
240 enum archive_flags {
241     no_header = 1,  // suppress archive header info
242     no_codecvt = 2,  // suppress alteration of codecvt facet
243     no_xml_tag_checking = 4,   // suppress checking of xml tags
244     no_tracking = 8,           // suppress ALL tracking
245     flags_last = 8
246 };
247 
248 BOOST_ARCHIVE_DECL const char *
249 BOOST_ARCHIVE_SIGNATURE();
250 
251 /* NOTE : Warning  : Warning : Warning : Warning : Warning
252  * If any of these are changed to different sized types,
253  * binary_iarchive won't be able to read older archives
254  * unless you rev the library version and include conditional
255  * code based on the library version.  There is nothing
256  * inherently wrong in doing this - but you have to be super
257  * careful because it's easy to get wrong and start breaking
258  * old archives !!!
259  */
260 
261 #define BOOST_ARCHIVE_STRONG_TYPEDEF(T, D)         \
262     class D : public T {                           \
263     public:                                        \
264         explicit D(const T tt) : T(tt){}           \
265     };                                             \
266 /**/
267 
268 BOOST_ARCHIVE_STRONG_TYPEDEF(class_id_type, class_id_reference_type)
269 BOOST_ARCHIVE_STRONG_TYPEDEF(class_id_type, class_id_optional_type)
270 BOOST_ARCHIVE_STRONG_TYPEDEF(object_id_type, object_reference_type)
271 
272 }// namespace archive
273 }// namespace boost
274 
275 #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
276 
277 #include <boost/serialization/level.hpp>
278 
279 // set implementation level to primitive for all types
280 // used internally by the serialization library
281 
282 BOOST_CLASS_IMPLEMENTATION(boost::archive::library_version_type, primitive_type)
283 BOOST_CLASS_IMPLEMENTATION(boost::archive::version_type, primitive_type)
284 BOOST_CLASS_IMPLEMENTATION(boost::archive::class_id_type, primitive_type)
285 BOOST_CLASS_IMPLEMENTATION(boost::archive::class_id_reference_type, primitive_type)
286 BOOST_CLASS_IMPLEMENTATION(boost::archive::class_id_optional_type, primitive_type)
287 BOOST_CLASS_IMPLEMENTATION(boost::archive::class_name_type, primitive_type)
288 BOOST_CLASS_IMPLEMENTATION(boost::archive::object_id_type, primitive_type)
289 BOOST_CLASS_IMPLEMENTATION(boost::archive::object_reference_type, primitive_type)
290 BOOST_CLASS_IMPLEMENTATION(boost::archive::tracking_type, primitive_type)
291 
292 #include <boost/serialization/is_bitwise_serializable.hpp>
293 
294 // set types used internally by the serialization library
295 // to be bitwise serializable
296 
297 BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::library_version_type)
298 BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::version_type)
299 BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::class_id_type)
300 BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::class_id_reference_type)
301 BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::class_id_optional_type)
302 BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::class_name_type)
303 BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::object_id_type)
304 BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::object_reference_type)
305 BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::tracking_type)
306 
307 #endif //BOOST_ARCHIVE_BASIC_ARCHIVE_HPP
308