Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkVectorContainer.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkVectorContainer.h,v $
00005   Language:  C++
00006   Date:      $Date: 2003/09/10 14:29:28 $
00007   Version:   $Revision: 1.55 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkVectorContainer_h
00018 #define __itkVectorContainer_h
00019 
00020 #include "itkObject.h"
00021 #include "itkObjectFactory.h"
00022 
00023 #include <utility>
00024 #include <vector>
00025 
00026 namespace itk
00027 {
00028 
00044 template <
00045   typename TElementIdentifier,
00046   typename TElement
00047   >
00048 class ITK_EXPORT VectorContainer: 
00049   public Object,
00050   public std::vector<TElement>
00051 {
00052 public:
00054   typedef VectorContainer     Self;
00055   typedef Object  Superclass;
00056   typedef SmartPointer<Self>  Pointer;
00057   typedef SmartPointer<const Self>  ConstPointer;
00058   
00060   typedef TElementIdentifier  ElementIdentifier;
00061   typedef TElement            Element;
00062   
00063 private:
00065   typedef std::vector<Element>                VectorType;
00066   typedef typename VectorType::size_type          size_type;  
00067   typedef typename VectorType::iterator           VectorIterator;
00068   typedef typename VectorType::const_iterator     VectorConstIterator;
00069     
00070 protected:
00074   VectorContainer():
00075     Object(), VectorType() {}
00076   VectorContainer(size_type n):
00077     Object(), VectorType(n) {}
00078   VectorContainer(size_type n, const Element& x):
00079     Object(), VectorType(n, x) {}
00080   VectorContainer(const Self& r):
00081     Object(), VectorType(r) {}
00082   template <typename InputIterator>
00083   VectorContainer(InputIterator first, InputIterator last):
00084     Object(), VectorType(first, last) {}
00085   
00086 public:
00087 
00089   typedef VectorType STLContainerType;
00090 
00092   itkNewMacro(Self);
00093   
00095   itkTypeMacro(VectorContainer, Object);
00096 
00098   class Iterator;
00099   class ConstIterator;
00100     
00102   STLContainerType & CastToSTLContainer() {
00103      return dynamic_cast<STLContainerType &>(*this); }
00104 
00106   const STLContainerType & CastToSTLConstContainer() const {
00107      return dynamic_cast<const STLContainerType &>(*this); }
00108 
00110   friend class Iterator;
00111   friend class ConstIterator;
00112   
00115   class Iterator
00116   {
00117   public:
00118     Iterator() {}
00119     Iterator(size_type d, const VectorIterator& i): m_Pos(d), m_Iter(i) {}
00120     
00121     Iterator& operator* ()    { return *this; }
00122     Iterator* operator-> ()   { return this; }
00123     Iterator& operator++ ()   { ++m_Pos; ++m_Iter; return *this; }
00124     Iterator operator++ (int) { Iterator temp(*this); ++m_Pos; ++m_Iter; return temp; }
00125     Iterator& operator-- ()   { --m_Pos; --m_Iter; return *this; }
00126     Iterator operator-- (int) { Iterator temp(*this); --m_Pos; --m_Iter; return temp; }
00127 
00128     bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
00129     bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
00130     bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
00131     bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
00132     
00134     ElementIdentifier Index(void) const { return static_cast<ElementIdentifier>( m_Pos ); }
00135     
00137     Element& Value(void) const { return *m_Iter; }
00138     
00139   private:
00140     size_type m_Pos;
00141     VectorIterator m_Iter;
00142     friend class ConstIterator;
00143   };
00144   
00147   class ConstIterator
00148   {
00149   public:
00150     ConstIterator() {}
00151     ConstIterator(size_type d, const VectorConstIterator& i): m_Pos(d), m_Iter(i) {}
00152     ConstIterator(const Iterator& r) { m_Pos = r.m_Pos; m_Iter = r.m_Iter; }
00153     
00154     ConstIterator& operator* ()    { return *this; }
00155     ConstIterator* operator-> ()   { return this; }
00156     ConstIterator& operator++ ()   { ++m_Pos; ++m_Iter; return *this; }
00157     ConstIterator operator++ (int) { ConstIterator temp(*this); ++m_Pos; ++m_Iter; return temp; }
00158     ConstIterator& operator-- ()   { --m_Pos; --m_Iter; return *this; }
00159     ConstIterator operator-- (int) { ConstIterator temp(*this); --m_Pos; --m_Iter; return temp; }
00160 
00161     ConstIterator& operator = (const Iterator& r) { m_Pos = r.m_Pos; m_Iter = r.m_Iter; return *this; }
00162     
00163     bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
00164     bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
00165     bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
00166     bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
00167     
00169     ElementIdentifier Index(void) const { return static_cast<ElementIdentifier>( m_Pos ); }
00170     
00172     const Element& Value(void) const { return *m_Iter; }
00173     
00174   private:
00175     size_type m_Pos;
00176     VectorConstIterator m_Iter;
00177     friend class Iterator;
00178   };  
00179   
00181   Element& ElementAt(ElementIdentifier);
00182   const Element& ElementAt(ElementIdentifier) const;
00183   Element& CreateElementAt(ElementIdentifier);
00184   Element GetElement(ElementIdentifier) const;
00185   void SetElement(ElementIdentifier, Element);
00186   void InsertElement(ElementIdentifier, Element);
00187   bool IndexExists(ElementIdentifier) const;
00188   bool GetElementIfIndexExists(ElementIdentifier, Element*) const;
00189   void CreateIndex(ElementIdentifier);
00190   void DeleteIndex(ElementIdentifier);
00191   ConstIterator Begin(void) const;
00192   ConstIterator End(void) const;  
00193   Iterator Begin(void);
00194   Iterator End(void);  
00195   unsigned long Size(void) const;
00196   void Reserve(ElementIdentifier);
00197   void Squeeze(void);
00198   void Initialize(void);
00199     
00200 };
00201 
00202 } // end namespace itk
00203   
00204 #ifndef ITK_MANUAL_INSTANTIATION
00205 #include "itkVectorContainer.txx"
00206 #endif
00207 
00208 #endif

Generated at Thu May 25 00:11:28 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000