polymorphic_oarchive.hpp 4.7 KB

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