remove_whitespace.hpp 4.8 KB

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