Medical Imaging Interaction Toolkit  2024.12.99-0da743f6
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  https://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 
61  {
62  return container.begin();
63  }
64 
66  {
67  return container.begin();
68  }
69 
71  {
72  return container.end();
73  }
74 
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 
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>
177 std::map<Key,T> ShrinkableMap<Key,T>::emptyContainer;
178 
180 
181 #endif // USSHRINKABLEMAP_H
us::ShrinkableMap::begin
iterator begin()
Definition: usShrinkableMap.h:60
us::ShrinkableMap::equal_range
std::pair< const_iterator, const_iterator > equal_range(const Key &key) const
Definition: usShrinkableMap.h:140
us::ShrinkableMap::value_type
container_type::value_type value_type
Definition: usShrinkableMap.h:51
us::ShrinkableMap::upper_bound
iterator upper_bound(const Key &key)
Definition: usShrinkableMap.h:155
us::ShrinkableMap::find
const_iterator find(const Key &key) const
Definition: usShrinkableMap.h:130
us::ShrinkableMap::lower_bound
const_iterator lower_bound(const Key &key) const
Definition: usShrinkableMap.h:150
us::ShrinkableMap::size
size_type size() const
Definition: usShrinkableMap.h:105
us::ShrinkableMap::iterator
container_type::iterator iterator
Definition: usShrinkableMap.h:46
us::ShrinkableMap::end
const_iterator end() const
Definition: usShrinkableMap.h:75
us::ShrinkableMap::ShrinkableMap
ShrinkableMap()
Definition: usShrinkableMap.h:55
us::ShrinkableMap::empty
bool empty() const
Definition: usShrinkableMap.h:95
us::ShrinkableMap::begin
const_iterator begin() const
Definition: usShrinkableMap.h:65
us::ShrinkableMap::max_size
size_type max_size() const
Definition: usShrinkableMap.h:110
us::ShrinkableMap::equal_range
std::pair< iterator, iterator > equal_range(const Key &key)
Definition: usShrinkableMap.h:135
us::ShrinkableMap::erase
size_type erase(const Key &key)
Definition: usShrinkableMap.h:90
us::ShrinkableMap::clear
void clear()
Definition: usShrinkableMap.h:100
us::ShrinkableMap::reference
container_type::reference reference
Definition: usShrinkableMap.h:52
us::ShrinkableMap::count
size_type count(const Key &key) const
Definition: usShrinkableMap.h:120
us::ShrinkableMap::mapped_type
container_type::mapped_type mapped_type
Definition: usShrinkableMap.h:50
us::ShrinkableMap::find
iterator find(const Key &key)
Definition: usShrinkableMap.h:125
us::ShrinkableMap
Definition: usShrinkableMap.h:38
usGlobalConfig.h
us::ShrinkableMap::erase
void erase(iterator pos)
Definition: usShrinkableMap.h:80
US_BEGIN_NAMESPACE
#define US_BEGIN_NAMESPACE
Definition: usGlobalConfig.h:76
us::ShrinkableMap::erase
void erase(iterator first, iterator last)
Definition: usShrinkableMap.h:85
us::ShrinkableMap::container_type
std::map< Key, T > container_type
Definition: usShrinkableMap.h:45
us::ShrinkableMap::lower_bound
iterator lower_bound(const Key &key)
Definition: usShrinkableMap.h:145
us::ShrinkableMap::const_reference
container_type::const_reference const_reference
Definition: usShrinkableMap.h:53
us::ShrinkableMap::end
iterator end()
Definition: usShrinkableMap.h:70
US_END_NAMESPACE
#define US_END_NAMESPACE
Definition: usGlobalConfig.h:77
us::ShrinkableMap::upper_bound
const_iterator upper_bound(const Key &key) const
Definition: usShrinkableMap.h:160
us::ShrinkableMap::size_type
container_type::size_type size_type
Definition: usShrinkableMap.h:48
us::ShrinkableMap::const_iterator
container_type::const_iterator const_iterator
Definition: usShrinkableMap.h:47
us::ShrinkableMap::key_type
container_type::key_type key_type
Definition: usShrinkableMap.h:49
us::ShrinkableMap::operator[]
T & operator[](const Key &key)
Definition: usShrinkableMap.h:115