Orfeo ToolBox  4.2
Orfeo ToolBox is not a black box
otbObjectList.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbObjectList_txx
19 #define __otbObjectList_txx
20 
21 #include "otbObjectList.h"
22 #include "itkMacro.h"
23 
24 namespace otb
25 {
29 template <class TObject>
32 {}
37 template <class TObject>
38 void
40 ::Reserve(unsigned int size)
41 {
42  m_InternalContainer.reserve(size);
43 }
48 template <class TObject>
49 unsigned int
51 ::Capacity(void) const
52 {
53  return m_InternalContainer.capacity();
54 }
59 template <class TObject>
60 unsigned int
62 ::Size(void) const
63 {
64  return m_InternalContainer.size();
65 }
70 template <class TObject>
71 void
73 ::Resize(unsigned int size)
74 {
75  m_InternalContainer.resize(size);
76 }
81 template <class TObject>
82 void
85 {
86  m_InternalContainer.push_back(element);
87  this->Modified();
88 }
89 
93 template <class TObject>
94 void
96 ::PopBack(void)
97 {
98  if (m_InternalContainer.size() > 0)
99  {
100  m_InternalContainer.pop_back();
101  this->Modified();
102  }
103 }
104 
110 template <class TObject>
111 void
113 ::SetNthElement(unsigned int index, ObjectPointerType element)
114 {
115  if (index >= m_InternalContainer.size())
116  {
117  itkExceptionMacro(
118  << "Impossible to SetNthElement with the index element " << index <<
119  "; this element don't exist, the size of the list is " << m_InternalContainer.size() << ".");
120  }
121  m_InternalContainer[index] = element;
122  this->Modified();
123 }
129 template <class TObject>
130 void
132 ::SetNthElement(unsigned int index, const ObjectType * element)
133 {
134  if (index >= m_InternalContainer.size())
135  {
136  itkExceptionMacro(
137  << "Impossible to SetNthElement with the index element " << index <<
138  "; this element don't exist, the size of the list is " << m_InternalContainer.size() << ".");
139  }
140  m_InternalContainer[index] = const_cast<ObjectType*>(element);
141  this->Modified();
142 }
143 
149 template <class TObject>
152 ::GetNthElement(unsigned int index) const
153 {
154  if (index >= m_InternalContainer.size())
155  {
156  itkExceptionMacro(
157  << "Impossible to GetNthElement with the index element " << index <<
158  "; this element don't exist, the size of the list is " << m_InternalContainer.size() << ".");
159  }
160  return m_InternalContainer[index];
161 }
167 template <class TObject>
170 ::Front(void)
171 {
172  return m_InternalContainer.front();
173 }
178 template <class TObject>
181 ::Back(void)
182 {
183  return m_InternalContainer.back();
184 }
189 template <class TObject>
190 void
192 ::Erase(unsigned int index)
193 {
194  if (index >= m_InternalContainer.size())
195  {
196  itkExceptionMacro(
197  << "Impossible to erase the index element " << index << "; the size of the list is " <<
198  m_InternalContainer.size() << ".");
199  }
200  m_InternalContainer.erase(m_InternalContainer.begin() + index);
201  this->Modified();
202 }
206 template <class TObject>
207 void
209 ::Clear(void)
210 {
211  m_InternalContainer.clear();
212  this->Modified();
213 }
214 
218 template <class TObject>
222 {
223  Iterator iter(m_InternalContainer.insert(position.GetIter(), element));
224  this->Modified();
225  return iter;
226 }
227 
231 template <class TObject>
235 {
236  ReverseIterator iter(m_InternalContainer.insert(position.GetIter(), element));
237  this->Modified();
238  return iter;
239 }
240 
245 template <class TObject>
248 ::Begin(void)
249 {
250  Iterator iter(m_InternalContainer.begin());
251  return iter;
252 }
257 template <class TObject>
260 ::Begin(void) const
261 {
262  ConstIterator iter(m_InternalContainer.begin());
263  return iter;
264 }
269 template <class TObject>
273 {
274  ReverseIterator iter(m_InternalContainer.rbegin());
275  return iter;
276 }
281 template <class TObject>
284 ::ReverseBegin(void) const
285 {
286  ReverseConstIterator iter(m_InternalContainer.rbegin());
287  return iter;
288 }
293 template <class TObject>
296 ::End(void)
297 {
298  Iterator iter(m_InternalContainer.end());
299  return iter;
300 }
305 template <class TObject>
308 ::End(void) const
309 {
310  ConstIterator iter(m_InternalContainer.end());
311  return iter;
312 }
317 template <class TObject>
321 {
322  ReverseIterator iter(m_InternalContainer.rend());
323  return iter;
324 }
329 template <class TObject>
332 ::ReverseEnd(void) const
333 {
334  ReverseConstIterator iter(m_InternalContainer.rend());
335  return iter;
336 }
342 template <class TObject>
343 void
346 {
347  m_InternalContainer.erase(begin.GetIter(), end.GetIter());
348  this->Modified();
349 }
354 template <class TObject>
355 void
358 {
359  m_InternalContainer.erase(loc.GetIter());
360  this->Modified();
361 }
362 
364 template <class TObject>
365 void
367 ::PrintSelf(std::ostream& os, itk::Indent indent) const
368 {
369  Superclass::PrintSelf(os, indent);
370  os << indent << "Size: " << m_InternalContainer.size() << std::endl;
371  os << indent << "List contains : " << std::endl;
372  ConstIterator iter = this->Begin();
373  while (iter != this->End())
374  {
375  os << indent.GetNextIndent() << iter.Get().GetPointer() << std::endl;
376  os << indent.GetNextIndent() << iter.Get() << std::endl;
377 // iter.Get()->PrintSelf(os, indent.GetNextIndent());
378 // iter.Get()->Print(os, indent.GetNextIndent());
379  ++iter;
380  }
381 }
382 } // end namespace otb
383 
384 #endif
ReverseIterator of the object list.
ReverseIterator ReverseBegin(void)
InternalIteratorType & GetIter(void)
ObjectPointerType GetNthElement(unsigned int index) const
Iterator End(void)
ReverseConstIterator of the object list.
ObjectType * GetPointer() const
unsigned int Size(void) const
Iterator of the object list.
void PrintSelf(std::ostream &os, itk::Indent indent) const
ObjectPointerType Front(void)
TObject ObjectType
Definition: otbObjectList.h:47
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)
Iterator Insert(Iterator position, ObjectPointerType element)
void SetNthElement(unsigned int index, ObjectPointerType element)
void Reserve(unsigned int size)
ReverseIterator ReverseEnd(void)
Indent GetNextIndent()
void Resize(unsigned int size)
unsigned int Capacity(void) const