any_iterator_interface.hpp 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2010. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file 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_DETAIL_ANY_ITERATOR_INTERFACE_HPP_INCLUDED
  11. #define BOOST_RANGE_DETAIL_ANY_ITERATOR_INTERFACE_HPP_INCLUDED
  12. #include <boost/range/detail/any_iterator_buffer.hpp>
  13. #include <boost/iterator/iterator_categories.hpp>
  14. #include <boost/type_traits/add_const.hpp>
  15. #include <boost/type_traits/add_reference.hpp>
  16. #include <boost/type_traits/is_reference.hpp>
  17. #include <boost/type_traits/remove_const.hpp>
  18. #include <boost/type_traits/remove_reference.hpp>
  19. namespace boost
  20. {
  21. namespace range_detail
  22. {
  23. template<class T>
  24. struct const_reference_type_generator
  25. {
  26. typedef typename mpl::if_<
  27. typename is_reference<T>::type,
  28. typename add_const<
  29. typename remove_reference<T>::type
  30. >::type&,
  31. T
  32. >::type type;
  33. };
  34. template<class T>
  35. struct mutable_reference_type_generator
  36. {
  37. typedef typename mpl::if_<
  38. typename mpl::and_<
  39. typename is_const<T>::type,
  40. typename mpl::not_<typename is_reference<T>::type>::type
  41. >::type,
  42. T,
  43. typename add_reference<T>::type
  44. >::type type;
  45. };
  46. template<
  47. class Reference
  48. , class Buffer
  49. >
  50. struct any_incrementable_iterator_interface
  51. {
  52. typedef typename mutable_reference_type_generator<
  53. Reference
  54. >::type reference;
  55. typedef typename const_reference_type_generator<
  56. Reference
  57. >::type const_reference;
  58. typedef typename remove_const<
  59. typename remove_reference<Reference>::type
  60. >::type reference_as_value_type;
  61. typedef Buffer buffer_type;
  62. virtual ~any_incrementable_iterator_interface() {}
  63. virtual any_incrementable_iterator_interface*
  64. clone(buffer_type& buffer) const = 0;
  65. virtual any_incrementable_iterator_interface<const_reference, Buffer>*
  66. clone_const_ref(buffer_type& buffer) const = 0;
  67. virtual any_incrementable_iterator_interface<reference_as_value_type, Buffer>*
  68. clone_reference_as_value(buffer_type& buffer) const = 0;
  69. virtual void increment() = 0;
  70. };
  71. template<
  72. class Reference
  73. , class Buffer
  74. >
  75. struct any_single_pass_iterator_interface
  76. : any_incrementable_iterator_interface<Reference, Buffer>
  77. {
  78. typedef typename any_incrementable_iterator_interface<Reference, Buffer>::reference reference;
  79. typedef typename any_incrementable_iterator_interface<Reference, Buffer>::const_reference const_reference;
  80. typedef typename any_incrementable_iterator_interface<Reference, Buffer>::buffer_type buffer_type;
  81. typedef typename any_incrementable_iterator_interface<Reference, Buffer>::reference_as_value_type reference_as_value_type;
  82. virtual any_single_pass_iterator_interface*
  83. clone(buffer_type& buffer) const = 0;
  84. virtual any_single_pass_iterator_interface<const_reference, Buffer>*
  85. clone_const_ref(buffer_type& buffer) const = 0;
  86. virtual any_single_pass_iterator_interface<reference_as_value_type, Buffer>*
  87. clone_reference_as_value(buffer_type& buffer) const = 0;
  88. virtual reference dereference() const = 0;
  89. virtual bool equal(const any_single_pass_iterator_interface& other) const = 0;
  90. };
  91. template<
  92. class Reference
  93. , class Buffer
  94. >
  95. struct any_forward_iterator_interface
  96. : any_single_pass_iterator_interface<Reference, Buffer>
  97. {
  98. typedef typename any_single_pass_iterator_interface<Reference, Buffer>::reference reference;
  99. typedef typename any_single_pass_iterator_interface<Reference, Buffer>::const_reference const_reference;
  100. typedef typename any_single_pass_iterator_interface<Reference, Buffer>::buffer_type buffer_type;
  101. typedef typename any_single_pass_iterator_interface<Reference, Buffer>::reference_as_value_type reference_as_value_type;
  102. virtual any_forward_iterator_interface*
  103. clone(buffer_type& buffer) const = 0;
  104. virtual any_forward_iterator_interface<const_reference, Buffer>*
  105. clone_const_ref(buffer_type& buffer) const = 0;
  106. virtual any_forward_iterator_interface<reference_as_value_type, Buffer>*
  107. clone_reference_as_value(buffer_type& buffer) const = 0;
  108. };
  109. template<
  110. class Reference
  111. , class Buffer
  112. >
  113. struct any_bidirectional_iterator_interface
  114. : any_forward_iterator_interface<Reference, Buffer>
  115. {
  116. typedef typename any_forward_iterator_interface<Reference, Buffer>::reference reference;
  117. typedef typename any_forward_iterator_interface<Reference, Buffer>::const_reference const_reference;
  118. typedef typename any_forward_iterator_interface<Reference, Buffer>::buffer_type buffer_type;
  119. typedef typename any_forward_iterator_interface<Reference, Buffer>::reference_as_value_type reference_as_value_type;
  120. virtual any_bidirectional_iterator_interface*
  121. clone(buffer_type& buffer) const = 0;
  122. virtual any_bidirectional_iterator_interface<const_reference, Buffer>*
  123. clone_const_ref(buffer_type& buffer) const = 0;
  124. virtual any_bidirectional_iterator_interface<reference_as_value_type, Buffer>*
  125. clone_reference_as_value(buffer_type& buffer) const = 0;
  126. virtual void decrement() = 0;
  127. };
  128. template<
  129. class Reference
  130. , class Difference
  131. , class Buffer
  132. >
  133. struct any_random_access_iterator_interface
  134. : any_bidirectional_iterator_interface<
  135. Reference
  136. , Buffer
  137. >
  138. {
  139. typedef typename any_bidirectional_iterator_interface<Reference, Buffer>::reference reference;
  140. typedef typename any_bidirectional_iterator_interface<Reference, Buffer>::const_reference const_reference;
  141. typedef typename any_bidirectional_iterator_interface<Reference, Buffer>::buffer_type buffer_type;
  142. typedef typename any_bidirectional_iterator_interface<Reference, Buffer>::reference_as_value_type reference_as_value_type;
  143. typedef Difference difference_type;
  144. virtual any_random_access_iterator_interface*
  145. clone(buffer_type& buffer) const = 0;
  146. virtual any_random_access_iterator_interface<const_reference, Difference, Buffer>*
  147. clone_const_ref(buffer_type& buffer) const = 0;
  148. virtual any_random_access_iterator_interface<reference_as_value_type, Difference, Buffer>*
  149. clone_reference_as_value(buffer_type& buffer) const = 0;
  150. virtual void advance(Difference offset) = 0;
  151. virtual Difference distance_to(const any_random_access_iterator_interface& other) const = 0;
  152. };
  153. template<
  154. class Traversal
  155. , class Reference
  156. , class Difference
  157. , class Buffer
  158. >
  159. struct any_iterator_interface_type_generator;
  160. template<
  161. class Reference
  162. , class Difference
  163. , class Buffer
  164. >
  165. struct any_iterator_interface_type_generator<
  166. incrementable_traversal_tag
  167. , Reference
  168. , Difference
  169. , Buffer
  170. >
  171. {
  172. typedef any_incrementable_iterator_interface<Reference, Buffer> type;
  173. };
  174. template<
  175. class Reference
  176. , class Difference
  177. , class Buffer
  178. >
  179. struct any_iterator_interface_type_generator<
  180. single_pass_traversal_tag
  181. , Reference
  182. , Difference
  183. , Buffer
  184. >
  185. {
  186. typedef any_single_pass_iterator_interface<Reference, Buffer> type;
  187. };
  188. template<
  189. class Reference
  190. , class Difference
  191. , class Buffer
  192. >
  193. struct any_iterator_interface_type_generator<
  194. forward_traversal_tag
  195. , Reference
  196. , Difference
  197. , Buffer
  198. >
  199. {
  200. typedef any_forward_iterator_interface<Reference, Buffer> type;
  201. };
  202. template<
  203. class Reference
  204. , class Difference
  205. , class Buffer
  206. >
  207. struct any_iterator_interface_type_generator<
  208. bidirectional_traversal_tag
  209. , Reference
  210. , Difference
  211. , Buffer
  212. >
  213. {
  214. typedef any_bidirectional_iterator_interface<Reference, Buffer> type;
  215. };
  216. template<
  217. class Reference
  218. , class Difference
  219. , class Buffer
  220. >
  221. struct any_iterator_interface_type_generator<
  222. random_access_traversal_tag
  223. , Reference
  224. , Difference
  225. , Buffer
  226. >
  227. {
  228. typedef any_random_access_iterator_interface<
  229. Reference
  230. , Difference
  231. , Buffer
  232. > type;
  233. };
  234. } // namespace range_detail
  235. } // namespace boost
  236. #endif // include guard