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

itkMapContainer.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkMapContainer.h,v $
00005   Language:  C++
00006   Date:      $Date: 2003/09/10 14:29:14 $
00007   Version:   $Revision: 1.46 $
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 __itkMapContainer_h
00018 #define __itkMapContainer_h
00019 
00020 #include "itkObject.h"
00021 #include "itkObjectFactory.h"
00022 
00023 #include <map>
00024 
00025 namespace itk
00026 {
00027 
00045 template <typename TElementIdentifier, typename TElement>
00046 class MapContainer:
00047   public Object,
00048   public std::map< TElementIdentifier , TElement >
00049 {
00050 public:
00052   typedef MapContainer        Self;
00053   typedef Object  Superclass;
00054   typedef SmartPointer<Self>  Pointer;
00055   typedef SmartPointer<const Self>  ConstPointer;
00056   
00058   itkTypeMacro(MapContainer, Object);
00059 
00061   typedef TElementIdentifier  ElementIdentifier;
00062   typedef TElement            Element;
00063     
00064 private:
00065   MapContainer(const Self&); //purposely not implemented
00066   void operator=(const Self&); //purposely not implemented
00067 
00069   typedef std::map<ElementIdentifier, Element>     MapType;
00070   typedef typename MapType::iterator               MapIterator;
00071   typedef typename MapType::const_iterator         MapConstIterator;
00072   typedef typename MapType::key_compare            MapKeyCompareType;
00073     
00074 public:
00078   MapContainer():MapType() {}
00079   MapContainer(const MapKeyCompareType& comp):MapType(comp) {}
00080   //  MapContainer(const Self& r):MapType(r) {}
00081   template <typename InputIterator>
00082   MapContainer(InputIterator first, InputIterator last):MapType(first, last) {}
00083   template <typename InputIterator>
00084   MapContainer(InputIterator first, InputIterator last,const MapKeyCompareType& comp):
00085     MapType(first, last, comp) {}  
00086   
00088   itkNewMacro(Self);
00089 
00091   typedef MapType STLContainerType;
00092 
00094   STLContainerType & CastToSTLContainer() {
00095      return dynamic_cast<STLContainerType &>(*this); }
00096 
00098   const STLContainerType & CastToSTLConstContainer() const {
00099      return dynamic_cast<const STLContainerType &>(*this); }
00100 
00102   class Iterator;
00103   class ConstIterator;
00104   friend class Iterator;
00105   friend class ConstIterator;
00106   
00108   class Iterator
00109   {
00110   public:
00111     Iterator() {}
00112     Iterator( const MapIterator& i ): m_Iter(i) {}
00113     
00114     Iterator& operator* ()    { return *this; }
00115     Iterator* operator-> ()   { return this; }
00116     Iterator& operator++ ()   { ++m_Iter; return *this; }
00117     Iterator operator++ (int) { Iterator temp(*this);  ++m_Iter; return temp; }
00118     Iterator& operator-- ()   { --m_Iter; return *this; }
00119     Iterator operator-- (int) { Iterator temp(*this); --m_Iter; return temp; }
00120 
00121     bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
00122     bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
00123     bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
00124     bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
00125  
00127     ElementIdentifier Index(void) const { return m_Iter->first; }
00128 
00130     Element& Value(void) { return m_Iter->second; }
00131   private:
00132     MapIterator      m_Iter;
00133     friend class     ConstIterator;
00134   };
00135   
00137   class ConstIterator
00138   {
00139   public:
00140     ConstIterator() {}
00141     ConstIterator(const MapConstIterator& ci): m_Iter(ci) {}
00142     ConstIterator(const Iterator& r) { m_Iter = r.m_Iter; }
00143 
00144     ConstIterator& operator* ()    { return *this; }
00145     ConstIterator* operator-> ()   { return this; }
00146     ConstIterator& operator++ ()   { ++m_Iter; return *this; }
00147     ConstIterator operator++ (int) { ConstIterator temp(*this);  ++m_Iter; return temp; }
00148     ConstIterator& operator-- ()   { --m_Iter; return *this; }
00149     ConstIterator operator-- (int) { ConstIterator temp(*this); --m_Iter; return temp; }
00150 
00151     bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
00152     bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
00153     bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
00154     bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
00155     
00157     ElementIdentifier Index(void) const { return m_Iter->first; }
00158 
00160     const Element& Value(void) const { return m_Iter->second; }
00161 
00162   private:
00163     MapConstIterator m_Iter;
00164     friend class Iterator;
00165   };
00166 
00168   Element& ElementAt(ElementIdentifier);
00169   const Element& ElementAt(ElementIdentifier) const;
00170   Element& CreateElementAt(ElementIdentifier);
00171   Element GetElement(ElementIdentifier) const;
00172   void SetElement(ElementIdentifier, Element);
00173   void InsertElement(ElementIdentifier, Element);
00174   bool IndexExists(ElementIdentifier) const;
00175   bool GetElementIfIndexExists(ElementIdentifier, Element*) const;
00176   void CreateIndex(ElementIdentifier);
00177   void DeleteIndex(ElementIdentifier);
00178   ConstIterator Begin(void) const;
00179   ConstIterator End(void) const;  
00180   Iterator Begin(void);
00181   Iterator End(void);  
00182   unsigned long Size(void) const;
00183   void Reserve(ElementIdentifier);
00184   void Squeeze(void);
00185   void Initialize(void);
00186     
00187 };
00188 
00189 } // end namespace itk
00190 
00191 #ifndef ITK_MANUAL_INSTANTIATION
00192 #include "itkMapContainer.txx"
00193 #endif
00194 
00195 #endif

Generated at Wed May 24 23:37:20 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000