comparison DEPENDENCIES/generic/include/boost/archive/iterators/remove_whitespace.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_REMOVE_WHITESPACE_HPP
2 #define BOOST_ARCHIVE_ITERATORS_REMOVE_WHITESPACE_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 // remove_whitespace.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
21 #include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
22
23 #include <boost/serialization/pfto.hpp>
24
25 #include <boost/iterator/iterator_adaptor.hpp>
26 #include <boost/iterator/filter_iterator.hpp>
27 #include <boost/iterator/iterator_traits.hpp>
28
29 //#include <boost/detail/workaround.hpp>
30 //#if ! BOOST_WORKAROUND(BOOST_MSVC, <=1300)
31
32 // here is the default standard implementation of the functor used
33 // by the filter iterator to remove spaces. Unfortunately usage
34 // of this implementation in combination with spirit trips a bug
35 // VC 6.5. The only way I can find to work around it is to
36 // implement a special non-standard version for this platform
37
38 #ifndef BOOST_NO_CWCTYPE
39 #include <cwctype> // iswspace
40 #if defined(BOOST_NO_STDC_NAMESPACE)
41 namespace std{ using ::iswspace; }
42 #endif
43 #endif
44
45 #include <cctype> // isspace
46 #if defined(BOOST_NO_STDC_NAMESPACE)
47 namespace std{ using ::isspace; }
48 #endif
49
50 #if defined(__STD_RWCOMPILER_H__) || defined(_RWSTD_VER)
51 // this is required for the RW STL on Linux and Tru64.
52 #undef isspace
53 #undef iswspace
54 #endif
55
56 //#endif // BOOST_WORKAROUND
57
58 namespace { // anonymous
59
60 template<class CharType>
61 struct remove_whitespace_predicate;
62
63 template<>
64 struct remove_whitespace_predicate<char>
65 {
66 bool operator()(unsigned char t){
67 return ! std::isspace(t);
68 }
69 };
70
71 #ifndef BOOST_NO_CWCHAR
72 template<>
73 struct remove_whitespace_predicate<wchar_t>
74 {
75 bool operator()(wchar_t t){
76 return ! std::iswspace(t);
77 }
78 };
79 #endif
80
81 } // namespace anonymous
82
83 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
84 // convert base64 file data (including whitespace and padding) to binary
85
86 namespace boost {
87 namespace archive {
88 namespace iterators {
89
90 // custom version of filter iterator which doesn't look ahead further than
91 // necessary
92
93 template<class Predicate, class Base>
94 class filter_iterator
95 : public boost::iterator_adaptor<
96 filter_iterator<Predicate, Base>,
97 Base,
98 use_default,
99 single_pass_traversal_tag
100 >
101 {
102 friend class boost::iterator_core_access;
103 typedef BOOST_DEDUCED_TYPENAME boost::iterator_adaptor<
104 filter_iterator<Predicate, Base>,
105 Base,
106 use_default,
107 single_pass_traversal_tag
108 > super_t;
109 typedef filter_iterator<Predicate, Base> this_t;
110 typedef BOOST_DEDUCED_TYPENAME super_t::reference reference_type;
111
112 reference_type dereference_impl(){
113 if(! m_full){
114 while(! m_predicate(* this->base_reference()))
115 ++(this->base_reference());
116 m_full = true;
117 }
118 return * this->base_reference();
119 }
120
121 reference_type dereference() const {
122 return const_cast<this_t *>(this)->dereference_impl();
123 }
124
125 Predicate m_predicate;
126 bool m_full;
127 public:
128 // note: this function is public only because comeau compiler complained
129 // I don't know if this is because the compiler is wrong or what
130 void increment(){
131 m_full = false;
132 ++(this->base_reference());
133 }
134 filter_iterator(Base start) :
135 super_t(start),
136 m_full(false)
137 {}
138 filter_iterator(){}
139 };
140
141 template<class Base>
142 class remove_whitespace :
143 public filter_iterator<
144 remove_whitespace_predicate<
145 BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
146 //BOOST_DEDUCED_TYPENAME Base::value_type
147 >,
148 Base
149 >
150 {
151 friend class boost::iterator_core_access;
152 typedef filter_iterator<
153 remove_whitespace_predicate<
154 BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
155 //BOOST_DEDUCED_TYPENAME Base::value_type
156 >,
157 Base
158 > super_t;
159 public:
160 // remove_whitespace(){} // why is this needed?
161 // make composible buy using templated constructor
162 template<class T>
163 remove_whitespace(BOOST_PFTO_WRAPPER(T) start) :
164 super_t(Base(BOOST_MAKE_PFTO_WRAPPER(static_cast< T >(start))))
165 {}
166 // intel 7.1 doesn't like default copy constructor
167 remove_whitespace(const remove_whitespace & rhs) :
168 super_t(rhs.base_reference())
169 {}
170 };
171
172 } // namespace iterators
173 } // namespace archive
174 } // namespace boost
175
176 #endif // BOOST_ARCHIVE_ITERATORS_REMOVE_WHITESPACE_HPP