polymorphic_iarchive_route.hpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #ifndef BOOST_ARCHIVE_DETAIL_POLYMORPHIC_IARCHIVE_ROUTE_HPP
  2. #define BOOST_ARCHIVE_DETAIL_POLYMORPHIC_IARCHIVE_ROUTE_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. // polymorphic_iarchive_route.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 <string>
  15. #include <ostream>
  16. #include <cstddef>
  17. #include <boost/config.hpp>
  18. #if defined(BOOST_NO_STDC_NAMESPACE)
  19. namespace std{
  20. using ::size_t;
  21. } // namespace std
  22. #endif
  23. #include <boost/cstdint.hpp>
  24. #include <boost/integer_traits.hpp>
  25. #include <boost/archive/polymorphic_iarchive.hpp>
  26. #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
  27. namespace boost {
  28. namespace serialization {
  29. class extended_type_info;
  30. } // namespace serialization
  31. namespace archive {
  32. namespace detail{
  33. class basic_iserializer;
  34. class basic_pointer_iserializer;
  35. #ifdef BOOST_MSVC
  36. # pragma warning(push)
  37. # pragma warning(disable : 4511 4512)
  38. #endif
  39. template<class ArchiveImplementation>
  40. class polymorphic_iarchive_route :
  41. public polymorphic_iarchive,
  42. // note: gcc dynamic cross cast fails if the the derivation below is
  43. // not public. I think this is a mistake.
  44. public /*protected*/ ArchiveImplementation
  45. {
  46. private:
  47. // these are used by the serialization library.
  48. void load_object(
  49. void *t,
  50. const basic_iserializer & bis
  51. ) BOOST_OVERRIDE {
  52. ArchiveImplementation::load_object(t, bis);
  53. }
  54. const basic_pointer_iserializer * load_pointer(
  55. void * & t,
  56. const basic_pointer_iserializer * bpis_ptr,
  57. const basic_pointer_iserializer * (*finder)(
  58. const boost::serialization::extended_type_info & type
  59. )
  60. ) BOOST_OVERRIDE {
  61. return ArchiveImplementation::load_pointer(t, bpis_ptr, finder);
  62. }
  63. void set_library_version(boost::serialization::library_version_type archive_library_version) BOOST_OVERRIDE {
  64. ArchiveImplementation::set_library_version(archive_library_version);
  65. }
  66. boost::serialization::library_version_type get_library_version() const BOOST_OVERRIDE {
  67. return ArchiveImplementation::get_library_version();
  68. }
  69. unsigned int get_flags() const BOOST_OVERRIDE {
  70. return ArchiveImplementation::get_flags();
  71. }
  72. void delete_created_pointers() BOOST_OVERRIDE {
  73. ArchiveImplementation::delete_created_pointers();
  74. }
  75. void reset_object_address(
  76. const void * new_address,
  77. const void * old_address
  78. ) BOOST_OVERRIDE {
  79. ArchiveImplementation::reset_object_address(new_address, old_address);
  80. }
  81. void load_binary(void * t, std::size_t size) BOOST_OVERRIDE {
  82. ArchiveImplementation::load_binary(t, size);
  83. }
  84. // primitive types the only ones permitted by polymorphic archives
  85. void load(bool & t) BOOST_OVERRIDE {
  86. ArchiveImplementation::load(t);
  87. }
  88. void load(char & t) BOOST_OVERRIDE {
  89. ArchiveImplementation::load(t);
  90. }
  91. void load(signed char & t) BOOST_OVERRIDE {
  92. ArchiveImplementation::load(t);
  93. }
  94. void load(unsigned char & t) BOOST_OVERRIDE {
  95. ArchiveImplementation::load(t);
  96. }
  97. #ifndef BOOST_NO_CWCHAR
  98. #ifndef BOOST_NO_INTRINSIC_WCHAR_T
  99. void load(wchar_t & t) BOOST_OVERRIDE {
  100. ArchiveImplementation::load(t);
  101. }
  102. #endif
  103. #endif
  104. void load(short & t) BOOST_OVERRIDE {
  105. ArchiveImplementation::load(t);
  106. }
  107. void load(unsigned short & t) BOOST_OVERRIDE {
  108. ArchiveImplementation::load(t);
  109. }
  110. void load(int & t) BOOST_OVERRIDE {
  111. ArchiveImplementation::load(t);
  112. }
  113. void load(unsigned int & t) BOOST_OVERRIDE {
  114. ArchiveImplementation::load(t);
  115. }
  116. void load(long & t) BOOST_OVERRIDE {
  117. ArchiveImplementation::load(t);
  118. }
  119. void load(unsigned long & t) BOOST_OVERRIDE {
  120. ArchiveImplementation::load(t);
  121. }
  122. #if defined(BOOST_HAS_LONG_LONG)
  123. void load(boost::long_long_type & t) BOOST_OVERRIDE {
  124. ArchiveImplementation::load(t);
  125. }
  126. void load(boost::ulong_long_type & t) BOOST_OVERRIDE {
  127. ArchiveImplementation::load(t);
  128. }
  129. #elif defined(BOOST_HAS_MS_INT64)
  130. void load(__int64 & t) BOOST_OVERRIDE {
  131. ArchiveImplementation::load(t);
  132. }
  133. void load(unsigned __int64 & t) BOOST_OVERRIDE {
  134. ArchiveImplementation::load(t);
  135. }
  136. #endif
  137. void load(float & t) BOOST_OVERRIDE {
  138. ArchiveImplementation::load(t);
  139. }
  140. void load(double & t) BOOST_OVERRIDE {
  141. ArchiveImplementation::load(t);
  142. }
  143. void load(std::string & t) BOOST_OVERRIDE {
  144. ArchiveImplementation::load(t);
  145. }
  146. #ifndef BOOST_NO_STD_WSTRING
  147. void load(std::wstring & t) BOOST_OVERRIDE {
  148. ArchiveImplementation::load(t);
  149. }
  150. #endif
  151. // used for xml and other tagged formats default does nothing
  152. void load_start(const char * name) BOOST_OVERRIDE {
  153. ArchiveImplementation::load_start(name);
  154. }
  155. void load_end(const char * name) BOOST_OVERRIDE {
  156. ArchiveImplementation::load_end(name);
  157. }
  158. void register_basic_serializer(const basic_iserializer & bis) BOOST_OVERRIDE {
  159. ArchiveImplementation::register_basic_serializer(bis);
  160. }
  161. helper_collection &
  162. get_helper_collection() BOOST_OVERRIDE {
  163. return ArchiveImplementation::get_helper_collection();
  164. }
  165. public:
  166. // this can't be inherited because they appear in multiple
  167. // parents
  168. typedef mpl::bool_<true> is_loading;
  169. typedef mpl::bool_<false> is_saving;
  170. // the >> operator
  171. template<class T>
  172. polymorphic_iarchive & operator>>(T & t){
  173. return polymorphic_iarchive::operator>>(t);
  174. }
  175. // the & operator
  176. template<class T>
  177. polymorphic_iarchive & operator&(T & t){
  178. return polymorphic_iarchive::operator&(t);
  179. }
  180. // register type function
  181. template<class T>
  182. const basic_pointer_iserializer *
  183. register_type(T * t = NULL){
  184. return ArchiveImplementation::register_type(t);
  185. }
  186. // all current archives take a stream as constructor argument
  187. template <class _Elem, class _Tr>
  188. polymorphic_iarchive_route(
  189. std::basic_istream<_Elem, _Tr> & is,
  190. unsigned int flags = 0
  191. ) :
  192. ArchiveImplementation(is, flags)
  193. {}
  194. ~polymorphic_iarchive_route() BOOST_OVERRIDE {}
  195. };
  196. } // namespace detail
  197. } // namespace archive
  198. } // namespace boost
  199. #ifdef BOOST_MSVC
  200. #pragma warning(pop)
  201. #endif
  202. #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
  203. #endif // BOOST_ARCHIVE_DETAIL_POLYMORPHIC_IARCHIVE_DISPATCH_HPP