node_elements.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Boost.Geometry Index
  2. //
  3. // R-tree node elements access
  4. //
  5. // Copyright (c) 2011-2015 Adam Wulkiewicz, Lodz, Poland.
  6. //
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_ELEMENTS_HPP
  11. #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_ELEMENTS_HPP
  12. #include <boost/container/vector.hpp>
  13. #include <boost/geometry/algorithms/detail/expand_by_epsilon.hpp>
  14. #include <boost/geometry/index/detail/varray.hpp>
  15. #include <boost/geometry/index/detail/rtree/node/pairs.hpp>
  16. namespace boost { namespace geometry { namespace index {
  17. namespace detail { namespace rtree {
  18. // element's indexable type
  19. template <typename Element, typename Translator>
  20. struct element_indexable_type
  21. {
  22. typedef typename indexable_type<Translator>::type type;
  23. };
  24. template <typename First, typename Pointer, typename Translator>
  25. struct element_indexable_type<
  26. rtree::ptr_pair<First, Pointer>,
  27. Translator
  28. >
  29. {
  30. typedef First type;
  31. };
  32. // is leaf element
  33. template <typename Element>
  34. struct is_leaf_element
  35. {
  36. static const bool value = true;
  37. };
  38. template <typename First, typename Pointer>
  39. struct is_leaf_element< rtree::ptr_pair<First, Pointer> >
  40. {
  41. static const bool value = false;
  42. };
  43. // element's indexable getter
  44. template <typename Element, typename Translator>
  45. typename result_type<Translator>::type
  46. element_indexable(Element const& el, Translator const& tr)
  47. {
  48. return tr(el);
  49. }
  50. template <typename First, typename Pointer, typename Translator>
  51. First const&
  52. element_indexable(rtree::ptr_pair<First, Pointer> const& el, Translator const& /*tr*/)
  53. {
  54. return el.first;
  55. }
  56. // nodes elements
  57. template <typename Node>
  58. struct elements_type
  59. {
  60. typedef typename Node::elements_type type;
  61. };
  62. template <typename Node>
  63. inline typename elements_type<Node>::type &
  64. elements(Node & n)
  65. {
  66. return n.elements;
  67. }
  68. template <typename Node>
  69. inline typename elements_type<Node>::type const&
  70. elements(Node const& n)
  71. {
  72. return n.elements;
  73. }
  74. // elements derived type
  75. template <typename Elements, typename NewValue>
  76. struct container_from_elements_type
  77. {
  78. typedef boost::container::vector<NewValue> type;
  79. };
  80. template <typename OldValue, size_t N, typename NewValue>
  81. struct container_from_elements_type<detail::varray<OldValue, N>, NewValue>
  82. {
  83. typedef detail::varray<NewValue, N> type;
  84. };
  85. }} // namespace detail::rtree
  86. }}} // namespace boost::geometry::index
  87. #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_NODE_ELEMENTS_HPP