find_iterator.hpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Boost string_algo library find_iterator.hpp header file ---------------------------//
  2. // Copyright Pavol Droba 2002-2003.
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. // See http://www.boost.org/ for updates, documentation, and revision history.
  8. #ifndef BOOST_STRING_FIND_ITERATOR_DETAIL_HPP
  9. #define BOOST_STRING_FIND_ITERATOR_DETAIL_HPP
  10. #include <boost/algorithm/string/config.hpp>
  11. #include <boost/range/iterator_range_core.hpp>
  12. #include <boost/iterator/iterator_facade.hpp>
  13. #include <boost/iterator/iterator_categories.hpp>
  14. #include <boost/function.hpp>
  15. namespace boost {
  16. namespace algorithm {
  17. namespace detail {
  18. // find_iterator base -----------------------------------------------//
  19. // Find iterator base
  20. template<typename IteratorT>
  21. class find_iterator_base
  22. {
  23. protected:
  24. // typedefs
  25. typedef IteratorT input_iterator_type;
  26. typedef iterator_range<IteratorT> match_type;
  27. typedef function2<
  28. match_type,
  29. input_iterator_type,
  30. input_iterator_type> finder_type;
  31. protected:
  32. // Protected construction/destruction
  33. // Default constructor
  34. find_iterator_base() {}
  35. // Copy construction
  36. find_iterator_base( const find_iterator_base& Other ) :
  37. m_Finder(Other.m_Finder) {}
  38. // Constructor
  39. template<typename FinderT>
  40. find_iterator_base( FinderT Finder, int ) :
  41. m_Finder(Finder) {}
  42. // Destructor
  43. ~find_iterator_base() {}
  44. // Find operation
  45. match_type do_find(
  46. input_iterator_type Begin,
  47. input_iterator_type End ) const
  48. {
  49. if (!m_Finder.empty())
  50. {
  51. return m_Finder(Begin,End);
  52. }
  53. else
  54. {
  55. return match_type(End,End);
  56. }
  57. }
  58. // Check
  59. bool is_null() const
  60. {
  61. return m_Finder.empty();
  62. }
  63. private:
  64. // Finder
  65. finder_type m_Finder;
  66. };
  67. } // namespace detail
  68. } // namespace algorithm
  69. } // namespace boost
  70. #endif // BOOST_STRING_FIND_ITERATOR_DETAIL_HPP