Medical Imaging Interaction Toolkit  2021.02.99-121d8b57
Medical Imaging Interaction Toolkit
usShrinkableMap.h
Go to the documentation of this file.
1 /*============================================================================
2 
3  Library: CppMicroServices
4 
5  Copyright (c) German Cancer Research Center (DKFZ)
6  All rights reserved.
7 
8  Licensed under the Apache License, Version 2.0 (the "License");
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0
13 
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 
20 ============================================================================*/
21 
22 #ifndef USSHRINKABLEMAP_H
23 #define USSHRINKABLEMAP_H
24 
25 #include "usGlobalConfig.h"
26 
27 #include <map>
28 
30 
37 template<class Key, class T>
39 {
40 private:
41  static std::map<Key,T> emptyContainer;
42 
43 public:
44 
45  typedef std::map<Key,T> container_type;
46  typedef typename container_type::iterator iterator;
47  typedef typename container_type::const_iterator const_iterator;
48  typedef typename container_type::size_type size_type;
49  typedef typename container_type::key_type key_type;
50  typedef typename container_type::mapped_type mapped_type;
51  typedef typename container_type::value_type value_type;
52  typedef typename container_type::reference reference;
53  typedef typename container_type::const_reference const_reference;
54 
56  : container(emptyContainer)
57  {
58  }
59 
60  iterator begin()
61  {
62  return container.begin();
63  }
64 
65  const_iterator begin() const
66  {
67  return container.begin();
68  }
69 
70  iterator end()
71  {
72  return container.end();
73  }
74 
75  const_iterator end() const
76  {
77  return container.end();
78  }
79 
80  void erase(iterator pos)
81  {
82  return container.erase(pos);
83  }
84 
85  void erase(iterator first, iterator last)
86  {
87  return container.erase(first, last);
88  }
89 
90  size_type erase(const Key& key)
91  {
92  return container.erase(key);
93  }
94 
95  bool empty() const
96  {
97  return container.empty();
98  }
99 
100  void clear()
101  {
102  container.clear();
103  }
104 
105  size_type size() const
106  {
107  return container.size();
108  }
109 
110  size_type max_size() const
111  {
112  return container.max_size();
113  }
114 
115  T& operator[](const Key& key)
116  {
117  return container[key];
118  }
119 
120  size_type count(const Key& key) const
121  {
122  return container.count(key);
123  }
124 
125  iterator find(const Key& key)
126  {
127  return container.find(key);
128  }
129 
130  const_iterator find(const Key& key) const
131  {
132  return container.find(key);
133  }
134 
135  std::pair<iterator,iterator> equal_range(const Key& key)
136  {
137  return container.equal_range(key);
138  }
139 
140  std::pair<const_iterator,const_iterator> equal_range(const Key& key) const
141  {
142  return container.equal_range(key);
143  }
144 
145  iterator lower_bound(const Key& key)
146  {
147  return container.lower_bound(key);
148  }
149 
150  const_iterator lower_bound(const Key& key) const
151  {
152  return container.lower_bound(key);
153  }
154 
155  iterator upper_bound(const Key& key)
156  {
157  return container.upper_bound(key);
158  }
159 
160  const_iterator upper_bound(const Key& key) const
161  {
162  return container.upper_bound(key);
163  }
164 
165 private:
166 
167  friend class ServiceHooks;
168 
169  ShrinkableMap(container_type& container)
170  : container(container)
171  {}
172 
173  container_type& container;
174 };
175 
176 template<class Key, class T>
178 
180 
181 #endif // USSHRINKABLEMAP_H
const_iterator lower_bound(const Key &key) const
size_type size() const
container_type::mapped_type mapped_type
container_type::key_type key_type
void erase(iterator first, iterator last)
void erase(iterator pos)
std::pair< const_iterator, const_iterator > equal_range(const Key &key) const
iterator find(const Key &key)
const_iterator end() const
iterator lower_bound(const Key &key)
container_type::const_iterator const_iterator
container_type::const_reference const_reference
std::pair< iterator, iterator > equal_range(const Key &key)
T & operator[](const Key &key)
size_type max_size() const
size_type erase(const Key &key)
iterator upper_bound(const Key &key)
container_type::value_type value_type
const_iterator find(const Key &key) const
size_type count(const Key &key) const
const_iterator begin() const
container_type::size_type size_type
#define US_END_NAMESPACE
#define US_BEGIN_NAMESPACE
container_type::iterator iterator
const_iterator upper_bound(const Key &key) const
bool empty() const
container_type::reference reference
std::map< Key, T > container_type