point_type.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  6. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  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_CORE_POINT_TYPE_HPP
  11. #define BOOST_GEOMETRY_CORE_POINT_TYPE_HPP
  12. #include <boost/mpl/assert.hpp>
  13. #include <boost/range/value_type.hpp>
  14. #include <boost/type_traits/remove_const.hpp>
  15. #include <boost/geometry/core/ring_type.hpp>
  16. #include <boost/geometry/core/tag.hpp>
  17. #include <boost/geometry/core/tags.hpp>
  18. #include <boost/geometry/util/bare_type.hpp>
  19. namespace boost { namespace geometry
  20. {
  21. namespace traits
  22. {
  23. /*!
  24. \brief Traits class indicating the type of contained points
  25. \ingroup traits
  26. \par Geometries:
  27. - all geometries except point
  28. \par Specializations should provide:
  29. - typedef P type (where P should fulfil the Point concept)
  30. \tparam Geometry geometry
  31. */
  32. template <typename Geometry>
  33. struct point_type
  34. {
  35. BOOST_MPL_ASSERT_MSG
  36. (
  37. false, NOT_IMPLEMENTED_FOR_THIS_POINT_TYPE, (types<Geometry>)
  38. );
  39. };
  40. } // namespace traits
  41. #ifndef DOXYGEN_NO_DISPATCH
  42. namespace core_dispatch
  43. {
  44. template <typename Tag, typename Geometry>
  45. struct point_type
  46. {
  47. // Default: call traits to get point type
  48. typedef typename boost::remove_const
  49. <
  50. typename traits::point_type<Geometry>::type
  51. >::type type;
  52. };
  53. // Specialization for point: the point itself
  54. template <typename Point>
  55. struct point_type<point_tag, Point>
  56. {
  57. typedef Point type;
  58. };
  59. // Specializations for linestring/ring, via boost::range
  60. template <typename Linestring>
  61. struct point_type<linestring_tag, Linestring>
  62. {
  63. typedef typename boost::range_value<Linestring>::type type;
  64. };
  65. template <typename Ring>
  66. struct point_type<ring_tag, Ring>
  67. {
  68. typedef typename boost::range_value<Ring>::type type;
  69. };
  70. // Specialization for polygon: the point-type is the point-type of its rings
  71. template <typename Polygon>
  72. struct point_type<polygon_tag, Polygon>
  73. {
  74. typedef typename point_type
  75. <
  76. ring_tag,
  77. typename ring_type<polygon_tag, Polygon>::type
  78. >::type type;
  79. };
  80. template <typename MultiPoint>
  81. struct point_type<multi_point_tag, MultiPoint>
  82. {
  83. typedef typename boost::range_value
  84. <
  85. MultiPoint
  86. >::type type;
  87. };
  88. template <typename MultiLinestring>
  89. struct point_type<multi_linestring_tag, MultiLinestring>
  90. {
  91. typedef typename point_type
  92. <
  93. linestring_tag,
  94. typename boost::range_value<MultiLinestring>::type
  95. >::type type;
  96. };
  97. template <typename MultiPolygon>
  98. struct point_type<multi_polygon_tag, MultiPolygon>
  99. {
  100. typedef typename point_type
  101. <
  102. polygon_tag,
  103. typename boost::range_value<MultiPolygon>::type
  104. >::type type;
  105. };
  106. } // namespace core_dispatch
  107. #endif // DOXYGEN_NO_DISPATCH
  108. /*!
  109. \brief \brief_meta{type, point_type, \meta_geometry_type}
  110. \tparam Geometry \tparam_geometry
  111. \ingroup core
  112. \qbk{[include reference/core/point_type.qbk]}
  113. */
  114. template <typename Geometry>
  115. struct point_type
  116. {
  117. typedef typename core_dispatch::point_type
  118. <
  119. typename tag<Geometry>::type,
  120. typename boost::geometry::util::bare_type<Geometry>::type
  121. >::type type;
  122. };
  123. }} // namespace boost::geometry
  124. #endif // BOOST_GEOMETRY_CORE_POINT_TYPE_HPP