polymorphic_iarchive.hpp 5.5 KB

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