num_geometries.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 = tag_cast_t<tag_t<Geometry>, single_tag, multi_tag>
  36. >
  37. struct num_geometries: not_implemented<Tag>
  38. {};
  39. template <typename Geometry>
  40. struct num_geometries<Geometry, single_tag>
  41. : detail::counting::other_count<1>
  42. {};
  43. template <typename MultiGeometry>
  44. struct num_geometries<MultiGeometry, multi_tag>
  45. {
  46. static inline std::size_t apply(MultiGeometry const& multi_geometry)
  47. {
  48. return boost::size(multi_geometry);
  49. }
  50. };
  51. } // namespace dispatch
  52. #endif // DOXYGEN_NO_DISPATCH
  53. namespace resolve_variant
  54. {
  55. template <typename Geometry>
  56. struct num_geometries
  57. {
  58. static inline std::size_t apply(Geometry const& geometry)
  59. {
  60. concepts::check<Geometry const>();
  61. return dispatch::num_geometries<Geometry>::apply(geometry);
  62. }
  63. };
  64. template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
  65. struct num_geometries<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
  66. {
  67. struct visitor: boost::static_visitor<std::size_t>
  68. {
  69. template <typename Geometry>
  70. inline std::size_t operator()(Geometry const& geometry) const
  71. {
  72. return num_geometries<Geometry>::apply(geometry);
  73. }
  74. };
  75. static inline std::size_t
  76. apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry)
  77. {
  78. return boost::apply_visitor(visitor(), geometry);
  79. }
  80. };
  81. } // namespace resolve_variant
  82. /*!
  83. \brief \brief_calc{number of geometries}
  84. \ingroup num_geometries
  85. \details \details_calc{num_geometries, number of geometries}.
  86. \tparam Geometry \tparam_geometry
  87. \param geometry \param_geometry
  88. \return \return_calc{number of geometries}
  89. \qbk{[include reference/algorithms/num_geometries.qbk]}
  90. */
  91. template <typename Geometry>
  92. inline std::size_t num_geometries(Geometry const& geometry)
  93. {
  94. return resolve_variant::num_geometries<Geometry>::apply(geometry);
  95. }
  96. }} // namespace boost::geometry
  97. #endif // BOOST_GEOMETRY_ALGORITHMS_NUM_GEOMETRIES_HPP