OTB  9.0.0
Orfeo Toolbox
otbObjectList.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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_h
22 #define otbObjectList_h
23 
24 #include <vector>
25 #include "itkDataObject.h"
27 #include "itkObjectFactory.h"
28 
29 namespace otb
30 {
39 template <class TObject>
40 class ITK_EXPORT ObjectList : public itk::DataObject, public DataObjectListInterface
41 {
42 public:
44  typedef ObjectList Self;
45  typedef itk::DataObject Superclass;
46  typedef itk::SmartPointer<Self> Pointer;
47  typedef itk::SmartPointer<const Self> ConstPointer;
48 
50  itkTypeMacro(ObjectList, DataObject);
51 
53  itkNewMacro(Self);
54 
56  typedef TObject ObjectType;
57  typedef itk::SmartPointer<ObjectType> ObjectPointerType;
58  typedef std::vector<ObjectPointerType> InternalContainerType;
59  typedef typename InternalContainerType::size_type InternalContainerSizeType;
60 
65  void Reserve(InternalContainerSizeType size);
66 
71  InternalContainerSizeType Capacity(void) const;
72 
77  InternalContainerSizeType Size(void) const override;
78 
83  void Resize(InternalContainerSizeType size);
84 
89  void PushBack(ObjectType* element);
90 
94  void PopBack(void);
95 
101  void SetNthElement(unsigned int index, ObjectPointerType element);
102  void SetNthElement(unsigned int index, const ObjectType* element);
103 
109  ObjectPointerType GetNthElement(unsigned int index) const;
110 
115  Superclass* GetNthDataObject(unsigned int index) const override;
116 
121  ObjectPointerType Front(void);
122 
127  ObjectPointerType Back(void);
128 
133  void Erase(unsigned int index);
134 
138  void Clear(void);
139 
140  class ConstIterator;
141  class ReverseIterator;
142  class ReverseConstIterator;
143  class Iterator;
144  friend class Iterator;
145  friend class ConstIterator;
146  friend class ReverseIterator;
147  friend class ReverseConstIterator;
148 
154  Iterator Insert(Iterator position, ObjectPointerType element);
155 
161  ReverseIterator Insert(ReverseIterator position, ObjectPointerType element);
162 
168  class ITK_EXPORT Iterator
169  {
170  public:
171  friend class ObjectList;
172  friend class ConstIterator;
174  typedef typename InternalContainerType::iterator InternalIteratorType;
175 
177  Iterator(){};
178 
181  : m_Iter(iter)
182  {};
183 
189  {
190  return (*m_Iter);
191  }
192 
196  void Set(ObjectPointerType element)
197  {
198  (*m_Iter) = element;
199  }
200 
205  {
206  ++m_Iter;
207  return *this;
208  }
209 
214  {
215  --m_Iter;
216  return *this;
217  }
218 
223  {
224  Iterator lIter(m_Iter + i);
225  return lIter;
226  }
227 
232  {
233  Iterator lIter(m_Iter - i);
234  return lIter;
235  }
236 
240  {
241  return m_Iter + i;
242  }
243 
247  {
248  return m_Iter - i;
249  }
250 
254  bool operator!=(const Iterator& it)
255  {
256  return (m_Iter != it.m_Iter);
257  }
258 
262  bool operator==(const Iterator& it)
263  {
264  return (m_Iter == it.m_Iter);
265  }
266 
271  {
272  m_Iter = it.m_Iter;
273  return *this;
274  }
275 
279  Iterator(const Iterator& it)
280  : m_Iter(it.m_Iter)
281  {};
282 
287  {
288  return (m_Iter);
289  }
290 
291  private:
292  // Internal iterator.
294  };
300  class ITK_EXPORT ConstIterator
301  {
302  public:
303  friend class ObjectList;
304  friend class Iterator;
306  typedef typename InternalContainerType::const_iterator InternalConstIteratorType;
307 
310 
313  {
314  m_Iter = iter;
315  };
316 
322  {
323  return (*m_Iter);
324  }
325 
330  {
331  ++m_Iter;
332  return *this;
333  }
334 
339  {
340  --m_Iter;
341  return *this;
342  }
343 
347  bool operator!=(const ConstIterator& it)
348  {
349  return (m_Iter != it.m_Iter);
350  }
351 
355  bool operator==(const ConstIterator& it)
356  {
357  return (m_Iter == it.m_Iter);
358  }
359 
364  {
365  m_Iter = it.m_Iter;
366  return *this;
367  }
368 
373  {
374  m_Iter = it.m_Iter;
375  return *this;
376  }
377 
382  : m_Iter(it.m_Iter)
383  {};
384 
389  : m_Iter(it.m_Iter)
390  {};
391 
392  private:
393  // Internal iterator.
394  InternalConstIteratorType m_Iter;
395  };
401  class ITK_EXPORT ReverseIterator
402  {
403  public:
404  friend class ObjectList;
405  friend class Iterator;
406 
407  friend class ReverseConstIterator;
409  typedef typename InternalContainerType::reverse_iterator InternalReverseIteratorType;
410 
413 
416  : m_Iter(iter)
417  {};
418 
424  {
425  return (*m_Iter);
426  }
427 
431  void Set(ObjectPointerType element)
432  {
433  (*m_Iter) = element;
434  }
435 
440  {
441  ++m_Iter;
442  return *this;
443  }
444 
449  {
450  --m_Iter;
451  return *this;
452  }
453 
457  bool operator!=(const ReverseIterator& it)
458  {
459  return (m_Iter != it.m_Iter);
460  }
461 
465  bool operator==(const ReverseIterator& it)
466  {
467  return (m_Iter == it.m_Iter);
468  }
469 
474  {
475  m_Iter = it.m_Iter;
476  return *this;
477  }
478 
483  : m_Iter(it.m_Iter)
484  {};
485 
490  {
491  return (m_Iter);
492  }
493 
494  private:
495  // Internal iterator.
497  };
503  class ITK_EXPORT ReverseConstIterator
504  {
505  public:
506  friend class ObjectList;
507  friend class Iterator;
508  friend class ConstIterator;
509  friend class ReverseIterator;
511  typedef typename InternalContainerType::const_reverse_iterator InternalReverseConstIteratorType;
512 
515 
518  : m_Iter(iter)
519  {};
520 
526  {
527  return (*m_Iter);
528  }
529 
534  {
535  ++m_Iter;
536  return *this;
537  }
538 
543  {
544  --m_Iter;
545  return *this;
546  }
547 
552  {
553  return (m_Iter != it.m_Iter);
554  }
555 
560  {
561  return (m_Iter == it.m_Iter);
562  }
563 
568  {
569  m_Iter = it.m_Iter;
570  return *this;
571  }
572 
577  {
578  m_Iter = it.m_Iter;
579  return *this;
580  }
581 
586  {
587  m_Iter = it.m_Iter;
588  };
589 
594  {
595  m_Iter = it.m_Iter;
596  };
597 
598  private:
599  // Internal iterator.
600  InternalReverseConstIteratorType m_Iter;
601  };
606  Iterator Begin(void);
607 
612  ConstIterator Begin(void) const;
613 
618  ReverseIterator ReverseBegin(void);
619 
624  ReverseConstIterator ReverseBegin(void) const;
625 
630  Iterator End(void);
631 
636  ConstIterator End(void) const;
637 
642  ReverseIterator ReverseEnd(void);
643 
648  ReverseConstIterator ReverseEnd(void) const;
649 
655  void Erase(Iterator begin, Iterator end);
656 
661  void Erase(Iterator loc);
662 
663 protected:
665  ObjectList();
666 
668  ~ObjectList() override
669  {
670  }
671 
673  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
674 
675 private:
676  ObjectList(const Self&) = delete;
677  void operator=(const Self&) = delete;
680 };
681 } // end namespace otb
682 
683 #ifndef OTB_MANUAL_INSTANTIATION
684 #include "otbObjectList.hxx"
685 #endif
686 
687 #endif
otb::ObjectList::ReverseConstIterator::operator==
bool operator==(const ReverseConstIterator &it)
Definition: otbObjectList.h:559
otb::ObjectList::ObjectPointerType
itk::SmartPointer< ObjectType > ObjectPointerType
Definition: otbObjectList.h:57
otb::ObjectList::ConstIterator::operator!=
bool operator!=(const ConstIterator &it)
Definition: otbObjectList.h:347
otb::ObjectList::ReverseConstIterator::operator=
ReverseConstIterator & operator=(const ReverseConstIterator &it)
Definition: otbObjectList.h:567
otb::ObjectList::ReverseIterator::ReverseIterator
ReverseIterator(const ReverseIterator &it)
Definition: otbObjectList.h:482
otb::ObjectList::ReverseConstIterator::Get
ObjectPointerType Get(void)
Definition: otbObjectList.h:525
otb::ObjectList::Iterator::operator+=
Iterator operator+=(int i)
Definition: otbObjectList.h:239
otb::ObjectList::ReverseIterator::operator==
bool operator==(const ReverseIterator &it)
Definition: otbObjectList.h:465
otb::ObjectList::Iterator::InternalIteratorType
InternalContainerType::iterator InternalIteratorType
Definition: otbObjectList.h:174
otb::ObjectList::Iterator::Get
ObjectPointerType Get(void)
Definition: otbObjectList.h:188
otb::ObjectList::Iterator::Set
void Set(ObjectPointerType element)
Definition: otbObjectList.h:196
otb::ObjectList::ReverseConstIterator
ReverseConstIterator of the object list.
Definition: otbObjectList.h:503
otb::ObjectList::ReverseConstIterator::InternalReverseConstIteratorType
InternalContainerType::const_reverse_iterator InternalReverseConstIteratorType
Definition: otbObjectList.h:511
otb::ObjectList::Iterator::operator--
Iterator & operator--()
Definition: otbObjectList.h:213
otb::ObjectList::ReverseConstIterator::ReverseConstIterator
ReverseConstIterator(InternalReverseConstIteratorType iter)
Definition: otbObjectList.h:517
otb::ObjectList::ConstIterator::ConstIterator
ConstIterator(const ConstIterator &it)
Definition: otbObjectList.h:381
otb::ObjectList::Iterator::operator!=
bool operator!=(const Iterator &it)
Definition: otbObjectList.h:254
otb::ObjectList::Iterator::GetIter
InternalIteratorType & GetIter(void)
Definition: otbObjectList.h:286
otb::ObjectList::Iterator::m_Iter
InternalIteratorType m_Iter
Definition: otbObjectList.h:293
otb::ObjectList::Iterator::operator-
Iterator operator-(int i)
Definition: otbObjectList.h:231
otb::ObjectList::ObjectType
TObject ObjectType
Definition: otbObjectList.h:53
otb::ObjectList::ConstIterator::InternalConstIteratorType
InternalContainerType::const_iterator InternalConstIteratorType
Definition: otbObjectList.h:306
otb::ObjectList::ConstIterator
ConstIterator of the object list.
Definition: otbObjectList.h:300
otb::ObjectList::ConstIterator::ConstIterator
ConstIterator(InternalConstIteratorType iter)
Definition: otbObjectList.h:312
otb::ObjectList::Iterator::operator++
Iterator & operator++()
Definition: otbObjectList.h:204
otb::ObjectList::ReverseIterator::Get
ObjectPointerType Get(void)
Definition: otbObjectList.h:423
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ObjectList::ReverseConstIterator::operator!=
bool operator!=(const ReverseConstIterator &it)
Definition: otbObjectList.h:551
otb::ObjectList::ReverseIterator::ReverseIterator
ReverseIterator(InternalReverseIteratorType iter)
Definition: otbObjectList.h:415
otb::ObjectList::ReverseIterator::InternalReverseIteratorType
InternalContainerType::reverse_iterator InternalReverseIteratorType
Definition: otbObjectList.h:409
otb::ObjectList::Superclass
itk::DataObject Superclass
Definition: otbObjectList.h:45
otb::ObjectList::Iterator::operator=
Iterator & operator=(const Iterator &it)
Definition: otbObjectList.h:270
otb::ObjectList::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbObjectList.h:46
otb::ObjectList::ReverseIterator::operator=
ReverseIterator & operator=(const ReverseIterator &it)
Definition: otbObjectList.h:473
otb::ObjectList::ConstIterator::m_Iter
InternalConstIteratorType m_Iter
Definition: otbObjectList.h:390
otb::ObjectList::Iterator::operator-=
Iterator operator-=(int i)
Definition: otbObjectList.h:246
otb::ObjectList::ConstIterator::operator=
ConstIterator & operator=(const Iterator &it)
Definition: otbObjectList.h:372
otb::ObjectList::ConstIterator::operator++
ConstIterator & operator++()
Definition: otbObjectList.h:329
otb::ObjectList::ReverseConstIterator::m_Iter
InternalReverseConstIteratorType m_Iter
Definition: otbObjectList.h:596
otb::ObjectList::Iterator::operator+
Iterator operator+(int i)
Definition: otbObjectList.h:222
otb::ObjectList::ReverseConstIterator::ReverseConstIterator
ReverseConstIterator(const ReverseIterator &it)
Definition: otbObjectList.h:593
otb::ObjectList::ReverseConstIterator::operator++
ReverseConstIterator & operator++()
Definition: otbObjectList.h:533
otb::ObjectList::~ObjectList
~ObjectList() override
Definition: otbObjectList.h:668
otb::ObjectList::ReverseConstIterator::operator=
ReverseConstIterator & operator=(const ReverseIterator &it)
Definition: otbObjectList.h:576
otb::ObjectList::Self
ObjectList Self
Definition: otbObjectList.h:44
otb::ObjectList::ConstIterator::operator==
bool operator==(const ConstIterator &it)
Definition: otbObjectList.h:355
otb::ObjectList::InternalContainerSizeType
InternalContainerType::size_type InternalContainerSizeType
Definition: otbObjectList.h:59
otb::ObjectList::ReverseIterator
ReverseIterator of the object list.
Definition: otbObjectList.h:401
otbObjectList.hxx
otb::ObjectList::ReverseIterator::operator--
ReverseIterator & operator--()
Definition: otbObjectList.h:448
otb::ObjectList::ConstIterator::Get
ObjectPointerType Get(void)
Definition: otbObjectList.h:321
otb::ObjectList::ReverseConstIterator::ReverseConstIterator
ReverseConstIterator()
Definition: otbObjectList.h:514
otb::SamplingRateCalculator
This class is a sampling rate calculator.
Definition: otbSamplingRateCalculator.h:40
otb::ObjectList::Iterator
Iterator of the object list.
Definition: otbObjectList.h:168
otb::ObjectList::ConstIterator::ConstIterator
ConstIterator(const Iterator &it)
Definition: otbObjectList.h:388
otb::ObjectList::InternalContainerType
std::vector< ObjectPointerType > InternalContainerType
Definition: otbObjectList.h:58
otb::ObjectList::ReverseIterator::ReverseIterator
ReverseIterator()
Definition: otbObjectList.h:412
otb::ObjectList::ConstIterator::ConstIterator
ConstIterator()
Definition: otbObjectList.h:309
otb::ObjectList::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbObjectList.h:47
otb::ObjectList::ReverseIterator::m_Iter
InternalReverseIteratorType m_Iter
Definition: otbObjectList.h:496
otb::ObjectList::ReverseIterator::Set
void Set(ObjectPointerType element)
Definition: otbObjectList.h:431
otb::DataObjectListInterface
Definition: otbDataObjectListInterface.h:30
otb::ObjectList::m_InternalContainer
InternalContainerType m_InternalContainer
Definition: otbObjectList.h:679
otb::ObjectList::Iterator::Iterator
Iterator(InternalIteratorType iter)
Definition: otbObjectList.h:180
otb::ObjectList
This class is a generic all-purpose wrapping around an std::vector<itk::SmartPointer<ObjectType> >.
Definition: otbObjectList.h:40
otbDataObjectListInterface.h
otb::ObjectList::ReverseIterator::GetIter
InternalReverseIteratorType & GetIter(void)
Definition: otbObjectList.h:489
otb::ObjectList::ConstIterator::operator=
ConstIterator & operator=(const ConstIterator &it)
Definition: otbObjectList.h:363
otb::ObjectList::ReverseIterator::operator++
ReverseIterator & operator++()
Definition: otbObjectList.h:439
otb::ObjectList::ReverseConstIterator::ReverseConstIterator
ReverseConstIterator(const ReverseConstIterator &it)
Definition: otbObjectList.h:585
otb::ObjectList::Iterator::Iterator
Iterator()
Definition: otbObjectList.h:177
otb::ObjectList::ReverseIterator::operator!=
bool operator!=(const ReverseIterator &it)
Definition: otbObjectList.h:457
otb::ObjectList::Iterator::Iterator
Iterator(const Iterator &it)
Definition: otbObjectList.h:279
otb::ObjectList::ReverseConstIterator::operator--
ReverseConstIterator & operator--()
Definition: otbObjectList.h:542
otb::ObjectList::Iterator::operator==
bool operator==(const Iterator &it)
Definition: otbObjectList.h:262
otb::ObjectList::ConstIterator::operator--
ConstIterator & operator--()
Definition: otbObjectList.h:338