geometry_collection_concept.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // Boost.Geometry
  2. // Copyright (c) 2021, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. #ifndef BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_GEOMETRY_COLLECTION_CONCEPT_HPP
  7. #define BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_GEOMETRY_COLLECTION_CONCEPT_HPP
  8. #include <utility>
  9. #include <boost/concept_check.hpp>
  10. #include <boost/range/concepts.hpp>
  11. #include <boost/geometry/core/geometry_types.hpp>
  12. #include <boost/geometry/core/mutable_range.hpp>
  13. #include <boost/geometry/core/tag.hpp>
  14. #include <boost/geometry/core/tags.hpp>
  15. #include <boost/geometry/core/visit.hpp>
  16. #include <boost/geometry/geometries/concepts/box_concept.hpp>
  17. #include <boost/geometry/geometries/concepts/concept_type.hpp>
  18. #include <boost/geometry/geometries/concepts/linestring_concept.hpp>
  19. #include <boost/geometry/geometries/concepts/multi_point_concept.hpp>
  20. #include <boost/geometry/geometries/concepts/multi_linestring_concept.hpp>
  21. #include <boost/geometry/geometries/concepts/multi_polygon_concept.hpp>
  22. #include <boost/geometry/geometries/concepts/point_concept.hpp>
  23. #include <boost/geometry/geometries/concepts/polygon_concept.hpp>
  24. #include <boost/geometry/geometries/concepts/ring_concept.hpp>
  25. #include <boost/geometry/geometries/concepts/segment_concept.hpp>
  26. #include <boost/geometry/util/sequence.hpp>
  27. #include <boost/geometry/util/type_traits.hpp>
  28. namespace boost { namespace geometry { namespace concepts
  29. {
  30. namespace detail
  31. {
  32. template
  33. <
  34. typename Geometry,
  35. typename SubGeometry,
  36. typename Tag = typename tag<Geometry>::type,
  37. bool IsSubDynamicOrCollection = util::is_dynamic_geometry<SubGeometry>::value
  38. || util::is_geometry_collection<SubGeometry>::value
  39. >
  40. struct GeometryType;
  41. // Prevent recursive concept checking
  42. template <typename Geometry, typename SubGeometry, typename Tag>
  43. struct GeometryType<Geometry, SubGeometry, Tag, true> {};
  44. template <typename Geometry, typename SubGeometry, typename Tag>
  45. struct GeometryType<Geometry const, SubGeometry, Tag, true> {};
  46. template <typename Geometry, typename SubGeometry>
  47. struct GeometryType<Geometry, SubGeometry, geometry_collection_tag, false>
  48. : concepts::concept_type<SubGeometry>::type
  49. {
  50. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  51. BOOST_CONCEPT_USAGE(GeometryType)
  52. {
  53. Geometry* gc = nullptr;
  54. SubGeometry* sg = nullptr;
  55. traits::emplace_back<Geometry>::apply(*gc, std::move(*sg));
  56. }
  57. #endif // DOXYGEN_NO_CONCEPT_MEMBERS
  58. };
  59. template <typename Geometry, typename SubGeometry>
  60. struct GeometryType<Geometry const, SubGeometry, geometry_collection_tag, false>
  61. : concepts::concept_type<SubGeometry const>::type
  62. {};
  63. template <typename Geometry, typename ...SubGeometries>
  64. struct GeometryTypesPack {};
  65. template <typename Geometry, typename SubGeometry, typename ...SubGeometries>
  66. struct GeometryTypesPack<Geometry, SubGeometry, SubGeometries...>
  67. : GeometryTypesPack<Geometry, SubGeometries...>
  68. , GeometryType<Geometry, SubGeometry>
  69. {};
  70. template <typename Geometry, typename SubGeometriesSequence>
  71. struct GeometryTypes;
  72. template <typename Geometry, typename ...SubGeometries>
  73. struct GeometryTypes<Geometry, util::type_sequence<SubGeometries...>>
  74. : GeometryTypesPack<Geometry, SubGeometries...>
  75. {};
  76. } // namespace detail
  77. template <typename Geometry>
  78. struct GeometryCollection
  79. : boost::ForwardRangeConcept<Geometry>
  80. {
  81. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  82. using sequence_t = typename traits::geometry_types<Geometry>::type;
  83. BOOST_CONCEPT_ASSERT( (detail::GeometryTypes<Geometry, sequence_t>) );
  84. BOOST_CONCEPT_USAGE(GeometryCollection)
  85. {
  86. Geometry* gc = nullptr;
  87. traits::clear<Geometry>::apply(*gc);
  88. traits::iter_visit<Geometry>::apply([](auto &&) {}, boost::begin(*gc));
  89. }
  90. #endif // DOXYGEN_NO_CONCEPT_MEMBERS
  91. };
  92. template <typename Geometry>
  93. struct ConstGeometryCollection
  94. : boost::ForwardRangeConcept<Geometry>
  95. {
  96. #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
  97. using sequence_t = typename traits::geometry_types<Geometry>::type;
  98. BOOST_CONCEPT_ASSERT( (detail::GeometryTypes<Geometry const, sequence_t>) );
  99. BOOST_CONCEPT_USAGE(ConstGeometryCollection)
  100. {
  101. Geometry const* gc = nullptr;
  102. traits::iter_visit<Geometry>::apply([](auto &&) {}, boost::begin(*gc));
  103. }
  104. #endif // DOXYGEN_NO_CONCEPT_MEMBERS
  105. };
  106. template <typename Geometry>
  107. struct concept_type<Geometry, geometry_collection_tag>
  108. {
  109. using type = GeometryCollection<Geometry>;
  110. };
  111. template <typename Geometry>
  112. struct concept_type<Geometry const, geometry_collection_tag>
  113. {
  114. using type = ConstGeometryCollection<Geometry>;
  115. };
  116. }}} // namespace boost::geometry::concepts
  117. #endif // BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_GEOMETRY_COLLECTION_CONCEPT_HPP