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