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: 2009-03-03 15:11:39 $
00007   Version:   $Revision: 1.59 $
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 TInputIterator>
00083   VectorContainer(TInputIterator first, TInputIterator last):
00084     Object(), VectorType(first, last) {}
00086 
00087 public:
00088 
00090   typedef VectorType                     STLContainerType;
00091   typedef typename VectorType::size_type VectorContainerSizeType;
00092 
00094   itkNewMacro(Self);
00095 
00097   itkTypeMacro(VectorContainer, Object);
00098 
00100   class Iterator;
00101   class ConstIterator;
00102 
00104   STLContainerType & CastToSTLContainer() {
00105      return dynamic_cast<STLContainerType &>(*this); }
00106 
00108   const STLContainerType & CastToSTLConstContainer() const {
00109      return dynamic_cast<const STLContainerType &>(*this); }
00110 
00112   friend class Iterator;
00113   friend class ConstIterator;
00114 
00118   class Iterator
00119     {
00120     public:
00121       Iterator() {}
00122       Iterator(size_type d, const VectorIterator& i): m_Pos(d), m_Iter(i) {}
00123       Iterator& operator* ()    { return *this; }
00124       Iterator* operator-> ()   { return this; }
00125       Iterator& operator++ ()   { ++m_Pos; ++m_Iter; return *this; }
00126       Iterator operator++ (int) { Iterator temp(*this); ++m_Pos; ++m_Iter; return temp; }
00127       Iterator& operator-- ()   { --m_Pos; --m_Iter; return *this; }
00128       Iterator operator-- (int) { Iterator temp(*this); --m_Pos; --m_Iter; return temp; }
00129       bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
00130       bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
00131       bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
00132       bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
00133       
00135       ElementIdentifier Index(void) const { return static_cast<ElementIdentifier>( m_Pos ); }
00136 
00138       Element& Value(void) const { return *m_Iter; }
00139 
00140     private:
00141       size_type m_Pos;
00142       VectorIterator m_Iter;
00143       friend class ConstIterator;
00144   };
00145   
00149   class ConstIterator
00150     {
00151     public:
00152       ConstIterator() {}
00153       ConstIterator(size_type d, const VectorConstIterator& i): m_Pos(d), m_Iter(i) {}
00154       ConstIterator(const Iterator& r) { m_Pos = r.m_Pos; m_Iter = r.m_Iter; }
00155       ConstIterator& operator* ()    { return *this; }
00156       ConstIterator* operator-> ()   { return this; }
00157       ConstIterator& operator++ ()   { ++m_Pos; ++m_Iter; return *this; }
00158       ConstIterator operator++ (int) { ConstIterator temp(*this); ++m_Pos; ++m_Iter; return temp; }
00159       ConstIterator& operator-- ()   { --m_Pos; --m_Iter; return *this; }
00160       ConstIterator operator-- (int) { ConstIterator temp(*this); --m_Pos; --m_Iter; return temp; }
00161       ConstIterator& operator = (const Iterator& r) { m_Pos = r.m_Pos; m_Iter = r.m_Iter; return *this; }
00162       bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
00163       bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
00164       bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
00165       bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
00166       
00168       ElementIdentifier Index(void) const { return static_cast<ElementIdentifier>( m_Pos ); }
00169 
00171       const Element& Value(void) const { return *m_Iter; }
00172 
00173     private:
00174       size_type m_Pos;
00175       VectorConstIterator m_Iter;
00176       friend class Iterator;
00177   };
00178   
00179   /* Declare the public interface routines. */
00180   
00189   Element& ElementAt(ElementIdentifier);
00190 
00197   const Element& ElementAt(ElementIdentifier) const;
00198 
00207   Element& CreateElementAt(ElementIdentifier);
00208 
00213   Element GetElement(ElementIdentifier) const;
00214 
00219   void SetElement(ElementIdentifier, Element );
00220 
00226   void InsertElement(ElementIdentifier, Element );
00227 
00232   bool IndexExists(ElementIdentifier) const;
00233 
00239   bool GetElementIfIndexExists(ElementIdentifier, Element*) const;
00240 
00246   void CreateIndex(ElementIdentifier);
00247 
00253   void DeleteIndex(ElementIdentifier);
00254 
00258   ConstIterator Begin(void) const;
00259 
00263   ConstIterator End(void) const;  
00264 
00268   Iterator Begin(void);
00269 
00273   Iterator End(void);  
00274 
00278   unsigned long Size(void) const;
00279 
00289   void Reserve( ElementIdentifier );
00290 
00297   void Squeeze(void);
00298 
00302   void Initialize(void);
00303 
00304 };
00305 
00306 } // end namespace itk
00307 
00308 // Define instantiation macro for this template.
00309 #define ITK_TEMPLATE_VectorContainer(_, EXPORT, x, y) namespace itk { \
00310   _(2(class EXPORT VectorContainer< ITK_TEMPLATE_2 x >)) \
00311   namespace Templates { typedef VectorContainer< ITK_TEMPLATE_2 x > \
00312                                                   VectorContainer##y; } \
00313   }
00314 
00315 #if ITK_TEMPLATE_EXPLICIT
00316 # include "Templates/itkVectorContainer+-.h"
00317 #endif
00318 
00319 #if ITK_TEMPLATE_TXX
00320 # include "itkVectorContainer.txx"
00321 #endif
00322 
00323 #endif
00324 

Generated at Thu May 28 11:54:15 2009 for ITK by doxygen 1.5.5 written by Dimitri van Heesch, © 1997-2000