basic_xml_iarchive.ipp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // basic_xml_iarchive.ipp:
  3. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  4. // Use, modification and distribution is subject to the Boost Software
  5. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. // See http://www.boost.org for updates, documentation, and revision history.
  8. #include <boost/assert.hpp>
  9. #include <cstddef> // NULL
  10. #include <algorithm>
  11. #include <boost/serialization/throw_exception.hpp>
  12. #include <boost/archive/xml_archive_exception.hpp>
  13. #include <boost/archive/basic_xml_iarchive.hpp>
  14. #include <boost/serialization/tracking.hpp>
  15. namespace boost {
  16. namespace archive {
  17. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  18. // implementation of xml_text_archive
  19. template<class Archive>
  20. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  21. basic_xml_iarchive<Archive>::load_start(const char *name){
  22. // if there's no name
  23. if(NULL == name)
  24. return;
  25. bool result = this->This()->gimpl->parse_start_tag(this->This()->get_is());
  26. if(true != result){
  27. boost::serialization::throw_exception(
  28. archive_exception(archive_exception::input_stream_error)
  29. );
  30. }
  31. // don't check start tag at highest level
  32. ++depth;
  33. return;
  34. }
  35. template<class Archive>
  36. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  37. basic_xml_iarchive<Archive>::load_end(const char *name){
  38. // if there's no name
  39. if(NULL == name)
  40. return;
  41. bool result = this->This()->gimpl->parse_end_tag(this->This()->get_is());
  42. if(true != result){
  43. boost::serialization::throw_exception(
  44. archive_exception(archive_exception::input_stream_error)
  45. );
  46. }
  47. // don't check start tag at highest level
  48. if(0 == --depth)
  49. return;
  50. if(0 == (this->get_flags() & no_xml_tag_checking)){
  51. // double check that the tag matches what is expected - useful for debug
  52. if(0 != name[this->This()->gimpl->rv.object_name.size()]
  53. || ! std::equal(
  54. this->This()->gimpl->rv.object_name.begin(),
  55. this->This()->gimpl->rv.object_name.end(),
  56. name
  57. )
  58. ){
  59. boost::serialization::throw_exception(
  60. xml_archive_exception(
  61. xml_archive_exception::xml_archive_tag_mismatch,
  62. name
  63. )
  64. );
  65. }
  66. }
  67. }
  68. template<class Archive>
  69. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  70. basic_xml_iarchive<Archive>::load_override(object_id_type & t){
  71. t = object_id_type(this->This()->gimpl->rv.object_id);
  72. }
  73. template<class Archive>
  74. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  75. basic_xml_iarchive<Archive>::load_override(version_type & t){
  76. t = version_type(this->This()->gimpl->rv.version);
  77. }
  78. template<class Archive>
  79. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  80. basic_xml_iarchive<Archive>::load_override(class_id_type & t){
  81. t = class_id_type(this->This()->gimpl->rv.class_id);
  82. }
  83. template<class Archive>
  84. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  85. basic_xml_iarchive<Archive>::load_override(tracking_type & t){
  86. t = this->This()->gimpl->rv.tracking_level;
  87. }
  88. template<class Archive>
  89. BOOST_ARCHIVE_OR_WARCHIVE_DECL
  90. basic_xml_iarchive<Archive>::basic_xml_iarchive(unsigned int flags) :
  91. detail::common_iarchive<Archive>(flags),
  92. depth(0)
  93. {}
  94. template<class Archive>
  95. BOOST_ARCHIVE_OR_WARCHIVE_DECL
  96. basic_xml_iarchive<Archive>::~basic_xml_iarchive(){
  97. }
  98. } // namespace archive
  99. } // namespace boost