1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2020 Barend Gehrels, Amsterdam, the Netherlands.
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)
10 #ifndef GEOMETRY_TEST_COUNT_SET_HPP
11 #define GEOMETRY_TEST_COUNT_SET_HPP
16 // Structure to manage expectations: sometimes the output might have one or
17 // two rings, both are fine.
28 m_values.insert(static_cast<std::size_t>(value));
32 count_set(std::size_t value1, std::size_t value2)
34 m_values.insert(value1);
35 m_values.insert(value2);
38 count_set(std::size_t value1, std::size_t value2, std::size_t value3)
40 m_values.insert(value1);
41 m_values.insert(value2);
42 m_values.insert(value3);
45 bool empty() const { return m_values.empty(); }
47 bool has(std::size_t value) const
49 return m_values.count(value) > 0;
52 friend std::ostream &operator<<(std::ostream &os, const count_set& s)
55 for (std::size_t const& value : s.m_values)
63 count_set operator+(const count_set& a) const
66 result.m_values = combine(this->m_values, a.m_values);
71 typedef std::set<std::size_t> set_type;
74 set_type combine(const set_type& a, const set_type& b) const
77 if (a.size() == 1 && b.size() == 1)
79 // The common scenario, both have one value
80 result.insert(*a.begin() + *b.begin());
82 else if (a.size() > 1 && b.size() == 1)
84 // One of them is optional, add the second
85 for (std::size_t const& value : a)
87 result.insert(value + *b.begin());
90 else if (b.size() > 1 && a.size() == 1)
94 // Else either is empty, or both have values and should be specified
99 inline count_set ignore_count()
104 inline count_set optional()
106 return count_set(0, 1);
109 #endif // GEOMETRY_TEST_COUNT_SET_HPP