Orfeo Toolbox  4.0
otbObjectList.h
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_h
19 #define __otbObjectList_h
20 
21 #include <vector>
22 #include "itkDataObject.h"
23 #include "itkObjectFactory.h"
24 
25 namespace otb
26 {
33 template <class TObject>
34 class ITK_EXPORT ObjectList : public itk::DataObject
35 {
36 public:
38  typedef ObjectList Self;
42 
44  itkTypeMacro(ObjectList, DataObject);
45 
47  itkNewMacro(Self);
48 
50  typedef TObject ObjectType;
52  typedef std::vector<ObjectPointerType> InternalContainerType;
53 
58  void Reserve(unsigned int size);
63  unsigned int Capacity(void) const;
68  unsigned int Size(void) const;
73  void Resize(unsigned int size);
78  void PushBack(ObjectType* element);
82  void PopBack(void);
88  void SetNthElement(unsigned int index, ObjectPointerType element);
89  void SetNthElement(unsigned int index, const ObjectType * element);
95  ObjectPointerType GetNthElement(unsigned int index) const;
100  ObjectPointerType Front(void);
105  ObjectPointerType Back(void);
110  void Erase(unsigned int index);
114  void Clear(void);
115 
116  class ConstIterator;
117  class ReverseIterator;
118  class ReverseConstIterator;
119  class Iterator;
120  friend class Iterator;
121  friend class ConstIterator;
122  friend class ReverseIterator;
123  friend class ReverseConstIterator;
124 
130  Iterator Insert(Iterator position, ObjectPointerType element);
136  ReverseIterator Insert(ReverseIterator position, ObjectPointerType element);
137 
141  class ITK_EXPORT Iterator
142  {
143 public:
144  friend class ObjectList;
145  friend class ConstIterator;
147  typedef typename InternalContainerType::iterator InternalIteratorType;
149  Iterator() {};
152  {
153  m_Iter = iter;
154  };
160  {
161  return (*m_Iter);
162  }
166  void Set(ObjectPointerType element)
167  {
168  (*m_Iter) = element;
169  this->Modified();
170  }
174  Iterator & operator ++()
175  {
176  ++m_Iter;
177  return *this;
178  }
182  Iterator & operator --()
183  {
184  --m_Iter;
185  return *this;
186  }
191  {
192  Iterator lIter(m_Iter + i);
193  return lIter;
194  }
195 
200  {
201  Iterator lIter(m_Iter - i);
202  return lIter;
203  }
207  bool operator !=(const Iterator& it)
208  {
209  return (m_Iter != it.m_Iter);
210  }
214  bool operator ==(const Iterator& it)
215  {
216  return (m_Iter == it.m_Iter);
217  }
221  Iterator & operator =(const Iterator& it)
222  {
223  m_Iter = it.m_Iter;
224  return *this;
225  }
229  Iterator(const Iterator &it)
230  {
231  m_Iter = it.m_Iter;
232  };
233 
237  InternalIteratorType& GetIter(void)
238  {
239  return (m_Iter);
240  }
241 private:
242  // Internal iterator.
244  };
248  class ITK_EXPORT ConstIterator
249  {
250 public:
251  friend class ObjectList;
252  friend class Iterator;
254  typedef typename InternalContainerType::const_iterator InternalConstIteratorType;
259  {
260  m_Iter = iter;
261  };
267  {
268  return (*m_Iter);
269  }
273  ConstIterator & operator ++()
274  {
275  ++m_Iter;
276  return *this;
277  }
281  ConstIterator & operator --()
282  {
283  --m_Iter;
284  return *this;
285  }
289  bool operator !=(const ConstIterator& it)
290  {
291  return (m_Iter != it.m_Iter);
292  }
296  bool operator ==(const ConstIterator& it)
297  {
298  return (m_Iter == it.m_Iter);
299  }
303  ConstIterator & operator =(const ConstIterator& it)
304  {
305  m_Iter = it.m_Iter;
306  return *this;
307  }
311  ConstIterator & operator =(const Iterator& it)
312  {
313  m_Iter = it.m_Iter;
314  return *this;
315  }
320  {
321  m_Iter = it.m_Iter;
322  };
327  {
328  m_Iter = it.m_Iter;
329  };
330 
331 private:
332  // Internal iterator.
333  InternalConstIteratorType m_Iter;
334  };
338  class ITK_EXPORT ReverseIterator
339  {
340 public:
341  friend class ObjectList;
342  friend class Iterator;
343 
344  friend class ReverseConstIterator;
346  typedef typename InternalContainerType::reverse_iterator InternalReverseIteratorType;
351  {
352  m_Iter = iter;
353  };
359  {
360  return (*m_Iter);
361  }
365  void Set(ObjectPointerType element)
366  {
367  (*m_Iter) = element;
368  }
372  ReverseIterator & operator ++()
373  {
374  ++m_Iter;
375  return *this;
376  }
380  ReverseIterator & operator --()
381  {
382  --m_Iter;
383  return *this;
384  }
388  bool operator !=(const ReverseIterator& it)
389  {
390  return (m_Iter != it.m_Iter);
391  }
395  bool operator ==(const ReverseIterator& it)
396  {
397  return (m_Iter == it.m_Iter);
398  }
402  ReverseIterator & operator =(const ReverseIterator& it)
403  {
404  m_Iter = it.m_Iter;
405  return *this;
406  }
411  {
412  m_Iter = it.m_Iter;
413  };
414 
419  {
420  return (m_Iter);
421  }
422 
423 private:
424  // Internal iterator.
426  };
430  class ITK_EXPORT ReverseConstIterator
431  {
432 public:
433  friend class ObjectList;
434  friend class Iterator;
435  friend class ConstIterator;
436  friend class ReverseIterator;
438  typedef typename InternalContainerType::reverse_iterator InternalReverseConstIteratorType;
443  {
444  m_Iter = iter;
445  };
451  {
452  return (*m_Iter);
453  }
457  ReverseConstIterator & operator ++()
458  {
459  ++m_Iter;
460  return *this;
461  }
465  ReverseConstIterator & operator --()
466  {
467  --m_Iter;
468  return *this;
469  }
474  {
475  return (m_Iter != it.m_Iter);
476  }
481  {
482  return (m_Iter == it.m_Iter);
483  }
488  {
489  m_Iter = it.m_Iter;
490  return *this;
491  }
495  ReverseConstIterator & operator =(const ReverseIterator& it)
496  {
497  m_Iter = it.m_Iter;
498  return *this;
499  }
504  {
505  m_Iter = it.m_Iter;
506  };
511  {
512  m_Iter = it.m_Iter;
513  };
514 
515 private:
516  // Internal iterator.
517  InternalReverseConstIteratorType m_Iter;
518  };
523  Iterator Begin(void);
528  ConstIterator Begin(void) const;
533  ReverseIterator ReverseBegin(void);
538  ReverseConstIterator ReverseBegin(void) const;
543  Iterator End(void);
548  ConstIterator End(void) const;
553  ReverseIterator ReverseEnd(void);
558  ReverseConstIterator ReverseEnd(void) const;
564  void Erase(Iterator begin, Iterator end);
565 
570  void Erase(Iterator loc);
571 
572 protected:
574  ObjectList();
578  void PrintSelf(std::ostream& os, itk::Indent indent) const;
579 
580 private:
581  ObjectList(const Self &); //purposely not implemented
582  void operator =(const Self&); //purposely not implemented
585 };
586 } // end namespace otb
587 
588 #ifndef OTB_MANUAL_INSTANTIATION
589 #include "otbObjectList.txx"
590 #endif
591 
592 #endif

Generated at Sat Mar 8 2014 16:11:42 for Orfeo Toolbox with doxygen 1.8.3.1