1
0

basic_archive.hpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. #ifndef BOOST_ARCHIVE_BASIC_ARCHIVE_HPP
  2. #define BOOST_ARCHIVE_BASIC_ARCHIVE_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // basic_archive.hpp:
  9. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  10. // Use, modification and distribution is subject to the Boost Software
  11. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. // See http://www.boost.org for updates, documentation, and revision history.
  14. #include <boost/assert.hpp>
  15. #include <boost/config.hpp>
  16. #include <boost/cstdint.hpp> // size_t
  17. #include <boost/noncopyable.hpp>
  18. #include <boost/integer_traits.hpp>
  19. #include <boost/archive/detail/auto_link_archive.hpp>
  20. #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
  21. namespace boost {
  22. namespace archive {
  23. #if defined(_MSC_VER)
  24. #pragma warning( push )
  25. #pragma warning( disable : 4244 4267 )
  26. #endif
  27. /* NOTE : Warning : Warning : Warning : Warning : Warning
  28. * Don't ever changes this. If you do, they previously created
  29. * binary archives won't be readable !!!
  30. */
  31. class library_version_type {
  32. private:
  33. typedef uint_least16_t base_type;
  34. base_type t;
  35. public:
  36. library_version_type(): t(0) {};
  37. explicit library_version_type(const unsigned int & t_) : t(t_){
  38. BOOST_ASSERT(t_ <= boost::integer_traits<base_type>::const_max);
  39. }
  40. library_version_type(const library_version_type & t_) :
  41. t(t_.t)
  42. {}
  43. library_version_type & operator=(const library_version_type & rhs){
  44. t = rhs.t;
  45. return *this;
  46. }
  47. // used for text output
  48. operator base_type () const {
  49. return t;
  50. }
  51. // used for text input
  52. operator base_type & (){
  53. return t;
  54. }
  55. bool operator==(const library_version_type & rhs) const {
  56. return t == rhs.t;
  57. }
  58. bool operator<(const library_version_type & rhs) const {
  59. return t < rhs.t;
  60. }
  61. };
  62. BOOST_ARCHIVE_DECL(library_version_type)
  63. BOOST_ARCHIVE_VERSION();
  64. class version_type {
  65. private:
  66. typedef uint_least32_t base_type;
  67. base_type t;
  68. public:
  69. // should be private - but MPI fails if it's not!!!
  70. version_type(): t(0) {};
  71. explicit version_type(const unsigned int & t_) : t(t_){
  72. BOOST_ASSERT(t_ <= boost::integer_traits<base_type>::const_max);
  73. }
  74. version_type(const version_type & t_) :
  75. t(t_.t)
  76. {}
  77. version_type & operator=(const version_type & rhs){
  78. t = rhs.t;
  79. return *this;
  80. }
  81. // used for text output
  82. operator base_type () const {
  83. return t;
  84. }
  85. // used for text intput
  86. operator base_type & (){
  87. return t;
  88. }
  89. bool operator==(const version_type & rhs) const {
  90. return t == rhs.t;
  91. }
  92. bool operator<(const version_type & rhs) const {
  93. return t < rhs.t;
  94. }
  95. };
  96. class class_id_type {
  97. private:
  98. typedef int_least16_t base_type;
  99. base_type t;
  100. public:
  101. // should be private - but then can't use BOOST_STRONG_TYPE below
  102. class_id_type() : t(0) {};
  103. explicit class_id_type(const int t_) : t(t_){
  104. BOOST_ASSERT(t_ <= boost::integer_traits<base_type>::const_max);
  105. }
  106. explicit class_id_type(const std::size_t t_) : t(t_){
  107. // BOOST_ASSERT(t_ <= boost::integer_traits<base_type>::const_max);
  108. }
  109. class_id_type(const class_id_type & t_) :
  110. t(t_.t)
  111. {}
  112. class_id_type & operator=(const class_id_type & rhs){
  113. t = rhs.t;
  114. return *this;
  115. }
  116. // used for text output
  117. operator int () const {
  118. return t;
  119. }
  120. // used for text input
  121. operator int_least16_t &() {
  122. return t;
  123. }
  124. bool operator==(const class_id_type & rhs) const {
  125. return t == rhs.t;
  126. }
  127. bool operator<(const class_id_type & rhs) const {
  128. return t < rhs.t;
  129. }
  130. };
  131. #define NULL_POINTER_TAG boost::archive::class_id_type(-1)
  132. class object_id_type {
  133. private:
  134. typedef uint_least32_t base_type;
  135. base_type t;
  136. public:
  137. object_id_type(): t(0) {};
  138. // note: presumes that size_t >= unsigned int.
  139. explicit object_id_type(const std::size_t & t_) : t(t_){
  140. BOOST_ASSERT(t_ <= boost::integer_traits<base_type>::const_max);
  141. }
  142. object_id_type(const object_id_type & t_) :
  143. t(t_.t)
  144. {}
  145. object_id_type & operator=(const object_id_type & rhs){
  146. t = rhs.t;
  147. return *this;
  148. }
  149. // used for text output
  150. operator uint_least32_t () const {
  151. return t;
  152. }
  153. // used for text input
  154. operator uint_least32_t & () {
  155. return t;
  156. }
  157. bool operator==(const object_id_type & rhs) const {
  158. return t == rhs.t;
  159. }
  160. bool operator<(const object_id_type & rhs) const {
  161. return t < rhs.t;
  162. }
  163. };
  164. #if defined(_MSC_VER)
  165. #pragma warning( pop )
  166. #endif
  167. struct tracking_type {
  168. bool t;
  169. explicit tracking_type(const bool t_ = false)
  170. : t(t_)
  171. {};
  172. tracking_type(const tracking_type & t_)
  173. : t(t_.t)
  174. {}
  175. operator bool () const {
  176. return t;
  177. };
  178. operator bool & () {
  179. return t;
  180. };
  181. tracking_type & operator=(const bool t_){
  182. t = t_;
  183. return *this;
  184. }
  185. bool operator==(const tracking_type & rhs) const {
  186. return t == rhs.t;
  187. }
  188. bool operator==(const bool & rhs) const {
  189. return t == rhs;
  190. }
  191. tracking_type & operator=(const tracking_type & rhs){
  192. t = rhs.t;
  193. return *this;
  194. }
  195. };
  196. struct class_name_type :
  197. private boost::noncopyable
  198. {
  199. char *t;
  200. operator const char * & () const {
  201. return const_cast<const char * &>(t);
  202. }
  203. operator char * () {
  204. return t;
  205. }
  206. explicit class_name_type(const char *key_)
  207. : t(const_cast<char *>(key_)){}
  208. explicit class_name_type(char *key_)
  209. : t(key_){}
  210. class_name_type & operator=(const class_name_type & rhs){
  211. t = rhs.t;
  212. return *this;
  213. }
  214. };
  215. enum archive_flags {
  216. no_header = 1, // suppress archive header info
  217. no_codecvt = 2, // suppress alteration of codecvt facet
  218. no_xml_tag_checking = 4, // suppress checking of xml tags
  219. no_tracking = 8, // suppress ALL tracking
  220. flags_last = 8
  221. };
  222. BOOST_ARCHIVE_DECL(const char *)
  223. BOOST_ARCHIVE_SIGNATURE();
  224. /* NOTE : Warning : Warning : Warning : Warning : Warning
  225. * If any of these are changed to different sized types,
  226. * binary_iarchive won't be able to read older archives
  227. * unless you rev the library version and include conditional
  228. * code based on the library version. There is nothing
  229. * inherently wrong in doing this - but you have to be super
  230. * careful because it's easy to get wrong and start breaking
  231. * old archives !!!
  232. */
  233. #define BOOST_ARCHIVE_STRONG_TYPEDEF(T, D) \
  234. class D : public T { \
  235. public: \
  236. explicit D(const T tt) : T(tt){} \
  237. }; \
  238. /**/
  239. BOOST_ARCHIVE_STRONG_TYPEDEF(class_id_type, class_id_reference_type)
  240. BOOST_ARCHIVE_STRONG_TYPEDEF(class_id_type, class_id_optional_type)
  241. BOOST_ARCHIVE_STRONG_TYPEDEF(object_id_type, object_reference_type)
  242. }// namespace archive
  243. }// namespace boost
  244. #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
  245. #include <boost/serialization/level.hpp>
  246. // set implementation level to primitive for all types
  247. // used internally by the serialization library
  248. BOOST_CLASS_IMPLEMENTATION(boost::archive::library_version_type, primitive_type)
  249. BOOST_CLASS_IMPLEMENTATION(boost::archive::version_type, primitive_type)
  250. BOOST_CLASS_IMPLEMENTATION(boost::archive::class_id_type, primitive_type)
  251. BOOST_CLASS_IMPLEMENTATION(boost::archive::class_id_reference_type, primitive_type)
  252. BOOST_CLASS_IMPLEMENTATION(boost::archive::class_id_optional_type, primitive_type)
  253. BOOST_CLASS_IMPLEMENTATION(boost::archive::class_name_type, primitive_type)
  254. BOOST_CLASS_IMPLEMENTATION(boost::archive::object_id_type, primitive_type)
  255. BOOST_CLASS_IMPLEMENTATION(boost::archive::object_reference_type, primitive_type)
  256. BOOST_CLASS_IMPLEMENTATION(boost::archive::tracking_type, primitive_type)
  257. #include <boost/serialization/is_bitwise_serializable.hpp>
  258. // set types used internally by the serialization library
  259. // to be bitwise serializable
  260. BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::library_version_type)
  261. BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::version_type)
  262. BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::class_id_type)
  263. BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::class_id_reference_type)
  264. BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::class_id_optional_type)
  265. BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::class_name_type)
  266. BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::object_id_type)
  267. BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::object_reference_type)
  268. BOOST_IS_BITWISE_SERIALIZABLE(boost::archive::tracking_type)
  269. #endif //BOOST_ARCHIVE_BASIC_ARCHIVE_HPP