annotate DEPENDENCIES/generic/include/boost/archive/iterators/remove_whitespace.hpp @ 125:34e428693f5d vext

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