Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
usShrinkableVector.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 USSHRINKABLEVECTOR_H
23 #define USSHRINKABLEVECTOR_H
24 
25 #include "usGlobalConfig.h"
26 
27 #include <vector>
28 
30 
37 template<class E>
39 {
40 private:
41  static std::vector<E> emptyVector;
42 
43 public:
44 
45  typedef std::vector<E> 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::reference reference;
50  typedef typename container_type::const_reference const_reference;
51 
53  : container(emptyVector)
54  {
55  }
56 
58  {
59  return container.begin();
60  }
61 
63  {
64  return container.begin();
65  }
66 
68  {
69  return container.end();
70  }
71 
73  {
74  return container.end();
75  }
76 
78  {
79  return container.front();
80  }
81 
83  {
84  return container.front();
85  }
86 
88  {
89  return container.back();
90  }
91 
93  {
94  return container.back();
95  }
96 
98  {
99  return container.erase(pos);
100  }
101 
103  {
104  return container.erase(first, last);
105  }
106 
107  void pop_back()
108  {
109  container.pop_back();
110  }
111 
112  bool empty() const
113  {
114  return container.empty();
115  }
116 
117  void clear()
118  {
119  container.clear();
120  }
121 
122  size_type size() const
123  {
124  return container.size();
125  }
126 
128  {
129  return container.at(pos);
130  }
131 
133  {
134  return container.at(pos);
135  }
136 
138  {
139  return container[i];
140  }
141 
143  {
144  return container[i];
145  }
146 
147 private:
148 
149  friend class ModuleHooks;
150  friend class ServiceHooks;
151 
152  ShrinkableVector(container_type& container)
153  : container(container)
154  {}
155 
156  container_type& container;
157 };
158 
159 template<class E>
160 std::vector<E> ShrinkableVector<E>::emptyVector;
161 
163 
164 #endif // USSHRINKABLEVECTOR_H
const_reference operator[](size_type i) const
container_type::reference reference
container_type::const_reference const_reference
std::vector< E > container_type
container_type::size_type size_type
const_reference at(size_type pos) const
reference at(size_type pos)
const_iterator begin() const
const_reference front() const
reference operator[](size_type i)
size_type size() const
const_iterator end() const
const_reference back() const
iterator erase(iterator first, iterator last)
container_type::const_iterator const_iterator
iterator erase(iterator pos)
container_type::iterator iterator
#define US_END_NAMESPACE
#define US_BEGIN_NAMESPACE