cgv
Loading...
Searching...
No Matches
interval_map.h
1#pragma once
2
3#include <map>
4
5namespace cgv {
6namespace data {
7
11template<class Key, class T>
13public:
14 using base_type = std::map<Key, T>;
15 using key_type = Key;
16 using mapped_type = T;
17 using value_type = typename base_type::value_type;
18 using size_type = typename base_type::size_type;
19 using iterator = typename base_type::iterator;
20 using const_iterator = typename base_type::const_iterator;
21 using reverse_iterator = typename base_type::reverse_iterator;
22 using const_reverse_iterator = typename base_type::const_reverse_iterator;
23
24private:
25 base_type base;
26
27 const_iterator lower_bound_impl(key_type key) const {
28
29 const_iterator it = base.lower_bound(key);
30
31 if(it == base.end())
32 return base.empty() ? base.end() : std::prev(it);
33 else if(it->first == key)
34 return it;
35 else if(it == base.begin())
36 return base.end();
37 else
38 return std::prev(it);
39 }
40
41public:
42 void clear() { base.clear(); }
43
44 iterator begin() { return base.begin(); }
45
46 const_iterator begin() const { return base.begin(); }
47
48 iterator end() { return base.end(); }
49
50 const_iterator end() const { return base.end(); }
51
52 reverse_iterator rbegin() { return base.rbegin(); }
53
54 const_reverse_iterator rbegin() const { return base.rbegin(); }
55
56 reverse_iterator rend() { return base.rend(); }
57
58 const_reverse_iterator rend() const { return base.rend(); }
59
60 const_iterator cbegin() const { return base.cbegin(); }
61
62 const_iterator cend() const { return base.cend(); }
63
64 const_reverse_iterator crbegin() const { return base.crbegin(); }
65
66 const_reverse_iterator crend() const { return base.crend(); }
67
68 size_type size() const {
69
70 return base.size();
71 }
72
73 bool empty() const {
74
75 return base.empty();
76 }
77
78 std::pair<iterator, bool> insert(key_type key, const mapped_type& value) {
79
80 return base.insert({ key, value });
81 }
82
83 size_type erase(key_type frame) {
84
85 return base.erase(frame);
86 }
87
88 iterator erase(iterator it) {
89
90 return base.erase(it);
91 }
92
93 iterator find(key_type key) {
94
95 return base.find(key);
96 }
97
99 iterator lower_bound(key_type key) {
100
101 const_iterator it = lower_bound_impl(key);
102 return it == base.end() ? base.end() : base.find(it->first);
103 }
104
106 const_iterator lower_bound(key_type key) const {
107
108 return lower_bound_impl(key);
109 }
110
112 iterator upper_bound(key_type key) {
113
114 return base.upper_bound(key);
115 }
116
118 const_iterator upper_bound(key_type key) const {
119
120 return base.upper_bound(key);
121 }
122
126 std::pair<iterator, iterator> bounds(key_type key) {
127
128 return { lower_bound(key), upper_bound(key) };
129 }
130
134 std::pair<const_iterator, const_iterator> bounds(key_type key) const {
135
136 return { lower_bound(key), upper_bound(key) };
137 }
138};
139
140} // namespace data
141} // namespace cgv
virtual bool end()
perform the leave part of the action on the current object
Definition action.cxx:48
bool begin()
uses call_method of base class method_action to call the method refered to by the stored method point...
Definition action.h:122
Extension of a standard map container that allows easy retreival of lower and upper bounds given a ke...
iterator lower_bound(key_type key)
Returns an iterator pointing to the first element in the container whose key is equivalent or smaller...
const_iterator upper_bound(key_type key) const
Returns a const iterator pointing to the first element in the container whose key is greater than the...
const_iterator lower_bound(key_type key) const
Returns a const iterator pointing to the first element in the container whose key is equivalent or sm...
std::pair< const_iterator, const_iterator > bounds(key_type key) const
Returns a pair of const iterators pointing to the lower and upper bounds of the given key.
iterator upper_bound(key_type key)
Returns an iterator pointing to the first element in the container whose key is greater than the give...
std::pair< iterator, iterator > bounds(key_type key)
Returns a pair of iterators pointing to the lower and upper bounds of the given key.
the cgv namespace
Definition print.h:11