annotate DEPENDENCIES/generic/include/boost/archive/iterators/remove_whitespace.hpp @ 16:2665513ce2d3

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