basic_xml_iarchive.ipp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 <cstring> // strlen
  11. #include <algorithm>
  12. #include <boost/serialization/throw_exception.hpp>
  13. #include <boost/archive/xml_archive_exception.hpp>
  14. #include <boost/archive/basic_xml_iarchive.hpp>
  15. #include <boost/serialization/tracking.hpp>
  16. namespace boost {
  17. namespace archive {
  18. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  19. // implementation of xml_text_archive
  20. template<class Archive>
  21. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  22. basic_xml_iarchive<Archive>::load_start(const char *name){
  23. // if there's no name
  24. if(NULL == name)
  25. return;
  26. bool result = this->This()->gimpl->parse_start_tag(this->This()->get_is());
  27. if(true != result){
  28. boost::serialization::throw_exception(
  29. archive_exception(archive_exception::input_stream_error)
  30. );
  31. }
  32. // don't check start tag at highest level
  33. ++depth;
  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. std::size_t parameter_name_length = std::strlen(name);
  53. std::size_t object_name_length = this->This()->gimpl->rv.object_name.size();
  54. if(parameter_name_length != object_name_length
  55. || ! std::equal(
  56. this->This()->gimpl->rv.object_name.begin(),
  57. this->This()->gimpl->rv.object_name.end(),
  58. name
  59. )
  60. ){
  61. boost::serialization::throw_exception(
  62. xml_archive_exception(
  63. xml_archive_exception::xml_archive_tag_mismatch,
  64. name
  65. )
  66. );
  67. }
  68. }
  69. }
  70. template<class Archive>
  71. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  72. basic_xml_iarchive<Archive>::load_override(object_id_type & t){
  73. t = object_id_type(this->This()->gimpl->rv.object_id);
  74. }
  75. template<class Archive>
  76. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  77. basic_xml_iarchive<Archive>::load_override(version_type & t){
  78. t = version_type(this->This()->gimpl->rv.version);
  79. }
  80. template<class Archive>
  81. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  82. basic_xml_iarchive<Archive>::load_override(class_id_type & t){
  83. t = class_id_type(this->This()->gimpl->rv.class_id);
  84. }
  85. template<class Archive>
  86. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  87. basic_xml_iarchive<Archive>::load_override(tracking_type & t){
  88. t = this->This()->gimpl->rv.tracking_level;
  89. }
  90. template<class Archive>
  91. BOOST_ARCHIVE_OR_WARCHIVE_DECL
  92. basic_xml_iarchive<Archive>::basic_xml_iarchive(unsigned int flags) :
  93. detail::common_iarchive<Archive>(flags),
  94. depth(0)
  95. {}
  96. template<class Archive>
  97. BOOST_ARCHIVE_OR_WARCHIVE_DECL
  98. basic_xml_iarchive<Archive>::~basic_xml_iarchive(){
  99. }
  100. } // namespace archive
  101. } // namespace boost