OTB  6.7.0
Orfeo Toolbox
otbObjectList.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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_hxx
22 #define otbObjectList_hxx
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 }
175 
176 template <class TObject>
179 ::GetNthDataObject(unsigned int index) const
180 {
181 
182  return dynamic_cast<itk::DataObject *> ( GetNthElement(index).GetPointer() );
183 }
184 
190 template <class TObject>
193 ::Front(void)
194 {
195  return m_InternalContainer.front();
196 }
201 template <class TObject>
204 ::Back(void)
205 {
206  return m_InternalContainer.back();
207 }
208 
213 template <class TObject>
214 void
216 ::Erase(unsigned int index)
217 {
218  if (index >= m_InternalContainer.size())
219  {
220  itkExceptionMacro(
221  << "Impossible to erase the index element " << index << "; the size of the list is " <<
222  m_InternalContainer.size() << ".");
223  }
224  m_InternalContainer.erase(m_InternalContainer.begin() + index);
225  this->Modified();
226 }
227 
231 template <class TObject>
232 void
234 ::Clear(void)
235 {
236  m_InternalContainer.clear();
237  this->Modified();
238 }
240 
244 template <class TObject>
248 {
249  Iterator iter(m_InternalContainer.insert(position.GetIter(), element));
250  this->Modified();
251  return iter;
252 }
254 
258 template <class TObject>
262 {
263  ReverseIterator iter(
264  (typename InternalContainerType::reverse_iterator)(
265  m_InternalContainer.insert(position.GetIter().base(), element)
266  )
267  );
268  this->Modified();
269  return iter;
270 }
272 
277 template <class TObject>
280 ::Begin(void)
281 {
282  Iterator iter(m_InternalContainer.begin());
283  return iter;
284 }
285 
290 template <class TObject>
293 ::Begin(void) const
294 {
295  ConstIterator iter(m_InternalContainer.begin());
296  return iter;
297 }
298 
303 template <class TObject>
307 {
308  ReverseIterator iter(m_InternalContainer.rbegin());
309  return iter;
310 }
311 
316 template <class TObject>
319 ::ReverseBegin(void) const
320 {
321  ReverseConstIterator iter(m_InternalContainer.rbegin());
322  return iter;
323 }
324 
329 template <class TObject>
332 ::End(void)
333 {
334  Iterator iter(m_InternalContainer.end());
335  return iter;
336 }
337 
342 template <class TObject>
345 ::End(void) const
346 {
347  ConstIterator iter(m_InternalContainer.end());
348  return iter;
349 }
350 
355 template <class TObject>
359 {
360  ReverseIterator iter(m_InternalContainer.rend());
361  return iter;
362 }
363 
368 template <class TObject>
371 ::ReverseEnd(void) const
372 {
373  ReverseConstIterator iter(m_InternalContainer.rend());
374  return iter;
375 }
376 
382 template <class TObject>
383 void
386 {
387  m_InternalContainer.erase(begin.GetIter(), end.GetIter());
388  this->Modified();
389 }
390 
395 template <class TObject>
396 void
399 {
400  m_InternalContainer.erase(loc.GetIter());
401  this->Modified();
402 }
404 
406 template <class TObject>
407 void
409 ::PrintSelf(std::ostream& os, itk::Indent indent) const
410 {
411  Superclass::PrintSelf(os, indent);
412  os << indent << "Size: " << m_InternalContainer.size() << std::endl;
413  os << indent << "List contains : " << std::endl;
414  ConstIterator iter = this->Begin();
415  while (iter != this->End())
416  {
417  os << indent.GetNextIndent() << iter.Get().GetPointer() << std::endl;
418  os << indent.GetNextIndent() << iter.Get() << std::endl;
419 // iter.Get()->PrintSelf(os, indent.GetNextIndent());
420 // iter.Get()->Print(os, indent.GetNextIndent());
421  ++iter;
422  }
423 }
424 } // end namespace otb
426 
427 #endif
ReverseIterator of the object list.
ReverseIterator ReverseBegin(void)
InternalContainerType::size_type InternalContainerSizeType
Definition: otbObjectList.h:59
InternalIteratorType & GetIter(void)
ObjectPointerType GetNthElement(unsigned int index) const
InternalContainerSizeType Size(void) const 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:53
void PopBack(void)
ObjectPointerType Get(void)
ObjectPointerType Back(void)
ConstIterator of the object list.
InternalReverseIteratorType & GetIter(void)
void Erase(unsigned int index)
Superclass * GetNthDataObject(unsigned int index) const override
void PushBack(ObjectType *element)
Iterator Begin(void)
void Reserve(InternalContainerSizeType size)
Iterator Insert(Iterator position, ObjectPointerType element)
void SetNthElement(unsigned int index, ObjectPointerType element)
void PrintSelf(std::ostream &os, itk::Indent indent) const override
ReverseIterator ReverseEnd(void)
InternalContainerSizeType Capacity(void) const
Indent GetNextIndent()