basic_xml_iarchive.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef BOOST_ARCHIVE_BASIC_XML_IARCHIVE_HPP
  2. #define BOOST_ARCHIVE_BASIC_XML_IARCHIVE_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_iarchive.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_iarchive.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_iarchive;
  28. } // namespace detail
  29. /////////////////////////////////////////////////////////////////////////
  30. // class basic_xml_iarchive - read serialized objects from a input text stream
  31. template<class Archive>
  32. class BOOST_SYMBOL_VISIBLE basic_xml_iarchive :
  33. public detail::common_iarchive<Archive>
  34. {
  35. unsigned int depth;
  36. #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
  37. public:
  38. #else
  39. protected:
  40. friend class detail::interface_iarchive<Archive>;
  41. #endif
  42. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  43. load_start(const char *name);
  44. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  45. load_end(const char *name);
  46. // Anything not an attribute and not a name-value pair is an
  47. // should be trapped here.
  48. template<class T>
  49. void load_override(T & t)
  50. {
  51. // If your program fails to compile here, its most likely due to
  52. // not specifying an nvp wrapper around the variable to
  53. // be serialized.
  54. BOOST_MPL_ASSERT((serialization::is_wrapper< T >));
  55. this->detail_common_iarchive::load_override(t);
  56. }
  57. // Anything not an attribute - see below - should be a name value
  58. // pair and be processed here
  59. typedef detail::common_iarchive<Archive> detail_common_iarchive;
  60. template<class T>
  61. void load_override(
  62. const boost::serialization::nvp< T > & t
  63. ){
  64. this->This()->load_start(t.name());
  65. this->detail_common_iarchive::load_override(t.value());
  66. this->This()->load_end(t.name());
  67. }
  68. // specific overrides for attributes - handle as
  69. // primitives. These are not name-value pairs
  70. // so they have to be intercepted here and passed on to load.
  71. // although the class_id is included in the xml text file in order
  72. // to make the file self describing, it isn't used when loading
  73. // an xml archive. So we can skip it here. Note: we MUST override
  74. // it otherwise it will be loaded as a normal primitive w/o tag and
  75. // leaving the archive in an undetermined state
  76. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  77. load_override(class_id_type & t);
  78. void load_override(class_id_optional_type & /* t */){}
  79. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  80. load_override(object_id_type & t);
  81. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  82. load_override(version_type & t);
  83. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  84. load_override(tracking_type & t);
  85. // class_name_type can't be handled here as it depends upon the
  86. // char type used by the stream. So require the derived implementation
  87. // handle this.
  88. // void load_override(class_name_type & t);
  89. BOOST_ARCHIVE_OR_WARCHIVE_DECL
  90. basic_xml_iarchive(unsigned int flags);
  91. BOOST_ARCHIVE_OR_WARCHIVE_DECL
  92. ~basic_xml_iarchive();
  93. };
  94. } // namespace archive
  95. } // namespace boost
  96. #ifdef BOOST_MSVC
  97. #pragma warning(pop)
  98. #endif
  99. #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
  100. #endif // BOOST_ARCHIVE_BASIC_XML_IARCHIVE_HPP