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