basic_archive.hpp 9.2 KB

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