basic_xml_iarchive.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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) && (_MSC_VER >= 1020)
  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/serialization/pfto.hpp>
  16. #include <boost/detail/workaround.hpp>
  17. #include <boost/archive/detail/common_iarchive.hpp>
  18. #include <boost/serialization/nvp.hpp>
  19. #include <boost/serialization/string.hpp>
  20. #include <boost/mpl/assert.hpp>
  21. #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
  22. #ifdef BOOST_MSVC
  23. # pragma warning(push)
  24. # pragma warning(disable : 4511 4512)
  25. #endif
  26. namespace boost {
  27. namespace archive {
  28. /////////////////////////////////////////////////////////////////////////
  29. // class xml_iarchive - read serialized objects from a input text stream
  30. template<class Archive>
  31. class basic_xml_iarchive :
  32. public detail::common_iarchive<Archive>
  33. {
  34. protected:
  35. #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  36. public:
  37. #elif defined(BOOST_MSVC)
  38. // for some inexplicable reason insertion of "class" generates compile erro
  39. // on msvc 7.1
  40. friend detail::interface_oarchive<Archive>;
  41. #else
  42. friend class detail::interface_oarchive<Archive>;
  43. #endif
  44. unsigned int depth;
  45. BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
  46. load_start(const char *name);
  47. BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
  48. load_end(const char *name);
  49. // Anything not an attribute and not a name-value pair is an
  50. // should be trapped here.
  51. template<class T>
  52. void load_override(T & t, BOOST_PFTO int)
  53. {
  54. // If your program fails to compile here, its most likely due to
  55. // not specifying an nvp wrapper around the variable to
  56. // be serialized.
  57. BOOST_MPL_ASSERT((serialization::is_wrapper< T >));
  58. this->detail_common_iarchive::load_override(t, 0);
  59. }
  60. // Anything not an attribute - see below - should be a name value
  61. // pair and be processed here
  62. typedef detail::common_iarchive<Archive> detail_common_iarchive;
  63. template<class T>
  64. void load_override(
  65. #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  66. const
  67. #endif
  68. boost::serialization::nvp< T > & t,
  69. int
  70. ){
  71. this->This()->load_start(t.name());
  72. this->detail_common_iarchive::load_override(t.value(), 0);
  73. this->This()->load_end(t.name());
  74. }
  75. // specific overrides for attributes - handle as
  76. // primitives. These are not name-value pairs
  77. // so they have to be intercepted here and passed on to load.
  78. // although the class_id is included in the xml text file in order
  79. // to make the file self describing, it isn't used when loading
  80. // an xml archive. So we can skip it here. Note: we MUST override
  81. // it otherwise it will be loaded as a normal primitive w/o tag and
  82. // leaving the archive in an undetermined state
  83. void load_override(class_id_optional_type & /* t */, int){}
  84. BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
  85. load_override(object_id_type & t, int);
  86. BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
  87. load_override(version_type & t, int);
  88. BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
  89. load_override(class_id_type & t, int);
  90. BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
  91. load_override(tracking_type & t, int);
  92. // class_name_type can't be handled here as it depends upon the
  93. // char type used by the stream. So require the derived implementation
  94. // handle this.
  95. // void load_override(class_name_type & t, int);
  96. BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
  97. basic_xml_iarchive(unsigned int flags);
  98. BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
  99. ~basic_xml_iarchive();
  100. };
  101. } // namespace archive
  102. } // namespace boost
  103. #ifdef BOOST_MSVC
  104. #pragma warning(pop)
  105. #endif
  106. #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
  107. #endif // BOOST_ARCHIVE_BASIC_XML_IARCHIVE_HPP