comparison DEPENDENCIES/generic/include/boost/archive/iterators/escape.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
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 <boost/assert.hpp>
20 #include <cstddef> // NULL
21
22 #include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
23 #include <boost/iterator/iterator_adaptor.hpp>
24 #include <boost/iterator/iterator_traits.hpp>
25
26 namespace boost {
27 namespace archive {
28 namespace iterators {
29
30 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
31 // insert escapes into text
32
33 template<class Derived, class Base>
34 class escape :
35 public boost::iterator_adaptor<
36 Derived,
37 Base,
38 BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type,
39 single_pass_traversal_tag,
40 BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
41 >
42 {
43 typedef BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type base_value_type;
44 typedef BOOST_DEDUCED_TYPENAME boost::iterator_reference<Base>::type reference_type;
45 friend class boost::iterator_core_access;
46
47 typedef BOOST_DEDUCED_TYPENAME boost::iterator_adaptor<
48 Derived,
49 Base,
50 base_value_type,
51 single_pass_traversal_tag,
52 base_value_type
53 > super_t;
54
55 typedef escape<Derived, Base> this_t;
56
57 void dereference_impl() {
58 m_current_value = static_cast<Derived *>(this)->fill(m_bnext, m_bend);
59 m_full = true;
60 }
61
62 //Access the value referred to
63 reference_type dereference() const {
64 if(!m_full)
65 const_cast<this_t *>(this)->dereference_impl();
66 return m_current_value;
67 }
68
69 bool equal(const this_t & rhs) const {
70 if(m_full){
71 if(! rhs.m_full)
72 const_cast<this_t *>(& rhs)->dereference_impl();
73 }
74 else{
75 if(rhs.m_full)
76 const_cast<this_t *>(this)->dereference_impl();
77 }
78 if(m_bnext != rhs.m_bnext)
79 return false;
80 if(this->base_reference() != rhs.base_reference())
81 return false;
82 return true;
83 }
84
85 void increment(){
86 if(++m_bnext < m_bend){
87 m_current_value = *m_bnext;
88 return;
89 }
90 ++(this->base_reference());
91 m_bnext = NULL;
92 m_bend = NULL;
93 m_full = false;
94 }
95
96 // buffer to handle pending characters
97 const base_value_type *m_bnext;
98 const base_value_type *m_bend;
99 bool m_full;
100 base_value_type m_current_value;
101 public:
102 escape(Base base) :
103 super_t(base),
104 m_bnext(NULL),
105 m_bend(NULL),
106 m_full(false)
107 {
108 }
109 };
110
111 } // namespace iterators
112 } // namespace archive
113 } // namespace boost
114
115 #endif // BOOST_ARCHIVE_ITERATORS_ESCAPE_HPP