Medical Imaging Interaction Toolkit  2024.06.00
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
us::ShrinkableVector::clear
void clear()
Definition: usShrinkableVector.h:117
us::ShrinkableVector::empty
bool empty() const
Definition: usShrinkableVector.h:112
us::ShrinkableVector::end
iterator end()
Definition: usShrinkableVector.h:67
us::ShrinkableVector::back
reference back()
Definition: usShrinkableVector.h:87
us::ShrinkableVector::size
size_type size() const
Definition: usShrinkableVector.h:122
us::ShrinkableVector::end
const_iterator end() const
Definition: usShrinkableVector.h:72
us::ShrinkableVector::erase
iterator erase(iterator pos)
Definition: usShrinkableVector.h:97
us::ShrinkableVector::begin
const_iterator begin() const
Definition: usShrinkableVector.h:62
us::ShrinkableVector::begin
iterator begin()
Definition: usShrinkableVector.h:57
us::ShrinkableVector::at
reference at(size_type pos)
Definition: usShrinkableVector.h:127
us::ShrinkableVector::iterator
container_type::iterator iterator
Definition: usShrinkableVector.h:46
us::ShrinkableVector::reference
container_type::reference reference
Definition: usShrinkableVector.h:49
us::ShrinkableVector::ShrinkableVector
ShrinkableVector()
Definition: usShrinkableVector.h:52
us::ShrinkableVector::const_iterator
container_type::const_iterator const_iterator
Definition: usShrinkableVector.h:47
usGlobalConfig.h
US_BEGIN_NAMESPACE
#define US_BEGIN_NAMESPACE
Definition: usGlobalConfig.h:76
us::ShrinkableVector::const_reference
container_type::const_reference const_reference
Definition: usShrinkableVector.h:50
us::ShrinkableVector::front
reference front()
Definition: usShrinkableVector.h:77
US_END_NAMESPACE
#define US_END_NAMESPACE
Definition: usGlobalConfig.h:77
us::ShrinkableVector::back
const_reference back() const
Definition: usShrinkableVector.h:92
us::ShrinkableVector::front
const_reference front() const
Definition: usShrinkableVector.h:82
us::ShrinkableVector::container_type
std::vector< E > container_type
Definition: usShrinkableVector.h:45
us::ShrinkableVector::operator[]
reference operator[](size_type i)
Definition: usShrinkableVector.h:142
us::ShrinkableVector::operator[]
const_reference operator[](size_type i) const
Definition: usShrinkableVector.h:137
us::ShrinkableVector::size_type
container_type::size_type size_type
Definition: usShrinkableVector.h:48
us::ShrinkableVector::pop_back
void pop_back()
Definition: usShrinkableVector.h:107
us::ShrinkableVector::erase
iterator erase(iterator first, iterator last)
Definition: usShrinkableVector.h:102
us::ShrinkableVector
Definition: usShrinkableVector.h:38
us::ShrinkableVector::at
const_reference at(size_type pos) const
Definition: usShrinkableVector.h:132