• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <algorithm>
14
15#include <boost/serialization/throw_exception.hpp>
16#include <boost/archive/xml_archive_exception.hpp>
17#include <boost/archive/basic_xml_iarchive.hpp>
18#include <boost/serialization/tracking.hpp>
19
20namespace boost {
21namespace archive {
22
23/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
24// implementation of xml_text_archive
25
26template<class Archive>
27BOOST_ARCHIVE_OR_WARCHIVE_DECL void
28basic_xml_iarchive<Archive>::load_start(const char *name){
29    // if there's no name
30    if(NULL == name)
31        return;
32    bool result = this->This()->gimpl->parse_start_tag(this->This()->get_is());
33    if(true != result){
34        boost::serialization::throw_exception(
35            archive_exception(archive_exception::input_stream_error)
36        );
37    }
38    // don't check start tag at highest level
39    ++depth;
40}
41
42template<class Archive>
43BOOST_ARCHIVE_OR_WARCHIVE_DECL void
44basic_xml_iarchive<Archive>::load_end(const char *name){
45    // if there's no name
46    if(NULL == name)
47        return;
48    bool result = this->This()->gimpl->parse_end_tag(this->This()->get_is());
49    if(true != result){
50        boost::serialization::throw_exception(
51            archive_exception(archive_exception::input_stream_error)
52        );
53    }
54
55    // don't check start tag at highest level
56    if(0 == --depth)
57        return;
58
59    if(0 == (this->get_flags() & no_xml_tag_checking)){
60        // double check that the tag matches what is expected - useful for debug
61        if(0 != name[this->This()->gimpl->rv.object_name.size()]
62        || ! std::equal(
63                this->This()->gimpl->rv.object_name.begin(),
64                this->This()->gimpl->rv.object_name.end(),
65                name
66            )
67        ){
68            boost::serialization::throw_exception(
69                xml_archive_exception(
70                    xml_archive_exception::xml_archive_tag_mismatch,
71                    name
72                )
73            );
74        }
75    }
76}
77
78template<class Archive>
79BOOST_ARCHIVE_OR_WARCHIVE_DECL void
80basic_xml_iarchive<Archive>::load_override(object_id_type & t){
81    t = object_id_type(this->This()->gimpl->rv.object_id);
82}
83
84template<class Archive>
85BOOST_ARCHIVE_OR_WARCHIVE_DECL void
86basic_xml_iarchive<Archive>::load_override(version_type & t){
87    t = version_type(this->This()->gimpl->rv.version);
88}
89
90template<class Archive>
91BOOST_ARCHIVE_OR_WARCHIVE_DECL void
92basic_xml_iarchive<Archive>::load_override(class_id_type & t){
93    t = class_id_type(this->This()->gimpl->rv.class_id);
94}
95
96template<class Archive>
97BOOST_ARCHIVE_OR_WARCHIVE_DECL void
98basic_xml_iarchive<Archive>::load_override(tracking_type & t){
99    t = this->This()->gimpl->rv.tracking_level;
100}
101
102template<class Archive>
103BOOST_ARCHIVE_OR_WARCHIVE_DECL
104basic_xml_iarchive<Archive>::basic_xml_iarchive(unsigned int flags) :
105    detail::common_iarchive<Archive>(flags),
106    depth(0)
107{}
108template<class Archive>
109BOOST_ARCHIVE_OR_WARCHIVE_DECL
110basic_xml_iarchive<Archive>::~basic_xml_iarchive(){
111}
112
113} // namespace archive
114} // namespace boost
115