basic_xml_oarchive.hpp 4.5 KB

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