xml_oarchive.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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) && (_MSC_VER >= 1020)
  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. template<class Archive>
  35. class xml_oarchive_impl :
  36. public basic_text_oprimitive<std::ostream>,
  37. public basic_xml_oarchive<Archive>
  38. {
  39. #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
  40. public:
  41. #else
  42. friend class detail::interface_oarchive<Archive>;
  43. friend class basic_xml_oarchive<Archive>;
  44. friend class save_access;
  45. protected:
  46. #endif
  47. //void end_preamble(){
  48. // basic_xml_oarchive<Archive>::end_preamble();
  49. //}
  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<const unsigned int>(t));
  57. }
  58. void
  59. save(const boost::serialization::item_version_type & t){
  60. save(static_cast<const 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(BOOST_PP_EMPTY())
  75. xml_oarchive_impl(std::ostream & os, unsigned int flags);
  76. ~xml_oarchive_impl(){}
  77. public:
  78. void save_binary(const void *address, std::size_t count){
  79. this->end_preamble();
  80. #if ! defined(__MWERKS__)
  81. this->basic_text_oprimitive<std::ostream>::save_binary(
  82. #else
  83. this->basic_text_oprimitive::save_binary(
  84. #endif
  85. address,
  86. count
  87. );
  88. this->indent_next = true;
  89. }
  90. };
  91. // we use the following because we can't use
  92. // typedef xml_oarchive_impl<xml_oarchive_impl<...> > xml_oarchive;
  93. // do not derive from this class. If you want to extend this functionality
  94. // via inhertance, derived from xml_oarchive_impl instead. This will
  95. // preserve correct static polymorphism.
  96. class xml_oarchive :
  97. public xml_oarchive_impl<xml_oarchive>
  98. {
  99. public:
  100. xml_oarchive(std::ostream & os, unsigned int flags = 0) :
  101. xml_oarchive_impl<xml_oarchive>(os, flags)
  102. {}
  103. ~xml_oarchive(){}
  104. };
  105. typedef xml_oarchive naked_xml_oarchive;
  106. } // namespace archive
  107. } // namespace boost
  108. // required by export
  109. BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::archive::xml_oarchive)
  110. #ifdef BOOST_MSVC
  111. #pragma warning(pop)
  112. #endif
  113. #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
  114. #endif // BOOST_ARCHIVE_XML_OARCHIVE_HPP