source: NonGTP/Boost/boost/archive/iterators/remove_whitespace.hpp @ 857

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