OTB  5.0.0
Orfeo Toolbox
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 {}
33 
38 template <class TObject>
39 void
41 ::Reserve(unsigned int size)
42 {
43  m_InternalContainer.reserve(size);
44 }
45 
50 template <class TObject>
51 unsigned int
53 ::Capacity(void) const
54 {
55  return m_InternalContainer.capacity();
56 }
57 
62 template <class TObject>
63 unsigned int
65 ::Size(void) const
66 {
67  return m_InternalContainer.size();
68 }
69 
74 template <class TObject>
75 void
77 ::Resize(unsigned int size)
78 {
79  m_InternalContainer.resize(size);
80 }
81 
86 template <class TObject>
87 void
90 {
91  m_InternalContainer.push_back(element);
92  this->Modified();
93 }
95 
99 template <class TObject>
100 void
103 {
104  if (m_InternalContainer.size() > 0)
105  {
106  m_InternalContainer.pop_back();
107  this->Modified();
108  }
109 }
111 
117 template <class TObject>
118 void
120 ::SetNthElement(unsigned int index, ObjectPointerType element)
121 {
122  if (index >= m_InternalContainer.size())
123  {
124  itkExceptionMacro(
125  << "Impossible to SetNthElement with the index element " << index <<
126  "; this element don't exist, the size of the list is " << m_InternalContainer.size() << ".");
127  }
128  m_InternalContainer[index] = element;
129  this->Modified();
130 }
131 
137 template <class TObject>
138 void
140 ::SetNthElement(unsigned int index, const ObjectType * element)
141 {
142  if (index >= m_InternalContainer.size())
143  {
144  itkExceptionMacro(
145  << "Impossible to SetNthElement with the index element " << index <<
146  "; this element don't exist, the size of the list is " << m_InternalContainer.size() << ".");
147  }
148  m_InternalContainer[index] = const_cast<ObjectType*>(element);
149  this->Modified();
150 }
152 
158 template <class TObject>
161 ::GetNthElement(unsigned int index) const
162 {
163  if (index >= m_InternalContainer.size())
164  {
165  itkExceptionMacro(
166  << "Impossible to GetNthElement with the index element " << index <<
167  "; this element don't exist, the size of the list is " << m_InternalContainer.size() << ".");
168  }
169  return m_InternalContainer[index];
170 }
171 
177 template <class TObject>
180 ::Front(void)
181 {
182  return m_InternalContainer.front();
183 }
188 template <class TObject>
191 ::Back(void)
192 {
193  return m_InternalContainer.back();
194 }
195 
200 template <class TObject>
201 void
203 ::Erase(unsigned int index)
204 {
205  if (index >= m_InternalContainer.size())
206  {
207  itkExceptionMacro(
208  << "Impossible to erase the index element " << index << "; the size of the list is " <<
209  m_InternalContainer.size() << ".");
210  }
211  m_InternalContainer.erase(m_InternalContainer.begin() + index);
212  this->Modified();
213 }
214 
218 template <class TObject>
219 void
221 ::Clear(void)
222 {
223  m_InternalContainer.clear();
224  this->Modified();
225 }
227 
231 template <class TObject>
235 {
236  Iterator iter(m_InternalContainer.insert(position.GetIter(), element));
237  this->Modified();
238  return iter;
239 }
241 
245 template <class TObject>
249 {
250  ReverseIterator iter(m_InternalContainer.insert(position.GetIter(), element));
251  this->Modified();
252  return iter;
253 }
255 
260 template <class TObject>
263 ::Begin(void)
264 {
265  Iterator iter(m_InternalContainer.begin());
266  return iter;
267 }
268 
273 template <class TObject>
276 ::Begin(void) const
277 {
278  ConstIterator iter(m_InternalContainer.begin());
279  return iter;
280 }
281 
286 template <class TObject>
290 {
291  ReverseIterator iter(m_InternalContainer.rbegin());
292  return iter;
293 }
294 
299 template <class TObject>
302 ::ReverseBegin(void) const
303 {
304  ReverseConstIterator iter(m_InternalContainer.rbegin());
305  return iter;
306 }
307 
312 template <class TObject>
315 ::End(void)
316 {
317  Iterator iter(m_InternalContainer.end());
318  return iter;
319 }
320 
325 template <class TObject>
328 ::End(void) const
329 {
330  ConstIterator iter(m_InternalContainer.end());
331  return iter;
332 }
333 
338 template <class TObject>
342 {
343  ReverseIterator iter(m_InternalContainer.rend());
344  return iter;
345 }
346 
351 template <class TObject>
354 ::ReverseEnd(void) const
355 {
356  ReverseConstIterator iter(m_InternalContainer.rend());
357  return iter;
358 }
359 
365 template <class TObject>
366 void
369 {
370  m_InternalContainer.erase(begin.GetIter(), end.GetIter());
371  this->Modified();
372 }
373 
378 template <class TObject>
379 void
382 {
383  m_InternalContainer.erase(loc.GetIter());
384  this->Modified();
385 }
387 
389 template <class TObject>
390 void
392 ::PrintSelf(std::ostream& os, itk::Indent indent) const
393 {
394  Superclass::PrintSelf(os, indent);
395  os << indent << "Size: " << m_InternalContainer.size() << std::endl;
396  os << indent << "List contains : " << std::endl;
397  ConstIterator iter = this->Begin();
398  while (iter != this->End())
399  {
400  os << indent.GetNextIndent() << iter.Get().GetPointer() << std::endl;
401  os << indent.GetNextIndent() << iter.Get() << std::endl;
402 // iter.Get()->PrintSelf(os, indent.GetNextIndent());
403 // iter.Get()->Print(os, indent.GetNextIndent());
404  ++iter;
405  }
406 }
407 } // end namespace otb
409 
410 #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:49
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