Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
usShrinkableMap.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef USSHRINKABLEMAP_H
14 #define USSHRINKABLEMAP_H
15 
16 #include <usGlobalConfig.h>
17 
18 #include <map>
19 
20 namespace us {
21 
28 template<class Key, class T>
30 {
31 private:
32  static std::map<Key,T> emptyContainer;
33 
34 public:
35 
36  typedef std::map<Key,T> container_type;
37  typedef typename container_type::iterator iterator;
38  typedef typename container_type::const_iterator const_iterator;
39  typedef typename container_type::size_type size_type;
40  typedef typename container_type::key_type key_type;
41  typedef typename container_type::mapped_type mapped_type;
42  typedef typename container_type::value_type value_type;
43  typedef typename container_type::reference reference;
44  typedef typename container_type::const_reference const_reference;
45 
47  : container(emptyContainer)
48  {
49  }
50 
52  {
53  return container.begin();
54  }
55 
57  {
58  return container.begin();
59  }
60 
62  {
63  return container.end();
64  }
65 
67  {
68  return container.end();
69  }
70 
71  void erase(iterator pos)
72  {
73  return container.erase(pos);
74  }
75 
76  void erase(iterator first, iterator last)
77  {
78  return container.erase(first, last);
79  }
80 
81  size_type erase(const Key& key)
82  {
83  return container.erase(key);
84  }
85 
86  bool empty() const
87  {
88  return container.empty();
89  }
90 
91  void clear()
92  {
93  container.clear();
94  }
95 
96  size_type size() const
97  {
98  return container.size();
99  }
100 
102  {
103  return container.max_size();
104  }
105 
106  T& operator[](const Key& key)
107  {
108  return container[key];
109  }
110 
111  size_type count(const Key& key) const
112  {
113  return container.count(key);
114  }
115 
116  iterator find(const Key& key)
117  {
118  return container.find(key);
119  }
120 
121  const_iterator find(const Key& key) const
122  {
123  return container.find(key);
124  }
125 
126  std::pair<iterator,iterator> equal_range(const Key& key)
127  {
128  return container.equal_range(key);
129  }
130 
131  std::pair<const_iterator,const_iterator> equal_range(const Key& key) const
132  {
133  return container.equal_range(key);
134  }
135 
136  iterator lower_bound(const Key& key)
137  {
138  return container.lower_bound(key);
139  }
140 
141  const_iterator lower_bound(const Key& key) const
142  {
143  return container.lower_bound(key);
144  }
145 
146  iterator upper_bound(const Key& key)
147  {
148  return container.upper_bound(key);
149  }
150 
151  const_iterator upper_bound(const Key& key) const
152  {
153  return container.upper_bound(key);
154  }
155 
156 private:
157 
158  friend class ServiceHooks;
159 
160  ShrinkableMap(container_type& container)
161  : container(container)
162  {}
163 
164  container_type& container;
165 };
166 
167 template<class Key, class T>
168 std::map<Key,T> ShrinkableMap<Key,T>::emptyContainer;
169 
170 }
171 
172 #endif // USSHRINKABLEMAP_H
A std::map style associative container allowing query and removal operations only.
container_type::iterator iterator
size_type size() const
const_iterator end() const
size_type count(const Key &key) const
std::map< Key, T > container_type
void erase(iterator pos)
size_type max_size() const
const_iterator upper_bound(const Key &key) const
const_iterator lower_bound(const Key &key) const
iterator upper_bound(const Key &key)
container_type::const_iterator const_iterator
friend class ServiceHooks
T & operator[](const Key &key)
std::pair< const_iterator, const_iterator > equal_range(const Key &key) const
const_iterator find(const Key &key) const
size_type erase(const Key &key)
container_type::key_type key_type
container_type::const_reference const_reference
void erase(iterator first, iterator last)
container_type::value_type value_type
std::pair< iterator, iterator > equal_range(const Key &key)
bool empty() const
container_type::mapped_type mapped_type
container_type::reference reference
iterator lower_bound(const Key &key)
const_iterator begin() const
container_type::size_type size_type
iterator find(const Key &key)