Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / archive / iterators / remove_whitespace.hpp @ 2486

History | View | Annotate | Download (4.4 kB)

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