Quetzal-CoaTL
The Coalescence Template Library
Loading...
Searching...
No Matches
concepts.hpp
1// Copyright 2021 Arnaud Becheler <abechele@umich.edu>
2
10
11#pragma once
12
13#include "directionality.hpp"
14
15#include <boost/graph/adjacency_list.hpp>
16#include <boost/graph/adjacency_matrix.hpp>
17
18#include <concepts>
19#include <ranges>
20
21namespace quetzal::geography
22{
23
24namespace detail
25{
26template <typename T, typename... U>
27concept is_any_of = (std::same_as<T, U> || ...);
28
29template<typename T>
31{
32 template<typename Graph, typename Grid>
33 requires
34 std::same_as<T, typename Graph::edge_property> and
35 std::default_initializable<T> and
36 ( ! std::constructible_from<T, typename Graph::vertex_descriptor, typename Graph::vertex_descriptor, Grid> )
37 static inline constexpr void delegate(Graph::vertex_descriptor s, Graph::vertex_descriptor t, Graph& graph, Grid const& grid)
38 {
39 graph.add_edge(s, t, T{});
40 }
41
42 template<typename Graph, typename Grid>
43 requires std::same_as<T, typename Graph::edge_property> and
44 std::constructible_from<T, typename Graph::vertex_descriptor, typename Graph::vertex_descriptor, Grid>
45 static inline constexpr void delegate(Graph::vertex_descriptor s, Graph::vertex_descriptor t, Graph& graph, Grid const& grid)
46 {
47 graph.add_edge(s, t, T(s,t, grid));
48 }
49
50};
51
52template<>
54{
55 static inline constexpr void delegate(auto s, auto t, auto& graph, [[maybe_unused]] auto const& grid)
56 {
57 graph.add_edge(s, t);
58 }
59};
60
61}
62
64template <typename T>
66
67static_assert ( directional<isotropy> );
68static_assert ( directional<anisotropy> );
69
71using no_property = boost::no_property;
72
74struct sparse
75{
76 template<directional Directed, class VertexProperty, class EdgeProperty>
77 using rebind = boost::adjacency_list<boost::setS, boost::vecS, Directed, VertexProperty, EdgeProperty>;
78};
79
81struct dense
82{
83 template<class Directed, class VertexProperty, class EdgeProperty>
84 using rebind = boost::adjacency_matrix<Directed, VertexProperty, EdgeProperty, no_property, std::allocator<bool>>;
85};
86
88template<typename T>
90
91static_assert ( connectedness<dense> );
92static_assert ( connectedness<sparse> );
93
95template <typename T>
96concept two_dimensional = requires(T a) {
97 requires std::convertible_to<decltype(a.width()), int>;
98 requires std::convertible_to<decltype(a.height()), int>;
99 };
100
102template <typename T, class G, class S>
103concept bounding = two_dimensional<S> and requires(T t, typename G::vertex_descriptor s, G &graph, S const &grid) {
104 {
105 t(s, graph, grid)
106 } -> std::same_as<void>;
107 };
108} // namespace quetzal::geography
Definition graph.hpp:262
Concept to represent the bounding policy of a spatial graph.
Definition concepts.hpp:103
Concept to represent the connectedness of a graph.
Definition concepts.hpp:89
Definition concepts.hpp:27
Concept to represent the directionality of edges in a graph.
Definition concepts.hpp:65
Concept to represent a 2D spatial grid.
Definition concepts.hpp:96
Definition cardinal_k_ary_tree.hpp:46
Geospatial data formatting and processing.
Definition geography.hpp:17
boost::no_property no_property
Represents no information carried by vertices or edges of a graph.
Definition concepts.hpp:71
Tag for sparse graph representation.
Definition concepts.hpp:82
Tag for sparse graph representation.
Definition concepts.hpp:75