OTB  6.1.0
Orfeo Toolbox
otbObjectList.txx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
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 #ifndef otbObjectList_txx
22 #define otbObjectList_txx
23 
24 #include "otbObjectList.h"
25 #include "itkMacro.h"
26 
27 namespace otb
28 {
32 template <class TObject>
35 {}
36 
41 template <class TObject>
42 void
45 {
46  m_InternalContainer.reserve(size);
47 }
48 
53 template <class TObject>
56 ::Capacity(void) const
57 {
58  return m_InternalContainer.capacity();
59 }
60 
65 template <class TObject>
68 ::Size(void) const
69 {
70  return m_InternalContainer.size();
71 }
72 
77 template <class TObject>
78 void
81 {
82  m_InternalContainer.resize(size);
83 }
84 
89 template <class TObject>
90 void
93 {
94  m_InternalContainer.push_back(element);
95  this->Modified();
96 }
98 
102 template <class TObject>
103 void
106 {
107  if (m_InternalContainer.size() > 0)
108  {
109  m_InternalContainer.pop_back();
110  this->Modified();
111  }
112 }
114 
120 template <class TObject>
121 void
123 ::SetNthElement(unsigned int index, ObjectPointerType element)
124 {
125  if (index >= m_InternalContainer.size())
126  {
127  itkExceptionMacro(
128  << "Impossible to SetNthElement with the index element " << index <<
129  "; this element don't exist, the size of the list is " << m_InternalContainer.size() << ".");
130  }
131  m_InternalContainer[index] = element;
132  this->Modified();
133 }
134 
140 template <class TObject>
141 void
143 ::SetNthElement(unsigned int index, const ObjectType * element)
144 {
145  if (index >= m_InternalContainer.size())
146  {
147  itkExceptionMacro(
148  << "Impossible to SetNthElement with the index element " << index <<
149  "; this element don't exist, the size of the list is " << m_InternalContainer.size() << ".");
150  }
151  m_InternalContainer[index] = const_cast<ObjectType*>(element);
152  this->Modified();
153 }
155 
161 template <class TObject>
164 ::GetNthElement(unsigned int index) const
165 {
166  if (index >= m_InternalContainer.size())
167  {
168  itkExceptionMacro(
169  << "Impossible to GetNthElement with the index element " << index <<
170  "; this element don't exist, the size of the list is " << m_InternalContainer.size() << ".");
171  }
172  return m_InternalContainer[index];
173 }
174 
180 template <class TObject>
183 ::Front(void)
184 {
185  return m_InternalContainer.front();
186 }
191 template <class TObject>
194 ::Back(void)
195 {
196  return m_InternalContainer.back();
197 }
198 
203 template <class TObject>
204 void
206 ::Erase(unsigned int index)
207 {
208  if (index >= m_InternalContainer.size())
209  {
210  itkExceptionMacro(
211  << "Impossible to erase the index element " << index << "; the size of the list is " <<
212  m_InternalContainer.size() << ".");
213  }
214  m_InternalContainer.erase(m_InternalContainer.begin() + index);
215  this->Modified();
216 }
217 
221 template <class TObject>
222 void
224 ::Clear(void)
225 {
226  m_InternalContainer.clear();
227  this->Modified();
228 }
230 
234 template <class TObject>
238 {
239  Iterator iter(m_InternalContainer.insert(position.GetIter(), element));
240  this->Modified();
241  return iter;
242 }
244 
248 template <class TObject>
252 {
253  ReverseIterator iter(m_InternalContainer.insert(position.GetIter(), element));
254  this->Modified();
255  return iter;
256 }
258 
263 template <class TObject>
266 ::Begin(void)
267 {
268  Iterator iter(m_InternalContainer.begin());
269  return iter;
270 }
271 
276 template <class TObject>
279 ::Begin(void) const
280 {
281  ConstIterator iter(m_InternalContainer.begin());
282  return iter;
283 }
284 
289 template <class TObject>
293 {
294  ReverseIterator iter(m_InternalContainer.rbegin());
295  return iter;
296 }
297 
302 template <class TObject>
305 ::ReverseBegin(void) const
306 {
307  ReverseConstIterator iter(m_InternalContainer.rbegin());
308  return iter;
309 }
310 
315 template <class TObject>
318 ::End(void)
319 {
320  Iterator iter(m_InternalContainer.end());
321  return iter;
322 }
323 
328 template <class TObject>
331 ::End(void) const
332 {
333  ConstIterator iter(m_InternalContainer.end());
334  return iter;
335 }
336 
341 template <class TObject>
345 {
346  ReverseIterator iter(m_InternalContainer.rend());
347  return iter;
348 }
349 
354 template <class TObject>
357 ::ReverseEnd(void) const
358 {
359  ReverseConstIterator iter(m_InternalContainer.rend());
360  return iter;
361 }
362 
368 template <class TObject>
369 void
372 {
373  m_InternalContainer.erase(begin.GetIter(), end.GetIter());
374  this->Modified();
375 }
376 
381 template <class TObject>
382 void
385 {
386  m_InternalContainer.erase(loc.GetIter());
387  this->Modified();
388 }
390 
392 template <class TObject>
393 void
395 ::PrintSelf(std::ostream& os, itk::Indent indent) const
396 {
397  Superclass::PrintSelf(os, indent);
398  os << indent << "Size: " << m_InternalContainer.size() << std::endl;
399  os << indent << "List contains : " << std::endl;
400  ConstIterator iter = this->Begin();
401  while (iter != this->End())
402  {
403  os << indent.GetNextIndent() << iter.Get().GetPointer() << std::endl;
404  os << indent.GetNextIndent() << iter.Get() << std::endl;
405 // iter.Get()->PrintSelf(os, indent.GetNextIndent());
406 // iter.Get()->Print(os, indent.GetNextIndent());
407  ++iter;
408  }
409 }
410 } // end namespace otb
412 
413 #endif
ReverseIterator of the object list.
ReverseIterator ReverseBegin(void)
InternalContainerSizeType Size(void) const
InternalContainerType::size_type InternalContainerSizeType
Definition: otbObjectList.h:58
InternalIteratorType & GetIter(void)
ObjectPointerType GetNthElement(unsigned int index) const
void PrintSelf(std::ostream &os, itk::Indent indent) const ITK_OVERRIDE
Iterator End(void)
ReverseConstIterator of the object list.
ObjectType * GetPointer() const
Iterator of the object list.
ObjectPointerType Front(void)
void Resize(InternalContainerSizeType size)
TObject ObjectType
Definition: otbObjectList.h:52
void PopBack(void)
ObjectPointerType Get(void)
ObjectPointerType Back(void)
ConstIterator of the object list.
InternalReverseIteratorType & GetIter(void)
void Erase(unsigned int index)
void PushBack(ObjectType *element)
Iterator Begin(void)
void Reserve(InternalContainerSizeType size)
Iterator Insert(Iterator position, ObjectPointerType element)
void SetNthElement(unsigned int index, ObjectPointerType element)
ReverseIterator ReverseEnd(void)
InternalContainerSizeType Capacity(void) const
Indent GetNextIndent()