polymorphic_oarchive.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #ifndef BOOST_ARCHIVE_POLYMORPHIC_OARCHIVE_HPP
  2. #define BOOST_ARCHIVE_POLYMORPHIC_OARCHIVE_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_oarchive.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> // 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/oserializer.hpp>
  26. #include <boost/archive/detail/interface_oarchive.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_oarchive;
  40. class BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) basic_oserializer;
  41. }
  42. class polymorphic_oarchive;
  43. class polymorphic_oarchive_impl :
  44. public detail::interface_oarchive<polymorphic_oarchive>
  45. {
  46. #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
  47. public:
  48. #else
  49. friend class detail::interface_oarchive<polymorphic_oarchive>;
  50. friend class save_access;
  51. #endif
  52. // primitive types the only ones permitted by polymorphic archives
  53. virtual void save(const bool t) = 0;
  54. virtual void save(const char t) = 0;
  55. virtual void save(const signed char t) = 0;
  56. virtual void save(const unsigned char t) = 0;
  57. #ifndef BOOST_NO_CWCHAR
  58. #ifndef BOOST_NO_INTRINSIC_WCHAR_T
  59. virtual void save(const wchar_t t) = 0;
  60. #endif
  61. #endif
  62. virtual void save(const short t) = 0;
  63. virtual void save(const unsigned short t) = 0;
  64. virtual void save(const int t) = 0;
  65. virtual void save(const unsigned int t) = 0;
  66. virtual void save(const long t) = 0;
  67. virtual void save(const unsigned long t) = 0;
  68. #if defined(BOOST_HAS_LONG_LONG)
  69. virtual void save(const boost::long_long_type t) = 0;
  70. virtual void save(const boost::ulong_long_type t) = 0;
  71. #elif defined(BOOST_HAS_MS_INT64)
  72. virtual void save(const __int64 t) = 0;
  73. virtual void save(const unsigned __int64 t) = 0;
  74. #endif
  75. virtual void save(const float t) = 0;
  76. virtual void save(const double t) = 0;
  77. // string types are treated as primitives
  78. virtual void save(const std::string & t) = 0;
  79. #ifndef BOOST_NO_STD_WSTRING
  80. virtual void save(const std::wstring & t) = 0;
  81. #endif
  82. virtual void save_null_pointer() = 0;
  83. // used for xml and other tagged formats
  84. virtual void save_start(const char * name) = 0;
  85. virtual void save_end(const char * name) = 0;
  86. virtual void register_basic_serializer(const detail::basic_oserializer & bos) = 0;
  87. virtual void end_preamble() = 0;
  88. // msvc and borland won't automatically pass these to the base class so
  89. // make it explicit here
  90. template<class T>
  91. void save_override(T & t, BOOST_PFTO int)
  92. {
  93. archive::save(* this->This(), t);
  94. }
  95. // special treatment for name-value pairs.
  96. template<class T>
  97. void save_override(
  98. #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  99. const
  100. #endif
  101. ::boost::serialization::nvp< T > & t, int
  102. ){
  103. save_start(t.name());
  104. archive::save(* this->This(), t.const_value());
  105. save_end(t.name());
  106. }
  107. protected:
  108. virtual ~polymorphic_oarchive_impl(){};
  109. public:
  110. // utility functions implemented by all legal archives
  111. virtual unsigned int get_flags() const = 0;
  112. virtual library_version_type get_library_version() const = 0;
  113. virtual void save_binary(const void * t, std::size_t size) = 0;
  114. virtual void save_object(
  115. const void *x,
  116. const detail::basic_oserializer & bos
  117. ) = 0;
  118. virtual void save_pointer(
  119. const void * t,
  120. const detail::basic_pointer_oserializer * bpos_ptr
  121. ) = 0;
  122. };
  123. // note: preserve naming symmetry
  124. class polymorphic_oarchive :
  125. public polymorphic_oarchive_impl
  126. {
  127. public:
  128. virtual ~polymorphic_oarchive(){};
  129. };
  130. } // namespace archive
  131. } // namespace boost
  132. // required by export
  133. BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::archive::polymorphic_oarchive)
  134. #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
  135. #endif // BOOST_ARCHIVE_POLYMORPHIC_OARCHIVE_HPP