find_iterator.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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