mock_iterator.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2014. Use, modification and distribution is subject
  4. // to the Boost Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see http://www.boost.org/libs/range
  9. //
  10. #ifndef BOOST_RANGE_UNIT_TEST_ADAPTOR_MOCK_ITERATOR_HPP_INCLUDED
  11. #define BOOST_RANGE_UNIT_TEST_ADAPTOR_MOCK_ITERATOR_HPP_INCLUDED
  12. #include <boost/iterator/iterator_facade.hpp>
  13. namespace boost
  14. {
  15. namespace range
  16. {
  17. namespace unit_test
  18. {
  19. template<typename TraversalTag>
  20. class mock_iterator
  21. : public boost::iterator_facade<
  22. mock_iterator<TraversalTag>,
  23. int,
  24. TraversalTag,
  25. const int&
  26. >
  27. {
  28. public:
  29. mock_iterator()
  30. : m_value(0)
  31. {
  32. }
  33. explicit mock_iterator(int value)
  34. : m_value(value)
  35. {
  36. }
  37. private:
  38. void increment()
  39. {
  40. ++m_value;
  41. }
  42. void decrement()
  43. {
  44. --m_value;
  45. }
  46. bool equal(const mock_iterator& other) const
  47. {
  48. return m_value == other.m_value;
  49. }
  50. void advance(std::ptrdiff_t offset)
  51. {
  52. m_value += offset;
  53. }
  54. std::ptrdiff_t distance_to(const mock_iterator& other) const
  55. {
  56. return other.m_value - m_value;
  57. }
  58. const int& dereference() const
  59. {
  60. return m_value;
  61. }
  62. int m_value;
  63. friend class boost::iterator_core_access;
  64. };
  65. } // namespace unit_test
  66. } // namespace range
  67. } // namespace boost
  68. #endif // include guard