]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/count_set.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / geometry / test / count_set.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2020 Barend Gehrels, Amsterdam, the Netherlands.
4
5 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8
9
10 #ifndef GEOMETRY_TEST_COUNT_SET_HPP
11 #define GEOMETRY_TEST_COUNT_SET_HPP
12
13 #include <set>
14 #include <ostream>
15
16 // Structure to manage expectations: sometimes the output might have one or
17 // two rings, both are fine.
18 struct count_set
19 {
20 count_set()
21 {
22 }
23
24 count_set(int value)
25 {
26 if (value >= 0)
27 {
28 m_values.insert(static_cast<std::size_t>(value));
29 }
30 }
31
32 count_set(std::size_t value1, std::size_t value2)
33 {
34 m_values.insert(value1);
35 m_values.insert(value2);
36 }
37
38 count_set(std::size_t value1, std::size_t value2, std::size_t value3)
39 {
40 m_values.insert(value1);
41 m_values.insert(value2);
42 m_values.insert(value3);
43 }
44
45 bool empty() const { return m_values.empty(); }
46
47 bool has(std::size_t value) const
48 {
49 return m_values.count(value) > 0;
50 }
51
52 friend std::ostream &operator<<(std::ostream &os, const count_set& s)
53 {
54 os << "{";
55 for (std::size_t const& value : s.m_values)
56 {
57 os << " " << value;
58 }
59 os << "}";
60 return os;
61 }
62
63 count_set operator+(const count_set& a) const
64 {
65 count_set result;
66 result.m_values = combine(this->m_values, a.m_values);
67 return result;
68 }
69
70 private :
71 typedef std::set<std::size_t> set_type;
72 set_type m_values;
73
74 set_type combine(const set_type& a, const set_type& b) const
75 {
76 set_type result;
77 if (a.size() == 1 && b.size() == 1)
78 {
79 // The common scenario, both have one value
80 result.insert(*a.begin() + *b.begin());
81 }
82 else if (a.size() > 1 && b.size() == 1)
83 {
84 // One of them is optional, add the second
85 for (std::size_t const& value : a)
86 {
87 result.insert(value + *b.begin());
88 }
89 }
90 else if (b.size() > 1 && a.size() == 1)
91 {
92 return combine(b, a);
93 }
94 // Else either is empty, or both have values and should be specified
95 return result;
96 }
97 };
98
99 inline count_set ignore_count()
100 {
101 return count_set();
102 }
103
104 inline count_set optional()
105 {
106 return count_set(0, 1);
107 }
108
109 #endif // GEOMETRY_TEST_COUNT_SET_HPP