Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:29

0001 #ifndef BOOST_ARCHIVE_ITERATORS_REMOVE_WHITESPACE_HPP
0002 #define BOOST_ARCHIVE_ITERATORS_REMOVE_WHITESPACE_HPP
0003 
0004 // MS compatible compilers support #pragma once
0005 #if defined(_MSC_VER)
0006 # pragma once
0007 #endif
0008 
0009 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0010 // remove_whitespace.hpp
0011 
0012 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
0013 // Use, modification and distribution is subject to the Boost Software
0014 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0015 // http://www.boost.org/LICENSE_1_0.txt)
0016 
0017 //  See http://www.boost.org for updates, documentation, and revision history.
0018 
0019 #include <boost/assert.hpp>
0020 
0021 #include <boost/iterator/iterator_adaptor.hpp>
0022 #include <boost/iterator/filter_iterator.hpp>
0023 #include <boost/iterator/iterator_traits.hpp>
0024 
0025 // here is the default standard implementation of the functor used
0026 // by the filter iterator to remove spaces.  Unfortunately usage
0027 // of this implementation in combination with spirit trips a bug
0028 // VC 6.5.  The only way I can find to work around it is to
0029 // implement a special non-standard version for this platform
0030 
0031 #ifndef BOOST_NO_CWCTYPE
0032 #include <cwctype> // iswspace
0033 #if defined(BOOST_NO_STDC_NAMESPACE)
0034 namespace std{ using ::iswspace; }
0035 #endif
0036 #endif
0037 
0038 #include <cctype> // isspace
0039 #if defined(BOOST_NO_STDC_NAMESPACE)
0040 namespace std{ using ::isspace; }
0041 #endif
0042 
0043 #if defined(__STD_RWCOMPILER_H__) || defined(_RWSTD_VER)
0044 // this is required for the RW STL on Linux and Tru64.
0045 #undef isspace
0046 #undef iswspace
0047 #endif
0048 
0049 namespace { // anonymous
0050 
0051 template<class CharType>
0052 struct remove_whitespace_predicate;
0053 
0054 template<>
0055 struct remove_whitespace_predicate<char>
0056 {
0057     bool operator()(unsigned char t){
0058         return ! std::isspace(t);
0059     }
0060 };
0061 
0062 #ifndef BOOST_NO_CWCHAR
0063 template<>
0064 struct remove_whitespace_predicate<wchar_t>
0065 {
0066     bool operator()(wchar_t t){
0067         return ! std::iswspace(t);
0068     }
0069 };
0070 #endif
0071 
0072 } // namespace anonymous
0073 
0074 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0075 // convert base64 file data (including whitespace and padding) to binary
0076 
0077 namespace boost {
0078 namespace archive {
0079 namespace iterators {
0080 
0081 // custom version of filter iterator which doesn't look ahead further than
0082 // necessary
0083 
0084 template<class Predicate, class Base>
0085 class filter_iterator
0086     : public boost::iterator_adaptor<
0087         filter_iterator<Predicate, Base>,
0088         Base,
0089         use_default,
0090         single_pass_traversal_tag
0091     >
0092 {
0093     friend class boost::iterator_core_access;
0094     typedef typename boost::iterator_adaptor<
0095         filter_iterator<Predicate, Base>,
0096         Base,
0097         use_default,
0098         single_pass_traversal_tag
0099     > super_t;
0100     typedef filter_iterator<Predicate, Base> this_t;
0101     typedef typename super_t::reference reference_type;
0102 
0103     reference_type dereference_impl(){
0104         if(! m_full){
0105             while(! m_predicate(* this->base_reference()))
0106                 ++(this->base_reference());
0107             m_full = true;
0108         }
0109         return * this->base_reference();
0110     }
0111 
0112     reference_type dereference() const {
0113         return const_cast<this_t *>(this)->dereference_impl();
0114     }
0115 
0116     Predicate m_predicate;
0117     bool m_full;
0118 public:
0119     // note: this function is public only because comeau compiler complained
0120     // I don't know if this is because the compiler is wrong or what
0121     void increment(){
0122         m_full = false;
0123         ++(this->base_reference());
0124     }
0125     filter_iterator(Base start) :
0126         super_t(start),
0127         m_full(false)
0128     {}
0129     filter_iterator(){}
0130 };
0131 
0132 template<class Base>
0133 class remove_whitespace :
0134     public filter_iterator<
0135         remove_whitespace_predicate<
0136             typename boost::iterator_value<Base>::type
0137             //typename Base::value_type
0138         >,
0139         Base
0140     >
0141 {
0142     friend class boost::iterator_core_access;
0143     typedef filter_iterator<
0144         remove_whitespace_predicate<
0145             typename boost::iterator_value<Base>::type
0146             //typename Base::value_type
0147         >,
0148         Base
0149     > super_t;
0150 public:
0151 //    remove_whitespace(){} // why is this needed?
0152     // make composable by using templated constructor
0153     template<class T>
0154     remove_whitespace(T start) :
0155         super_t(Base(static_cast< T >(start)))
0156     {}
0157     // intel 7.1 doesn't like default copy constructor
0158     remove_whitespace(const remove_whitespace & rhs) :
0159         super_t(rhs.base_reference())
0160     {}
0161 };
0162 
0163 } // namespace iterators
0164 } // namespace archive
0165 } // namespace boost
0166 
0167 #endif // BOOST_ARCHIVE_ITERATORS_REMOVE_WHITESPACE_HPP