1 | #ifndef BOOST_ARCHIVE_ITERATORS_ESCAPE_HPP
|
---|
2 | #define BOOST_ARCHIVE_ITERATORS_ESCAPE_HPP
|
---|
3 |
|
---|
4 | // MS compatible compilers support #pragma once
|
---|
5 | #if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
---|
6 | # pragma once
|
---|
7 | #endif
|
---|
8 |
|
---|
9 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
---|
10 | // escape.hpp
|
---|
11 |
|
---|
12 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
---|
13 | // Use, modification and distribution is subject to the Boost Software
|
---|
14 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
---|
15 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
16 |
|
---|
17 | // See http://www.boost.org for updates, documentation, and revision history.
|
---|
18 |
|
---|
19 | #include <cassert>
|
---|
20 |
|
---|
21 | #include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
|
---|
22 | #include <boost/iterator/iterator_adaptor.hpp>
|
---|
23 | #include <boost/iterator/iterator_traits.hpp>
|
---|
24 |
|
---|
25 | namespace boost {
|
---|
26 | namespace archive {
|
---|
27 | namespace iterators {
|
---|
28 |
|
---|
29 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
---|
30 | // insert escapes into text
|
---|
31 |
|
---|
32 | template<class Derived, class Base>
|
---|
33 | class escape :
|
---|
34 | public boost::iterator_adaptor<
|
---|
35 | Derived,
|
---|
36 | Base,
|
---|
37 | BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type,
|
---|
38 | single_pass_traversal_tag,
|
---|
39 | BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
|
---|
40 | >{
|
---|
41 | typedef BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type base_value_type;
|
---|
42 | typedef BOOST_DEDUCED_TYPENAME boost::iterator_reference<Base>::type reference_type;
|
---|
43 | friend class boost::iterator_core_access;
|
---|
44 |
|
---|
45 | typedef BOOST_DEDUCED_TYPENAME boost::iterator_adaptor<
|
---|
46 | Derived,
|
---|
47 | Base,
|
---|
48 | base_value_type,
|
---|
49 | single_pass_traversal_tag,
|
---|
50 | base_value_type
|
---|
51 | > super_t;
|
---|
52 |
|
---|
53 | typedef escape<Derived, Base> this_t;
|
---|
54 |
|
---|
55 | bool equal(const this_t & rhs) const {
|
---|
56 | return
|
---|
57 | NULL == m_bnext
|
---|
58 | && NULL == m_bend
|
---|
59 | && this->base_reference() == rhs.base_reference()
|
---|
60 | ;
|
---|
61 | }
|
---|
62 |
|
---|
63 | //Access the value referred to
|
---|
64 | reference_type dereference() const {
|
---|
65 | return m_current_value;
|
---|
66 | }
|
---|
67 |
|
---|
68 | void increment(){
|
---|
69 | if(++m_bnext < m_bend){
|
---|
70 | m_current_value = *m_bnext;
|
---|
71 | return;
|
---|
72 | }
|
---|
73 | ++(this->base_reference());
|
---|
74 | m_bnext = NULL;
|
---|
75 | m_bend = NULL;
|
---|
76 | m_current_value = (static_cast<Derived *>(this))->fill(m_bnext, m_bend);
|
---|
77 | }
|
---|
78 |
|
---|
79 | // buffer to handle pending characters
|
---|
80 | const base_value_type *m_bnext;
|
---|
81 | const base_value_type *m_bend;
|
---|
82 | BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type m_current_value;
|
---|
83 | bool m_full;
|
---|
84 | public:
|
---|
85 | escape(Base base) :
|
---|
86 | super_t(base),
|
---|
87 | m_bnext(NULL),
|
---|
88 | m_bend(NULL)
|
---|
89 | {
|
---|
90 | m_current_value = static_cast<Derived *>(this)->fill(m_bnext, m_bend);
|
---|
91 | }
|
---|
92 | };
|
---|
93 |
|
---|
94 | } // namespace iterators
|
---|
95 | } // namespace archive
|
---|
96 | } // namespace boost
|
---|
97 |
|
---|
98 | #endif // BOOST_ARCHIVE_ITERATORS_ESCAPE_HPP
|
---|