polymorphic_iarchive.hpp 5.0 KB

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