OTB  7.2.0
Orfeo Toolbox
otbObjectList.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2020 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>
34 {
35 }
36 
41 template <class TObject>
43 {
44  m_InternalContainer.reserve(size);
45 }
46 
51 template <class TObject>
53 {
54  return m_InternalContainer.capacity();
55 }
56 
61 template <class TObject>
63 {
64  return m_InternalContainer.size();
65 }
66 
71 template <class TObject>
73 {
74  m_InternalContainer.resize(size);
75 }
76 
81 template <class TObject>
83 {
84  m_InternalContainer.push_back(element);
85  this->Modified();
86 }
88 
92 template <class TObject>
94 {
95  if (m_InternalContainer.size() > 0)
96  {
97  m_InternalContainer.pop_back();
98  this->Modified();
99  }
100 }
102 
108 template <class TObject>
110 {
111  if (index >= m_InternalContainer.size())
112  {
113  itkExceptionMacro(<< "Impossible to SetNthElement with the index element " << index << "; this element don't exist, the size of the list is "
114  << m_InternalContainer.size() << ".");
115  }
116  m_InternalContainer[index] = element;
117  this->Modified();
118 }
119 
125 template <class TObject>
126 void ObjectList<TObject>::SetNthElement(unsigned int index, const ObjectType* element)
127 {
128  if (index >= m_InternalContainer.size())
129  {
130  itkExceptionMacro(<< "Impossible to SetNthElement with the index element " << index << "; this element don't exist, the size of the list is "
131  << m_InternalContainer.size() << ".");
132  }
133  m_InternalContainer[index] = const_cast<ObjectType*>(element);
134  this->Modified();
135 }
137 
143 template <class TObject>
145 {
146  if (index >= m_InternalContainer.size())
147  {
148  itkExceptionMacro(<< "Impossible to GetNthElement with the index element " << index << "; this element don't exist, the size of the list is "
149  << m_InternalContainer.size() << ".");
150  }
151  return m_InternalContainer[index];
152 }
154 
155 template <class TObject>
157 {
158 
159  return dynamic_cast<itk::DataObject*>(GetNthElement(index).GetPointer());
160 }
161 
167 template <class TObject>
169 {
170  return m_InternalContainer.front();
171 }
176 template <class TObject>
178 {
179  return m_InternalContainer.back();
180 }
181 
186 template <class TObject>
187 void ObjectList<TObject>::Erase(unsigned int index)
188 {
189  if (index >= m_InternalContainer.size())
190  {
191  itkExceptionMacro(<< "Impossible to erase the index element " << index << "; the size of the list is " << m_InternalContainer.size() << ".");
192  }
193  m_InternalContainer.erase(m_InternalContainer.begin() + index);
194  this->Modified();
195 }
196 
200 template <class TObject>
202 {
203  m_InternalContainer.clear();
204  this->Modified();
205 }
207 
211 template <class TObject>
213 {
214  Iterator iter(m_InternalContainer.insert(position.GetIter(), element));
215  this->Modified();
216  return iter;
217 }
219 
223 template <class TObject>
225 {
226  ReverseIterator iter((typename InternalContainerType::reverse_iterator)(m_InternalContainer.insert(position.GetIter().base(), element)));
227  this->Modified();
228  return iter;
229 }
231 
236 template <class TObject>
238 {
239  Iterator iter(m_InternalContainer.begin());
240  return iter;
241 }
242 
247 template <class TObject>
249 {
250  ConstIterator iter(m_InternalContainer.begin());
251  return iter;
252 }
253 
258 template <class TObject>
260 {
261  ReverseIterator iter(m_InternalContainer.rbegin());
262  return iter;
263 }
264 
269 template <class TObject>
271 {
272  ReverseConstIterator iter(m_InternalContainer.rbegin());
273  return iter;
274 }
275 
280 template <class TObject>
282 {
283  Iterator iter(m_InternalContainer.end());
284  return iter;
285 }
286 
291 template <class TObject>
293 {
294  ConstIterator iter(m_InternalContainer.end());
295  return iter;
296 }
297 
302 template <class TObject>
304 {
305  ReverseIterator iter(m_InternalContainer.rend());
306  return iter;
307 }
308 
313 template <class TObject>
315 {
316  ReverseConstIterator iter(m_InternalContainer.rend());
317  return iter;
318 }
319 
325 template <class TObject>
326 void ObjectList<TObject>::Erase(Iterator begin, Iterator end)
327 {
328  m_InternalContainer.erase(begin.GetIter(), end.GetIter());
329  this->Modified();
330 }
331 
336 template <class TObject>
337 void ObjectList<TObject>::Erase(Iterator loc)
338 {
339  m_InternalContainer.erase(loc.GetIter());
340  this->Modified();
341 }
343 
345 template <class TObject>
346 void ObjectList<TObject>::PrintSelf(std::ostream& os, itk::Indent indent) const
347 {
348  Superclass::PrintSelf(os, indent);
349  os << indent << "Size: " << m_InternalContainer.size() << std::endl;
350  os << indent << "List contains : " << std::endl;
351  ConstIterator iter = this->Begin();
352  while (iter != this->End())
353  {
354  os << indent.GetNextIndent() << iter.Get().GetPointer() << std::endl;
355  os << indent.GetNextIndent() << iter.Get() << std::endl;
356  // iter.Get()->PrintSelf(os, indent.GetNextIndent());
357  // iter.Get()->Print(os, indent.GetNextIndent());
358  ++iter;
359  }
360 }
361 } // end namespace otb
363 
364 #endif
ReverseIterator of the object list.
ReverseIterator ReverseBegin(void)
InternalContainerType::size_type InternalContainerSizeType
Definition: otbObjectList.h:59
InternalContainerSizeType Size(void) const override
Iterator End(void)
ReverseConstIterator of the object list.
Iterator of the object list.
ObjectPointerType Front(void)
void Resize(InternalContainerSizeType size)
itk::SmartPointer< ObjectType > ObjectPointerType
Definition: otbObjectList.h:57
void PopBack(void)
ObjectPointerType Back(void)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
ConstIterator of the object list.
void Erase(unsigned int index)
InternalContainerSizeType Capacity(void) const
Superclass * GetNthDataObject(unsigned int index) const override
void PushBack(ObjectType *element)
Iterator Begin(void)
void Reserve(InternalContainerSizeType size)
This class is a sampling rate calculator.
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)
ObjectPointerType GetNthElement(unsigned int index) const
itk::DataObject Superclass
Definition: otbObjectList.h:45