1
0

basic_binary_iarchive.hpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #ifndef BOOST_ARCHIVE_BASIC_BINARY_IARCHIVE_HPP
  2. #define BOOST_ARCHIVE_BASIC_BINARY_IARCHIVE_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_binary_iarchive.hpp
  9. //
  10. // archives stored as native binary - this should be the fastest way
  11. // to archive the state of a group of obects. It makes no attempt to
  12. // convert to any canonical form.
  13. // IN GENERAL, ARCHIVES CREATED WITH THIS CLASS WILL NOT BE READABLE
  14. // ON PLATFORM APART FROM THE ONE THEY ARE CREATED ON
  15. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  16. // Use, modification and distribution is subject to the Boost Software
  17. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  18. // http://www.boost.org/LICENSE_1_0.txt)
  19. // See http://www.boost.org for updates, documentation, and revision history.
  20. #include <boost/config.hpp>
  21. #include <boost/detail/workaround.hpp>
  22. #include <boost/serialization/pfto.hpp>
  23. #include <boost/archive/basic_archive.hpp>
  24. #include <boost/archive/detail/common_iarchive.hpp>
  25. #include <boost/serialization/collection_size_type.hpp>
  26. #include <boost/serialization/string.hpp>
  27. #include <boost/serialization/item_version_type.hpp>
  28. #include <boost/integer_traits.hpp>
  29. #ifdef BOOST_MSVC
  30. # pragma warning(push)
  31. # pragma warning(disable : 4511 4512)
  32. #endif
  33. #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
  34. namespace boost {
  35. namespace archive {
  36. /////////////////////////////////////////////////////////////////////////
  37. // class basic_binary_iarchive - read serialized objects from a input binary stream
  38. template<class Archive>
  39. class basic_binary_iarchive :
  40. public detail::common_iarchive<Archive>
  41. {
  42. protected:
  43. #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  44. public:
  45. #elif defined(BOOST_MSVC)
  46. // for some inexplicable reason insertion of "class" generates compile erro
  47. // on msvc 7.1
  48. friend detail::interface_iarchive<Archive>;
  49. #else
  50. friend class detail::interface_iarchive<Archive>;
  51. #endif
  52. // intermediate level to support override of operators
  53. // fot templates in the absence of partial function
  54. // template ordering. If we get here pass to base class
  55. // note extra nonsense to sneak it pass the borland compiers
  56. typedef detail::common_iarchive<Archive> detail_common_iarchive;
  57. template<class T>
  58. void load_override(T & t, BOOST_PFTO int version){
  59. this->detail_common_iarchive::load_override(t, static_cast<int>(version));
  60. }
  61. // include these to trap a change in binary format which
  62. // isn't specifically handled
  63. // upto 32K classes
  64. BOOST_STATIC_ASSERT(sizeof(class_id_type) == sizeof(int_least16_t));
  65. BOOST_STATIC_ASSERT(sizeof(class_id_reference_type) == sizeof(int_least16_t));
  66. // upto 2G objects
  67. BOOST_STATIC_ASSERT(sizeof(object_id_type) == sizeof(uint_least32_t));
  68. BOOST_STATIC_ASSERT(sizeof(object_reference_type) == sizeof(uint_least32_t));
  69. // binary files don't include the optional information
  70. void load_override(class_id_optional_type & /* t */, int){}
  71. void load_override(tracking_type & t, int /*version*/){
  72. library_version_type lvt = this->get_library_version();
  73. if(boost::archive::library_version_type(6) < lvt){
  74. int_least8_t x=0;
  75. * this->This() >> x;
  76. t = boost::archive::tracking_type(x);
  77. }
  78. else{
  79. bool x=0;
  80. * this->This() >> x;
  81. t = boost::archive::tracking_type(x);
  82. }
  83. }
  84. void load_override(class_id_type & t, int version){
  85. library_version_type lvt = this->get_library_version();
  86. if(boost::archive::library_version_type(7) < lvt){
  87. this->detail_common_iarchive::load_override(t, version);
  88. }
  89. else
  90. if(boost::archive::library_version_type(6) < lvt){
  91. int_least16_t x=0;
  92. * this->This() >> x;
  93. t = boost::archive::class_id_type(x);
  94. }
  95. else{
  96. int x=0;
  97. * this->This() >> x;
  98. t = boost::archive::class_id_type(x);
  99. }
  100. }
  101. void load_override(class_id_reference_type & t, int version){
  102. load_override(static_cast<class_id_type &>(t), version);
  103. }
  104. #if 0
  105. void load_override(class_id_reference_type & t, int version){
  106. library_version_type lvt = this->get_library_version();
  107. if(boost::archive::library_version_type(7) < lvt){
  108. this->detail_common_iarchive::load_override(t, version);
  109. }
  110. else
  111. if(boost::archive::library_version_type(6) < lvt){
  112. int_least16_t x=0;
  113. * this->This() >> x;
  114. t = boost::archive::class_id_reference_type(
  115. boost::archive::class_id_type(x)
  116. );
  117. }
  118. else{
  119. int x=0;
  120. * this->This() >> x;
  121. t = boost::archive::class_id_reference_type(
  122. boost::archive::class_id_type(x)
  123. );
  124. }
  125. }
  126. #endif
  127. void load_override(version_type & t, int version){
  128. library_version_type lvt = this->get_library_version();
  129. if(boost::archive::library_version_type(7) < lvt){
  130. this->detail_common_iarchive::load_override(t, version);
  131. }
  132. else
  133. if(boost::archive::library_version_type(6) < lvt){
  134. uint_least8_t x=0;
  135. * this->This() >> x;
  136. t = boost::archive::version_type(x);
  137. }
  138. else
  139. if(boost::archive::library_version_type(5) < lvt){
  140. uint_least16_t x=0;
  141. * this->This() >> x;
  142. t = boost::archive::version_type(x);
  143. }
  144. else
  145. if(boost::archive::library_version_type(2) < lvt){
  146. // upto 255 versions
  147. unsigned char x=0;
  148. * this->This() >> x;
  149. t = version_type(x);
  150. }
  151. else{
  152. unsigned int x=0;
  153. * this->This() >> x;
  154. t = boost::archive::version_type(x);
  155. }
  156. }
  157. void load_override(boost::serialization::item_version_type & t, int version){
  158. library_version_type lvt = this->get_library_version();
  159. // if(boost::archive::library_version_type(7) < lvt){
  160. if(boost::archive::library_version_type(6) < lvt){
  161. this->detail_common_iarchive::load_override(t, version);
  162. }
  163. else
  164. if(boost::archive::library_version_type(6) < lvt){
  165. uint_least16_t x=0;
  166. * this->This() >> x;
  167. t = boost::serialization::item_version_type(x);
  168. }
  169. else{
  170. unsigned int x=0;
  171. * this->This() >> x;
  172. t = boost::serialization::item_version_type(x);
  173. }
  174. }
  175. void load_override(serialization::collection_size_type & t, int version){
  176. if(boost::archive::library_version_type(5) < this->get_library_version()){
  177. this->detail_common_iarchive::load_override(t, version);
  178. }
  179. else{
  180. unsigned int x=0;
  181. * this->This() >> x;
  182. t = serialization::collection_size_type(x);
  183. }
  184. }
  185. BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
  186. load_override(class_name_type & t, int);
  187. BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
  188. init();
  189. basic_binary_iarchive(unsigned int flags) :
  190. detail::common_iarchive<Archive>(flags)
  191. {}
  192. };
  193. } // namespace archive
  194. } // namespace boost
  195. #ifdef BOOST_MSVC
  196. #pragma warning(pop)
  197. #endif
  198. #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
  199. #endif // BOOST_ARCHIVE_BASIC_BINARY_IARCHIVE_HPP