Medical Imaging Interaction Toolkit  2016.11.0
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,
6  Division of Medical and Biological Informatics
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 USSHRINKABLEVECTOR_H
23 #define USSHRINKABLEVECTOR_H
24 
25 #include "usGlobalConfig.h"
26 
27 #include <vector>
28 
29 US_BEGIN_NAMESPACE
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 
57  iterator begin()
58  {
59  return container.begin();
60  }
61 
62  const_iterator begin() const
63  {
64  return container.begin();
65  }
66 
67  iterator end()
68  {
69  return container.end();
70  }
71 
72  const_iterator end() const
73  {
74  return container.end();
75  }
76 
77  reference front()
78  {
79  return container.front();
80  }
81 
82  const_reference front() const
83  {
84  return container.front();
85  }
86 
87  reference back()
88  {
89  return container.back();
90  }
91 
92  const_reference back() const
93  {
94  return container.back();
95  }
96 
97  iterator erase(iterator pos)
98  {
99  return container.erase(pos);
100  }
101 
102  iterator erase(iterator first, iterator last)
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 
127  reference at(size_type pos)
128  {
129  return container.at(pos);
130  }
131 
132  const_reference at(size_type pos) const
133  {
134  return container.at(pos);
135  }
136 
137  const_reference operator[](size_type i) const
138  {
139  return container[i];
140  }
141 
142  reference operator[](size_type i)
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 
162 US_END_NAMESPACE
163 
164 #endif // USSHRINKABLEVECTOR_H
container_type::reference reference
reference at(size_type pos)
const_iterator end() const
const_reference back() const
size_type size() const
std::vector< E > container_type
iterator erase(iterator pos)
container_type::const_iterator const_iterator
const_reference front() const
container_type::iterator iterator
const_reference operator[](size_type i) const
container_type::const_reference const_reference
const_iterator begin() const
container_type::size_type size_type
const_reference at(size_type pos) const
reference operator[](size_type i)
iterator erase(iterator first, iterator last)