]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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) | |
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 <boost/assert.hpp> | |
20 | #include <cstddef> // NULL | |
21 | ||
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 | typename boost::iterator_value<Base>::type, | |
38 | single_pass_traversal_tag, | |
39 | typename boost::iterator_value<Base>::type | |
40 | > | |
41 | { | |
42 | typedef typename boost::iterator_value<Base>::type base_value_type; | |
43 | typedef typename boost::iterator_reference<Base>::type reference_type; | |
44 | friend class boost::iterator_core_access; | |
45 | ||
46 | typedef typename boost::iterator_adaptor< | |
47 | Derived, | |
48 | Base, | |
49 | base_value_type, | |
50 | single_pass_traversal_tag, | |
51 | base_value_type | |
52 | > super_t; | |
53 | ||
54 | typedef escape<Derived, Base> this_t; | |
55 | ||
56 | void dereference_impl() { | |
57 | m_current_value = static_cast<Derived *>(this)->fill(m_bnext, m_bend); | |
58 | m_full = true; | |
59 | } | |
60 | ||
61 | //Access the value referred to | |
62 | reference_type dereference() const { | |
63 | if(!m_full) | |
64 | const_cast<this_t *>(this)->dereference_impl(); | |
65 | return m_current_value; | |
66 | } | |
67 | ||
68 | bool equal(const this_t & rhs) const { | |
69 | if(m_full){ | |
70 | if(! rhs.m_full) | |
71 | const_cast<this_t *>(& rhs)->dereference_impl(); | |
72 | } | |
73 | else{ | |
74 | if(rhs.m_full) | |
75 | const_cast<this_t *>(this)->dereference_impl(); | |
76 | } | |
77 | if(m_bnext != rhs.m_bnext) | |
78 | return false; | |
79 | if(this->base_reference() != rhs.base_reference()) | |
80 | return false; | |
81 | return true; | |
82 | } | |
83 | ||
84 | void increment(){ | |
85 | if(++m_bnext < m_bend){ | |
86 | m_current_value = *m_bnext; | |
87 | return; | |
88 | } | |
89 | ++(this->base_reference()); | |
90 | m_bnext = NULL; | |
91 | m_bend = NULL; | |
92 | m_full = false; | |
93 | } | |
94 | ||
95 | // buffer to handle pending characters | |
96 | const base_value_type *m_bnext; | |
97 | const base_value_type *m_bend; | |
98 | bool m_full; | |
99 | base_value_type m_current_value; | |
100 | public: | |
101 | escape(Base base) : | |
102 | super_t(base), | |
103 | m_bnext(NULL), | |
104 | m_bend(NULL), | |
105 | m_full(false) | |
106 | { | |
107 | } | |
108 | }; | |
109 | ||
110 | } // namespace iterators | |
111 | } // namespace archive | |
112 | } // namespace boost | |
113 | ||
114 | #endif // BOOST_ARCHIVE_ITERATORS_ESCAPE_HPP |