polymorphic_iarchive.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #ifndef BOOST_ARCHIVE_POLYMORPHIC_IARCHIVE_HPP
  2. #define BOOST_ARCHIVE_POLYMORPHIC_IARCHIVE_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.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 <cstddef> // std::size_t
  15. #include <climits> // ULONG_MAX
  16. #include <string>
  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/archive/detail/iserializer.hpp>
  25. #include <boost/archive/detail/interface_iarchive.hpp>
  26. #include <boost/serialization/library_version_type.hpp>
  27. #include <boost/serialization/nvp.hpp>
  28. #include <boost/archive/detail/register_archive.hpp>
  29. #include <boost/archive/detail/decl.hpp>
  30. #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
  31. namespace boost {
  32. namespace serialization {
  33. class extended_type_info;
  34. } // namespace serialization
  35. namespace archive {
  36. namespace detail {
  37. class basic_iarchive;
  38. class basic_iserializer;
  39. }
  40. class polymorphic_iarchive;
  41. class BOOST_SYMBOL_VISIBLE polymorphic_iarchive_impl :
  42. public detail::interface_iarchive<polymorphic_iarchive>
  43. {
  44. #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
  45. public:
  46. #else
  47. friend class detail::interface_iarchive<polymorphic_iarchive>;
  48. friend class load_access;
  49. #endif
  50. // primitive types the only ones permitted by polymorphic archives
  51. virtual void load(bool & t) = 0;
  52. virtual void load(char & t) = 0;
  53. virtual void load(signed char & t) = 0;
  54. virtual void load(unsigned char & t) = 0;
  55. #ifndef BOOST_NO_CWCHAR
  56. #ifndef BOOST_NO_INTRINSIC_WCHAR_T
  57. virtual void load(wchar_t & t) = 0;
  58. #endif
  59. #endif
  60. virtual void load(short & t) = 0;
  61. virtual void load(unsigned short & t) = 0;
  62. virtual void load(int & t) = 0;
  63. virtual void load(unsigned int & t) = 0;
  64. virtual void load(long & t) = 0;
  65. virtual void load(unsigned long & t) = 0;
  66. #if defined(BOOST_HAS_LONG_LONG)
  67. virtual void load(boost::long_long_type & t) = 0;
  68. virtual void load(boost::ulong_long_type & t) = 0;
  69. #elif defined(BOOST_HAS_MS_INT64)
  70. virtual void load(__int64 & t) = 0;
  71. virtual void load(unsigned __int64 & t) = 0;
  72. #endif
  73. virtual void load(float & t) = 0;
  74. virtual void load(double & t) = 0;
  75. // string types are treated as primitives
  76. virtual void load(std::string & t) = 0;
  77. #ifndef BOOST_NO_STD_WSTRING
  78. virtual void load(std::wstring & t) = 0;
  79. #endif
  80. // used for xml and other tagged formats
  81. virtual void load_start(const char * name) = 0;
  82. virtual void load_end(const char * name) = 0;
  83. virtual void register_basic_serializer(const detail::basic_iserializer & bis) = 0;
  84. virtual detail::helper_collection & get_helper_collection() = 0;
  85. // msvc and borland won't automatically pass these to the base class so
  86. // make it explicit here
  87. template<class T>
  88. void load_override(T & t)
  89. {
  90. archive::load(* this->This(), t);
  91. }
  92. // special treatment for name-value pairs.
  93. template<class T>
  94. void load_override(
  95. const boost::serialization::nvp< T > & t
  96. ){
  97. load_start(t.name());
  98. archive::load(* this->This(), t.value());
  99. load_end(t.name());
  100. }
  101. protected:
  102. virtual ~polymorphic_iarchive_impl() {}
  103. public:
  104. // utility function implemented by all legal archives
  105. virtual void set_library_version(
  106. boost::serialization::library_version_type archive_library_version
  107. ) = 0;
  108. virtual boost::serialization::library_version_type get_library_version() const = 0;
  109. virtual unsigned int get_flags() const = 0;
  110. virtual void delete_created_pointers() = 0;
  111. virtual void reset_object_address(
  112. const void * new_address,
  113. const void * old_address
  114. ) = 0;
  115. virtual void load_binary(void * t, std::size_t size) = 0;
  116. // these are used by the serialization library implementation.
  117. virtual void load_object(
  118. void *t,
  119. const detail::basic_iserializer & bis
  120. ) = 0;
  121. virtual const detail::basic_pointer_iserializer * load_pointer(
  122. void * & t,
  123. const detail::basic_pointer_iserializer * bpis_ptr,
  124. const detail::basic_pointer_iserializer * (*finder)(
  125. const boost::serialization::extended_type_info & type
  126. )
  127. ) = 0;
  128. };
  129. } // namespace archive
  130. } // namespace boost
  131. #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
  132. namespace boost {
  133. namespace archive {
  134. class BOOST_SYMBOL_VISIBLE polymorphic_iarchive :
  135. public polymorphic_iarchive_impl
  136. {
  137. public:
  138. ~polymorphic_iarchive() BOOST_OVERRIDE {}
  139. };
  140. } // namespace archive
  141. } // namespace boost
  142. // required by export
  143. BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::archive::polymorphic_iarchive)
  144. #endif // BOOST_ARCHIVE_POLYMORPHIC_IARCHIVE_HPP