xml_oarchive.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #ifndef BOOST_ARCHIVE_XML_OARCHIVE_HPP
  2. #define BOOST_ARCHIVE_XML_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. // xml_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 <ostream>
  15. #include <cstddef> // size_t
  16. #include <boost/config.hpp>
  17. #if defined(BOOST_NO_STDC_NAMESPACE)
  18. namespace std{
  19. using ::size_t;
  20. } // namespace std
  21. #endif
  22. #include <boost/archive/detail/auto_link_archive.hpp>
  23. #include <boost/archive/basic_text_oprimitive.hpp>
  24. #include <boost/archive/basic_xml_oarchive.hpp>
  25. #include <boost/archive/detail/register_archive.hpp>
  26. #include <boost/serialization/item_version_type.hpp>
  27. #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
  28. #ifdef BOOST_MSVC
  29. # pragma warning(push)
  30. # pragma warning(disable : 4511 4512)
  31. #endif
  32. namespace boost {
  33. namespace archive {
  34. namespace detail {
  35. template<class Archive> class interface_oarchive;
  36. } // namespace detail
  37. template<class Archive>
  38. class BOOST_SYMBOL_VISIBLE xml_oarchive_impl :
  39. public basic_text_oprimitive<std::ostream>,
  40. public basic_xml_oarchive<Archive>
  41. {
  42. #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
  43. public:
  44. #else
  45. protected:
  46. friend class detail::interface_oarchive<Archive>;
  47. friend class basic_xml_oarchive<Archive>;
  48. friend class save_access;
  49. #endif
  50. template<class T>
  51. void save(const T & t){
  52. basic_text_oprimitive<std::ostream>::save(t);
  53. }
  54. void
  55. save(const version_type & t){
  56. save(static_cast<unsigned int>(t));
  57. }
  58. void
  59. save(const boost::serialization::item_version_type & t){
  60. save(static_cast<unsigned int>(t));
  61. }
  62. BOOST_ARCHIVE_DECL void
  63. save(const char * t);
  64. #ifndef BOOST_NO_INTRINSIC_WCHAR_T
  65. BOOST_ARCHIVE_DECL void
  66. save(const wchar_t * t);
  67. #endif
  68. BOOST_ARCHIVE_DECL void
  69. save(const std::string &s);
  70. #ifndef BOOST_NO_STD_WSTRING
  71. BOOST_ARCHIVE_DECL void
  72. save(const std::wstring &ws);
  73. #endif
  74. BOOST_ARCHIVE_DECL
  75. xml_oarchive_impl(std::ostream & os, unsigned int flags);
  76. BOOST_ARCHIVE_DECL
  77. ~xml_oarchive_impl() BOOST_OVERRIDE;
  78. public:
  79. BOOST_ARCHIVE_DECL
  80. void save_binary(const void *address, std::size_t count);
  81. };
  82. } // namespace archive
  83. } // namespace boost
  84. #ifdef BOOST_MSVC
  85. #pragma warning(pop)
  86. #endif
  87. #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
  88. #ifdef BOOST_MSVC
  89. # pragma warning(push)
  90. # pragma warning(disable : 4511 4512)
  91. #endif
  92. namespace boost {
  93. namespace archive {
  94. // we use the following because we can't use
  95. // typedef xml_oarchive_impl<xml_oarchive_impl<...> > xml_oarchive;
  96. // do not derive from this class. If you want to extend this functionality
  97. // via inheritance, derived from xml_oarchive_impl instead. This will
  98. // preserve correct static polymorphism.
  99. class BOOST_SYMBOL_VISIBLE xml_oarchive :
  100. public xml_oarchive_impl<xml_oarchive>
  101. {
  102. public:
  103. xml_oarchive(std::ostream & os, unsigned int flags = 0) :
  104. xml_oarchive_impl<xml_oarchive>(os, flags)
  105. {
  106. if(0 == (flags & no_header))
  107. init();
  108. }
  109. ~xml_oarchive() BOOST_OVERRIDE {}
  110. };
  111. } // namespace archive
  112. } // namespace boost
  113. // required by export
  114. BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::archive::xml_oarchive)
  115. #ifdef BOOST_MSVC
  116. #pragma warning(pop)
  117. #endif
  118. #endif // BOOST_ARCHIVE_XML_OARCHIVE_HPP