all_custom_container.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef GEOMETRY_TEST_TEST_GEOMETRIES_ALL_CUSTOM_CONTAINER_HPP
  8. #define GEOMETRY_TEST_TEST_GEOMETRIES_ALL_CUSTOM_CONTAINER_HPP
  9. #include <cstddef>
  10. #include <deque>
  11. template <typename Item>
  12. class all_custom_container
  13. {
  14. private :
  15. std::deque<Item> m_hidden_deque;
  16. public :
  17. typedef typename std::deque<Item>::iterator custom_iterator_type;
  18. typedef typename std::deque<Item>::const_iterator custom_const_iterator_type;
  19. inline std::size_t custom_size() const { return m_hidden_deque.size(); }
  20. inline custom_const_iterator_type custom_begin() const { return m_hidden_deque.begin(); }
  21. inline custom_const_iterator_type custom_end() const { return m_hidden_deque.end(); }
  22. inline custom_iterator_type custom_begin() { return m_hidden_deque.begin(); }
  23. inline custom_iterator_type custom_end() { return m_hidden_deque.end(); }
  24. inline void custom_clear() { m_hidden_deque.clear(); }
  25. inline void custom_push_back(Item const& p) { m_hidden_deque.push_back(p); }
  26. inline void custom_resize(std::size_t new_size) { m_hidden_deque.resize(new_size); }
  27. };
  28. // 1. Adapt to Boost.Geometry (for e.g. inner rings)
  29. namespace boost { namespace geometry
  30. {
  31. namespace traits
  32. {
  33. template <typename Item>
  34. struct clear<all_custom_container<Item> >
  35. {
  36. static inline void apply(all_custom_container<Item>& container)
  37. {
  38. container.custom_clear();
  39. }
  40. };
  41. template <typename Item>
  42. struct push_back<all_custom_container<Item> >
  43. {
  44. static inline void apply(all_custom_container<Item>& container, Item const& item)
  45. {
  46. container.custom_push_back(item);
  47. }
  48. };
  49. template <typename Item>
  50. struct resize<all_custom_container<Item> >
  51. {
  52. static inline void apply(all_custom_container<Item>& container, std::size_t new_size)
  53. {
  54. container.custom_resize(new_size);
  55. }
  56. };
  57. } // namespace traits
  58. }} // namespace boost::geometry
  59. // 2a. Adapt to Boost.Range, meta-functions
  60. namespace boost
  61. {
  62. template<typename Item>
  63. struct range_mutable_iterator<all_custom_container<Item> >
  64. {
  65. typedef typename all_custom_container<Item>::custom_iterator_type type;
  66. };
  67. template<typename Item>
  68. struct range_const_iterator<all_custom_container<Item> >
  69. {
  70. typedef typename all_custom_container<Item>::custom_const_iterator_type type;
  71. };
  72. } // namespace boost
  73. // 2b. Adapt to Boost.Range, part 2, ADP
  74. template<typename Item>
  75. inline typename all_custom_container<Item>::custom_iterator_type
  76. range_begin(all_custom_container<Item>& container)
  77. {
  78. return container.custom_begin();
  79. }
  80. template<typename Item>
  81. inline typename all_custom_container<Item>::custom_const_iterator_type
  82. range_begin(all_custom_container<Item> const& container)
  83. {
  84. return container.custom_begin();
  85. }
  86. template<typename Item>
  87. inline typename all_custom_container<Item>::custom_iterator_type
  88. range_end(all_custom_container<Item>& container)
  89. {
  90. return container.custom_end();
  91. }
  92. template<typename Item>
  93. inline typename all_custom_container<Item>::custom_const_iterator_type
  94. range_end(all_custom_container<Item> const& container)
  95. {
  96. return container.custom_end();
  97. }
  98. // (Optional)
  99. template<typename Item>
  100. inline std::size_t range_calculate_size(all_custom_container<Item> const& container)
  101. {
  102. return container.custom_size();
  103. }
  104. #endif // GEOMETRY_TEST_TEST_GEOMETRIES_ALL_CUSTOM_CONTAINER_HPP