Chris@16: #ifndef BOOST_ARCHIVE_ITERATORS_REMOVE_WHITESPACE_HPP Chris@16: #define BOOST_ARCHIVE_ITERATORS_REMOVE_WHITESPACE_HPP Chris@16: Chris@16: // MS compatible compilers support #pragma once Chris@101: #if defined(_MSC_VER) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 Chris@16: // remove_whitespace.hpp Chris@16: Chris@16: // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // See http://www.boost.org for updates, documentation, and revision history. Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: // here is the default standard implementation of the functor used Chris@16: // by the filter iterator to remove spaces. Unfortunately usage Chris@16: // of this implementation in combination with spirit trips a bug Chris@16: // VC 6.5. The only way I can find to work around it is to Chris@16: // implement a special non-standard version for this platform Chris@16: Chris@16: #ifndef BOOST_NO_CWCTYPE Chris@16: #include // iswspace Chris@16: #if defined(BOOST_NO_STDC_NAMESPACE) Chris@16: namespace std{ using ::iswspace; } Chris@16: #endif Chris@16: #endif Chris@16: Chris@16: #include // isspace Chris@16: #if defined(BOOST_NO_STDC_NAMESPACE) Chris@16: namespace std{ using ::isspace; } Chris@16: #endif Chris@16: Chris@16: #if defined(__STD_RWCOMPILER_H__) || defined(_RWSTD_VER) Chris@16: // this is required for the RW STL on Linux and Tru64. Chris@16: #undef isspace Chris@16: #undef iswspace Chris@16: #endif Chris@16: Chris@16: namespace { // anonymous Chris@16: Chris@16: template Chris@16: struct remove_whitespace_predicate; Chris@16: Chris@16: template<> Chris@16: struct remove_whitespace_predicate Chris@16: { Chris@16: bool operator()(unsigned char t){ Chris@16: return ! std::isspace(t); Chris@16: } Chris@16: }; Chris@16: Chris@16: #ifndef BOOST_NO_CWCHAR Chris@16: template<> Chris@16: struct remove_whitespace_predicate Chris@16: { Chris@16: bool operator()(wchar_t t){ Chris@16: return ! std::iswspace(t); Chris@16: } Chris@16: }; Chris@16: #endif Chris@16: Chris@16: } // namespace anonymous Chris@16: Chris@16: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 Chris@16: // convert base64 file data (including whitespace and padding) to binary Chris@16: Chris@16: namespace boost { Chris@16: namespace archive { Chris@16: namespace iterators { Chris@16: Chris@16: // custom version of filter iterator which doesn't look ahead further than Chris@16: // necessary Chris@16: Chris@16: template Chris@16: class filter_iterator Chris@16: : public boost::iterator_adaptor< Chris@16: filter_iterator, Chris@16: Base, Chris@16: use_default, Chris@16: single_pass_traversal_tag Chris@16: > Chris@16: { Chris@16: friend class boost::iterator_core_access; Chris@101: typedef typename boost::iterator_adaptor< Chris@16: filter_iterator, Chris@16: Base, Chris@16: use_default, Chris@16: single_pass_traversal_tag Chris@16: > super_t; Chris@16: typedef filter_iterator this_t; Chris@101: typedef typename super_t::reference reference_type; Chris@16: Chris@16: reference_type dereference_impl(){ Chris@16: if(! m_full){ Chris@16: while(! m_predicate(* this->base_reference())) Chris@16: ++(this->base_reference()); Chris@16: m_full = true; Chris@16: } Chris@16: return * this->base_reference(); Chris@16: } Chris@16: Chris@16: reference_type dereference() const { Chris@16: return const_cast(this)->dereference_impl(); Chris@16: } Chris@16: Chris@16: Predicate m_predicate; Chris@16: bool m_full; Chris@16: public: Chris@16: // note: this function is public only because comeau compiler complained Chris@16: // I don't know if this is because the compiler is wrong or what Chris@16: void increment(){ Chris@16: m_full = false; Chris@16: ++(this->base_reference()); Chris@16: } Chris@16: filter_iterator(Base start) : Chris@16: super_t(start), Chris@16: m_full(false) Chris@16: {} Chris@16: filter_iterator(){} Chris@16: }; Chris@16: Chris@16: template Chris@16: class remove_whitespace : Chris@16: public filter_iterator< Chris@16: remove_whitespace_predicate< Chris@101: typename boost::iterator_value::type Chris@101: //typename Base::value_type Chris@16: >, Chris@16: Base Chris@16: > Chris@16: { Chris@16: friend class boost::iterator_core_access; Chris@16: typedef filter_iterator< Chris@16: remove_whitespace_predicate< Chris@101: typename boost::iterator_value::type Chris@101: //typename Base::value_type Chris@16: >, Chris@16: Base Chris@16: > super_t; Chris@16: public: Chris@16: // remove_whitespace(){} // why is this needed? Chris@16: // make composible buy using templated constructor Chris@16: template Chris@16: remove_whitespace(BOOST_PFTO_WRAPPER(T) start) : Chris@16: super_t(Base(BOOST_MAKE_PFTO_WRAPPER(static_cast< T >(start)))) Chris@16: {} Chris@16: // intel 7.1 doesn't like default copy constructor Chris@16: remove_whitespace(const remove_whitespace & rhs) : Chris@16: super_t(rhs.base_reference()) Chris@16: {} Chris@16: }; Chris@16: Chris@16: } // namespace iterators Chris@16: } // namespace archive Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_ARCHIVE_ITERATORS_REMOVE_WHITESPACE_HPP