polymorphic_iarchive_route.hpp 6.5 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. virtual void load_object(
  49. void *t,
  50. const basic_iserializer & bis
  51. ){
  52. ArchiveImplementation::load_object(t, bis);
  53. }
  54. virtual 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. ){
  61. return ArchiveImplementation::load_pointer(t, bpis_ptr, finder);
  62. }
  63. virtual void set_library_version(library_version_type archive_library_version){
  64. ArchiveImplementation::set_library_version(archive_library_version);
  65. }
  66. virtual library_version_type get_library_version() const{
  67. return ArchiveImplementation::get_library_version();
  68. }
  69. virtual unsigned int get_flags() const {
  70. return ArchiveImplementation::get_flags();
  71. }
  72. virtual void delete_created_pointers(){
  73. ArchiveImplementation::delete_created_pointers();
  74. }
  75. virtual void reset_object_address(
  76. const void * new_address,
  77. const void * old_address
  78. ){
  79. ArchiveImplementation::reset_object_address(new_address, old_address);
  80. }
  81. virtual void load_binary(void * t, std::size_t size){
  82. ArchiveImplementation::load_binary(t, size);
  83. }
  84. // primitive types the only ones permitted by polymorphic archives
  85. virtual void load(bool & t){
  86. ArchiveImplementation::load(t);
  87. }
  88. virtual void load(char & t){
  89. ArchiveImplementation::load(t);
  90. }
  91. virtual void load(signed char & t){
  92. ArchiveImplementation::load(t);
  93. }
  94. virtual void load(unsigned char & t){
  95. ArchiveImplementation::load(t);
  96. }
  97. #ifndef BOOST_NO_CWCHAR
  98. #ifndef BOOST_NO_INTRINSIC_WCHAR_T
  99. virtual void load(wchar_t & t){
  100. ArchiveImplementation::load(t);
  101. }
  102. #endif
  103. #endif
  104. virtual void load(short & t){
  105. ArchiveImplementation::load(t);
  106. }
  107. virtual void load(unsigned short & t){
  108. ArchiveImplementation::load(t);
  109. }
  110. virtual void load(int & t){
  111. ArchiveImplementation::load(t);
  112. }
  113. virtual void load(unsigned int & t){
  114. ArchiveImplementation::load(t);
  115. }
  116. virtual void load(long & t){
  117. ArchiveImplementation::load(t);
  118. }
  119. virtual void load(unsigned long & t){
  120. ArchiveImplementation::load(t);
  121. }
  122. #if defined(BOOST_HAS_LONG_LONG)
  123. virtual void load(boost::long_long_type & t){
  124. ArchiveImplementation::load(t);
  125. }
  126. virtual void load(boost::ulong_long_type & t){
  127. ArchiveImplementation::load(t);
  128. }
  129. #elif defined(BOOST_HAS_MS_INT64)
  130. virtual void load(__int64 & t){
  131. ArchiveImplementation::load(t);
  132. }
  133. virtual void load(unsigned __int64 & t){
  134. ArchiveImplementation::load(t);
  135. }
  136. #endif
  137. virtual void load(float & t){
  138. ArchiveImplementation::load(t);
  139. }
  140. virtual void load(double & t){
  141. ArchiveImplementation::load(t);
  142. }
  143. virtual void load(std::string & t){
  144. ArchiveImplementation::load(t);
  145. }
  146. #ifndef BOOST_NO_STD_WSTRING
  147. virtual void load(std::wstring & t){
  148. ArchiveImplementation::load(t);
  149. }
  150. #endif
  151. // used for xml and other tagged formats default does nothing
  152. virtual void load_start(const char * name){
  153. ArchiveImplementation::load_start(name);
  154. }
  155. virtual void load_end(const char * name){
  156. ArchiveImplementation::load_end(name);
  157. }
  158. virtual void register_basic_serializer(const basic_iserializer & bis){
  159. ArchiveImplementation::register_basic_serializer(bis);
  160. }
  161. virtual helper_collection &
  162. get_helper_collection(){
  163. return ArchiveImplementation::get_helper_collection();
  164. }
  165. public:
  166. // this can't be inheriteded because they appear in mulitple
  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. virtual ~polymorphic_iarchive_route(){};
  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