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