basic_archive.hpp 8.2 KB

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