basic_xml_oarchive.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #ifndef BOOST_ARCHIVE_BASIC_XML_OARCHIVE_HPP
  2. #define BOOST_ARCHIVE_BASIC_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. // basic_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 <boost/config.hpp>
  15. #include <boost/mpl/assert.hpp>
  16. #include <boost/archive/detail/common_oarchive.hpp>
  17. #include <boost/serialization/nvp.hpp>
  18. #include <boost/serialization/string.hpp>
  19. #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
  20. #ifdef BOOST_MSVC
  21. # pragma warning(push)
  22. # pragma warning(disable : 4511 4512)
  23. #endif
  24. namespace boost {
  25. namespace archive {
  26. namespace detail {
  27. template<class Archive> class interface_oarchive;
  28. } // namespace detail
  29. //////////////////////////////////////////////////////////////////////
  30. // class basic_xml_oarchive - write serialized objects to a xml output stream
  31. template<class Archive>
  32. class BOOST_SYMBOL_VISIBLE basic_xml_oarchive :
  33. public detail::common_oarchive<Archive>
  34. {
  35. // special stuff for xml output
  36. unsigned int depth;
  37. bool pending_preamble;
  38. #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
  39. public:
  40. #else
  41. protected:
  42. friend class detail::interface_oarchive<Archive>;
  43. #endif
  44. bool indent_next;
  45. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  46. indent();
  47. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  48. init();
  49. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  50. windup();
  51. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  52. write_attribute(
  53. const char *attribute_name,
  54. int t,
  55. const char *conjunction = "=\""
  56. );
  57. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  58. write_attribute(
  59. const char *attribute_name,
  60. const char *key
  61. );
  62. // helpers used below
  63. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  64. save_start(const char *name);
  65. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  66. save_end(const char *name);
  67. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  68. end_preamble();
  69. // Anything not an attribute and not a name-value pair is an
  70. // error and should be trapped here.
  71. template<class T>
  72. void save_override(T & t)
  73. {
  74. // If your program fails to compile here, its most likely due to
  75. // not specifying an nvp wrapper around the variable to
  76. // be serialized.
  77. BOOST_MPL_ASSERT((serialization::is_wrapper< T >));
  78. this->detail_common_oarchive::save_override(t);
  79. }
  80. // special treatment for name-value pairs.
  81. typedef detail::common_oarchive<Archive> detail_common_oarchive;
  82. template<class T>
  83. void save_override(
  84. const ::boost::serialization::nvp< T > & t
  85. ){
  86. this->This()->save_start(t.name());
  87. this->detail_common_oarchive::save_override(t.const_value());
  88. this->This()->save_end(t.name());
  89. }
  90. // specific overrides for attributes - not name value pairs so we
  91. // want to trap them before the above "fall through"
  92. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  93. save_override(const class_id_type & t);
  94. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  95. save_override(const class_id_optional_type & t);
  96. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  97. save_override(const class_id_reference_type & t);
  98. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  99. save_override(const object_id_type & t);
  100. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  101. save_override(const object_reference_type & t);
  102. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  103. save_override(const version_type & t);
  104. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  105. save_override(const class_name_type & t);
  106. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  107. save_override(const tracking_type & t);
  108. BOOST_ARCHIVE_OR_WARCHIVE_DECL
  109. basic_xml_oarchive(unsigned int flags);
  110. BOOST_ARCHIVE_OR_WARCHIVE_DECL
  111. ~basic_xml_oarchive();
  112. };
  113. } // namespace archive
  114. } // namespace boost
  115. #ifdef BOOST_MSVC
  116. #pragma warning(pop)
  117. #endif
  118. #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
  119. #endif // BOOST_ARCHIVE_BASIC_XML_OARCHIVE_HPP