find_iterator.hpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. BOOST_DEFAULTED_FUNCTION(find_iterator_base(), {})
  35. // Copy construction
  36. BOOST_DEFAULTED_FUNCTION(find_iterator_base( const find_iterator_base& Other ), :
  37. m_Finder(Other.m_Finder) {}
  38. )
  39. // Assignment
  40. BOOST_DEFAULTED_FUNCTION(find_iterator_base& operator=( const find_iterator_base& Other ), {
  41. m_Finder = Other.m_Finder;
  42. return *this;
  43. })
  44. // Constructor
  45. template<typename FinderT>
  46. find_iterator_base( FinderT Finder, int ) :
  47. m_Finder(Finder) {}
  48. // Destructor
  49. BOOST_DEFAULTED_FUNCTION(~find_iterator_base(), {})
  50. // Find operation
  51. match_type do_find(
  52. input_iterator_type Begin,
  53. input_iterator_type End ) const
  54. {
  55. if (!m_Finder.empty())
  56. {
  57. return m_Finder(Begin,End);
  58. }
  59. else
  60. {
  61. return match_type(End,End);
  62. }
  63. }
  64. // Check
  65. bool is_null() const
  66. {
  67. return m_Finder.empty();
  68. }
  69. private:
  70. // Finder
  71. finder_type m_Finder;
  72. };
  73. } // namespace detail
  74. } // namespace algorithm
  75. } // namespace boost
  76. #endif // BOOST_STRING_FIND_ITERATOR_DETAIL_HPP