1 #ifndef BOOST_ARCHIVE_ITERATORS_REMOVE_WHITESPACE_HPP
2 #define BOOST_ARCHIVE_ITERATORS_REMOVE_WHITESPACE_HPP
4 // MS compatible compilers support #pragma once
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // remove_whitespace.hpp
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)
17 // See http://www.boost.org for updates, documentation, and revision history.
19 #include <boost/assert.hpp>
21 #include <boost/iterator/iterator_adaptor.hpp>
22 #include <boost/iterator/filter_iterator.hpp>
23 #include <boost/iterator/iterator_traits.hpp>
25 // here is the default standard implementation of the functor used
26 // by the filter iterator to remove spaces. Unfortunately usage
27 // of this implementation in combination with spirit trips a bug
28 // VC 6.5. The only way I can find to work around it is to
29 // implement a special non-standard version for this platform
31 #ifndef BOOST_NO_CWCTYPE
32 #include <cwctype> // iswspace
33 #if defined(BOOST_NO_STDC_NAMESPACE)
34 namespace std{ using ::iswspace; }
38 #include <cctype> // isspace
39 #if defined(BOOST_NO_STDC_NAMESPACE)
40 namespace std{ using ::isspace; }
43 #if defined(__STD_RWCOMPILER_H__) || defined(_RWSTD_VER)
44 // this is required for the RW STL on Linux and Tru64.
49 namespace { // anonymous
51 template<class CharType>
52 struct remove_whitespace_predicate;
55 struct remove_whitespace_predicate<char>
57 bool operator()(unsigned char t){
58 return ! std::isspace(t);
62 #ifndef BOOST_NO_CWCHAR
64 struct remove_whitespace_predicate<wchar_t>
66 bool operator()(wchar_t t){
67 return ! std::iswspace(t);
72 } // namespace anonymous
74 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
75 // convert base64 file data (including whitespace and padding) to binary
81 // custom version of filter iterator which doesn't look ahead further than
84 template<class Predicate, class Base>
86 : public boost::iterator_adaptor<
87 filter_iterator<Predicate, Base>,
90 single_pass_traversal_tag
93 friend class boost::iterator_core_access;
94 typedef typename boost::iterator_adaptor<
95 filter_iterator<Predicate, Base>,
98 single_pass_traversal_tag
100 typedef filter_iterator<Predicate, Base> this_t;
101 typedef typename super_t::reference reference_type;
103 reference_type dereference_impl(){
105 while(! m_predicate(* this->base_reference()))
106 ++(this->base_reference());
109 return * this->base_reference();
112 reference_type dereference() const {
113 return const_cast<this_t *>(this)->dereference_impl();
116 Predicate m_predicate;
119 // note: this function is public only because comeau compiler complained
120 // I don't know if this is because the compiler is wrong or what
123 ++(this->base_reference());
125 filter_iterator(Base start) :
133 class remove_whitespace :
134 public filter_iterator<
135 remove_whitespace_predicate<
136 typename boost::iterator_value<Base>::type
137 //typename Base::value_type
142 friend class boost::iterator_core_access;
143 typedef filter_iterator<
144 remove_whitespace_predicate<
145 typename boost::iterator_value<Base>::type
146 //typename Base::value_type
151 // remove_whitespace(){} // why is this needed?
152 // make composible buy using templated constructor
154 remove_whitespace(T start) :
155 super_t(Base(static_cast< T >(start)))
157 // intel 7.1 doesn't like default copy constructor
158 remove_whitespace(const remove_whitespace & rhs) :
159 super_t(rhs.base_reference())
163 } // namespace iterators
164 } // namespace archive
167 #endif // BOOST_ARCHIVE_ITERATORS_REMOVE_WHITESPACE_HPP