OTB  7.2.0
Orfeo Toolbox
otbObjectList.h
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_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 
180  Iterator(InternalIteratorType iter)
181  {
182  m_Iter = iter;
183  };
184 
189  ObjectPointerType Get(void)
190  {
191  return (*m_Iter);
192  }
193 
197  void Set(ObjectPointerType element)
198  {
199  (*m_Iter) = element;
200  }
201 
206  {
207  ++m_Iter;
208  return *this;
209  }
210 
215  {
216  --m_Iter;
217  return *this;
218  }
219 
224  {
225  Iterator lIter(m_Iter + i);
226  return lIter;
227  }
228 
233  {
234  Iterator lIter(m_Iter - i);
235  return lIter;
236  }
237 
241  {
242  return m_Iter + i;
243  }
244 
248  {
249  return m_Iter - i;
250  }
251 
255  bool operator!=(const Iterator& it)
256  {
257  return (m_Iter != it.m_Iter);
258  }
259 
263  bool operator==(const Iterator& it)
264  {
265  return (m_Iter == it.m_Iter);
266  }
267 
272  {
273  m_Iter = it.m_Iter;
274  return *this;
275  }
276 
280  Iterator(const Iterator& it)
281  {
282  m_Iter = it.m_Iter;
283  };
284 
288  InternalIteratorType& GetIter(void)
289  {
290  return (m_Iter);
291  }
292 
293  private:
294  // Internal iterator.
295  InternalIteratorType m_Iter;
296  };
302  class ITK_EXPORT ConstIterator
303  {
304  public:
305  friend class ObjectList;
306  friend class Iterator;
308  typedef typename InternalContainerType::const_iterator InternalConstIteratorType;
309 
312 
314  ConstIterator(InternalConstIteratorType iter)
315  {
316  m_Iter = iter;
317  };
318 
323  ObjectPointerType Get(void)
324  {
325  return (*m_Iter);
326  }
327 
332  {
333  ++m_Iter;
334  return *this;
335  }
336 
341  {
342  --m_Iter;
343  return *this;
344  }
345 
349  bool operator!=(const ConstIterator& it)
350  {
351  return (m_Iter != it.m_Iter);
352  }
353 
357  bool operator==(const ConstIterator& it)
358  {
359  return (m_Iter == it.m_Iter);
360  }
361 
366  {
367  m_Iter = it.m_Iter;
368  return *this;
369  }
370 
375  {
376  m_Iter = it.m_Iter;
377  return *this;
378  }
379 
384  {
385  m_Iter = it.m_Iter;
386  };
387 
392  {
393  m_Iter = it.m_Iter;
394  };
395 
396  private:
397  // Internal iterator.
398  InternalConstIteratorType m_Iter;
399  };
405  class ITK_EXPORT ReverseIterator
406  {
407  public:
408  friend class ObjectList;
409  friend class Iterator;
410 
411  friend class ReverseConstIterator;
413  typedef typename InternalContainerType::reverse_iterator InternalReverseIteratorType;
414 
417 
419  ReverseIterator(InternalReverseIteratorType iter)
420  {
421  m_Iter = iter;
422  };
423 
428  ObjectPointerType Get(void)
429  {
430  return (*m_Iter);
431  }
432 
436  void Set(ObjectPointerType element)
437  {
438  (*m_Iter) = element;
439  }
440 
445  {
446  ++m_Iter;
447  return *this;
448  }
449 
454  {
455  --m_Iter;
456  return *this;
457  }
458 
462  bool operator!=(const ReverseIterator& it)
463  {
464  return (m_Iter != it.m_Iter);
465  }
466 
470  bool operator==(const ReverseIterator& it)
471  {
472  return (m_Iter == it.m_Iter);
473  }
474 
479  {
480  m_Iter = it.m_Iter;
481  return *this;
482  }
483 
488  {
489  m_Iter = it.m_Iter;
490  };
491 
495  InternalReverseIteratorType& GetIter(void)
496  {
497  return (m_Iter);
498  }
499 
500  private:
501  // Internal iterator.
502  InternalReverseIteratorType m_Iter;
503  };
509  class ITK_EXPORT ReverseConstIterator
510  {
511  public:
512  friend class ObjectList;
513  friend class Iterator;
514  friend class ConstIterator;
515  friend class ReverseIterator;
517  typedef typename InternalContainerType::const_reverse_iterator InternalReverseConstIteratorType;
518 
521 
523  ReverseConstIterator(InternalReverseConstIteratorType iter)
524  {
525  m_Iter = iter;
526  };
527 
532  ObjectPointerType Get(void)
533  {
534  return (*m_Iter);
535  }
536 
541  {
542  ++m_Iter;
543  return *this;
544  }
545 
550  {
551  --m_Iter;
552  return *this;
553  }
554 
559  {
560  return (m_Iter != it.m_Iter);
561  }
562 
567  {
568  return (m_Iter == it.m_Iter);
569  }
570 
575  {
576  m_Iter = it.m_Iter;
577  return *this;
578  }
579 
584  {
585  m_Iter = it.m_Iter;
586  return *this;
587  }
588 
593  {
594  m_Iter = it.m_Iter;
595  };
596 
601  {
602  m_Iter = it.m_Iter;
603  };
604 
605  private:
606  // Internal iterator.
607  InternalReverseConstIteratorType m_Iter;
608  };
613  Iterator Begin(void);
614 
619  ConstIterator Begin(void) const;
620 
625  ReverseIterator ReverseBegin(void);
626 
631  ReverseConstIterator ReverseBegin(void) const;
632 
637  Iterator End(void);
638 
643  ConstIterator End(void) const;
644 
649  ReverseIterator ReverseEnd(void);
650 
655  ReverseConstIterator ReverseEnd(void) const;
656 
662  void Erase(Iterator begin, Iterator end);
663 
668  void Erase(Iterator loc);
669 
670 protected:
672  ObjectList();
673 
675  ~ObjectList() override
676  {
677  }
678 
680  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
681 
682 private:
683  ObjectList(const Self&) = delete;
684  void operator=(const Self&) = delete;
686  InternalContainerType m_InternalContainer;
687 };
688 } // end namespace otb
689 
690 #ifndef OTB_MANUAL_INSTANTIATION
691 #include "otbObjectList.hxx"
692 #endif
693 
694 #endif
ReverseIterator of the object list.
ReverseConstIterator & operator--()
ReverseConstIterator(const ReverseConstIterator &it)
InternalContainerType::size_type InternalContainerSizeType
Definition: otbObjectList.h:59
InternalConstIteratorType m_Iter
InternalIteratorType & GetIter(void)
ReverseConstIterator & operator=(const ReverseIterator &it)
ReverseConstIterator(const ReverseIterator &it)
ReverseIterator(InternalReverseIteratorType iter)
InternalIteratorType m_Iter
InternalContainerType m_InternalContainer
InternalContainerType::const_iterator InternalConstIteratorType
ReverseConstIterator of the object list.
Iterator of the object list.
ConstIterator(const ConstIterator &it)
InternalContainerType::const_reverse_iterator InternalReverseConstIteratorType
bool operator!=(const ReverseConstIterator &it)
ObjectPointerType Get(void)
bool operator==(const ConstIterator &it)
InternalContainerType::reverse_iterator InternalReverseIteratorType
ConstIterator & operator=(const ConstIterator &it)
TObject ObjectType
Definition: otbObjectList.h:53
itk::SmartPointer< ObjectType > ObjectPointerType
Definition: otbObjectList.h:57
ReverseConstIterator(InternalReverseConstIteratorType iter)
bool operator!=(const ReverseIterator &it)
Iterator & operator=(const Iterator &it)
ConstIterator(const Iterator &it)
ReverseConstIterator & operator++()
This class is a generic all-purpose wrapping around an std::vector<itk::SmartPointer<ObjectType> >...
Definition: otbObjectList.h:40
ConstIterator(InternalConstIteratorType iter)
Iterator operator+(int i)
InternalContainerType::iterator InternalIteratorType
ObjectPointerType Get(void)
bool operator==(const ReverseIterator &it)
InternalReverseIteratorType m_Iter
ReverseIterator & operator=(const ReverseIterator &it)
Iterator operator-(int i)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
ConstIterator of the object list.
Iterator(const Iterator &it)
itk::SmartPointer< const Self > ConstPointer
Definition: otbObjectList.h:47
InternalReverseIteratorType & GetIter(void)
~ObjectList() override
itk::SmartPointer< Self > Pointer
Definition: otbObjectList.h:46
std::vector< ObjectPointerType > InternalContainerType
Definition: otbObjectList.h:58
ReverseIterator(const ReverseIterator &it)
Iterator operator-=(int i)
void Set(ObjectPointerType element)
bool operator==(const ReverseConstIterator &it)
bool operator==(const Iterator &it)
ReverseConstIterator & operator=(const ReverseConstIterator &it)
ReverseIterator & operator--()
bool operator!=(const Iterator &it)
bool operator!=(const ConstIterator &it)
InternalReverseConstIteratorType m_Iter
ObjectPointerType Get(void)
ReverseIterator & operator++()
Iterator operator+=(int i)
void Set(ObjectPointerType element)
ConstIterator & operator=(const Iterator &it)
Iterator(InternalIteratorType iter)
ObjectList Self
Definition: otbObjectList.h:44
itk::DataObject Superclass
Definition: otbObjectList.h:45