num_geometries.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
  5. // This file was modified by Oracle on 2014.
  6. // Modifications copyright (c) 2014, Oracle and/or its affiliates.
  7. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  10. // Use, modification and distribution is subject to the Boost Software License,
  11. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_ALGORITHMS_NUM_GEOMETRIES_HPP
  14. #define BOOST_GEOMETRY_ALGORITHMS_NUM_GEOMETRIES_HPP
  15. #include <cstddef>
  16. #include <boost/range.hpp>
  17. #include <boost/variant/apply_visitor.hpp>
  18. #include <boost/variant/static_visitor.hpp>
  19. #include <boost/variant/variant_fwd.hpp>
  20. #include <boost/geometry/algorithms/not_implemented.hpp>
  21. #include <boost/geometry/core/tag.hpp>
  22. #include <boost/geometry/core/tags.hpp>
  23. #include <boost/geometry/core/tag_cast.hpp>
  24. #include <boost/geometry/geometries/concepts/check.hpp>
  25. #include <boost/geometry/algorithms/detail/counting.hpp>
  26. namespace boost { namespace geometry
  27. {
  28. #ifndef DOXYGEN_NO_DISPATCH
  29. namespace dispatch
  30. {
  31. template
  32. <
  33. typename Geometry,
  34. typename Tag = typename tag_cast
  35. <
  36. typename tag<Geometry>::type,
  37. single_tag,
  38. multi_tag
  39. >::type
  40. >
  41. struct num_geometries: not_implemented<Tag>
  42. {};
  43. template <typename Geometry>
  44. struct num_geometries<Geometry, single_tag>
  45. : detail::counting::other_count<1>
  46. {};
  47. template <typename MultiGeometry>
  48. struct num_geometries<MultiGeometry, multi_tag>
  49. {
  50. static inline std::size_t apply(MultiGeometry const& multi_geometry)
  51. {
  52. return boost::size(multi_geometry);
  53. }
  54. };
  55. } // namespace dispatch
  56. #endif // DOXYGEN_NO_DISPATCH
  57. namespace resolve_variant
  58. {
  59. template <typename Geometry>
  60. struct num_geometries
  61. {
  62. static inline std::size_t apply(Geometry const& geometry)
  63. {
  64. concepts::check<Geometry const>();
  65. return dispatch::num_geometries<Geometry>::apply(geometry);
  66. }
  67. };
  68. template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
  69. struct num_geometries<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
  70. {
  71. struct visitor: boost::static_visitor<std::size_t>
  72. {
  73. template <typename Geometry>
  74. inline std::size_t operator()(Geometry const& geometry) const
  75. {
  76. return num_geometries<Geometry>::apply(geometry);
  77. }
  78. };
  79. static inline std::size_t
  80. apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry)
  81. {
  82. return boost::apply_visitor(visitor(), geometry);
  83. }
  84. };
  85. } // namespace resolve_variant
  86. /*!
  87. \brief \brief_calc{number of geometries}
  88. \ingroup num_geometries
  89. \details \details_calc{num_geometries, number of geometries}.
  90. \tparam Geometry \tparam_geometry
  91. \param geometry \param_geometry
  92. \return \return_calc{number of geometries}
  93. \qbk{[include reference/algorithms/num_geometries.qbk]}
  94. */
  95. template <typename Geometry>
  96. inline std::size_t num_geometries(Geometry const& geometry)
  97. {
  98. return resolve_variant::num_geometries<Geometry>::apply(geometry);
  99. }
  100. }} // namespace boost::geometry
  101. #endif // BOOST_GEOMETRY_ALGORITHMS_NUM_GEOMETRIES_HPP