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: 2007/01/30 20:56:09 $
00007   Version:   $Revision: 1.48 $
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) {}  
00087 
00089   itkNewMacro(Self);
00090 
00092   typedef MapType STLContainerType;
00093 
00095   STLContainerType & CastToSTLContainer() {
00096      return dynamic_cast<STLContainerType &>(*this); }
00097 
00099   const STLContainerType & CastToSTLConstContainer() const {
00100      return dynamic_cast<const STLContainerType &>(*this); }
00101 
00103   class Iterator;
00104   class ConstIterator;
00105   friend class Iterator;
00106   friend class ConstIterator;
00107 
00109   class Iterator
00110   {
00111   public:
00112     Iterator() {}
00113     Iterator( const MapIterator& i ): m_Iter(i) {}
00114     
00115     Iterator& operator* ()    { return *this; }
00116     Iterator* operator-> ()   { return this; }
00117     Iterator& operator++ ()   { ++m_Iter; return *this; }
00118     Iterator operator++ (int) { Iterator temp(*this);  ++m_Iter; return temp; }
00119     Iterator& operator-- ()   { --m_Iter; return *this; }
00120     Iterator operator-- (int) { Iterator temp(*this); --m_Iter; return temp; }
00121 
00122     bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
00123     bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
00124     bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
00125     bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
00126  
00128     ElementIdentifier Index(void) const { return m_Iter->first; }
00129 
00131     Element& Value(void) { return m_Iter->second; }
00132   private:
00133     MapIterator      m_Iter;
00134     friend class     ConstIterator;
00135   };
00136 
00138   class ConstIterator
00139   {
00140   public:
00141     ConstIterator() {}
00142     ConstIterator(const MapConstIterator& ci): m_Iter(ci) {}
00143     ConstIterator(const Iterator& r) { m_Iter = r.m_Iter; }
00144 
00145     ConstIterator& operator* ()    { return *this; }
00146     ConstIterator* operator-> ()   { return this; }
00147     ConstIterator& operator++ ()   { ++m_Iter; return *this; }
00148     ConstIterator operator++ (int) { ConstIterator temp(*this);  ++m_Iter; return temp; }
00149     ConstIterator& operator-- ()   { --m_Iter; return *this; }
00150     ConstIterator operator-- (int) { ConstIterator temp(*this); --m_Iter; return temp; }
00151 
00152     bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
00153     bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
00154     bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
00155     bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
00156     
00158     ElementIdentifier Index(void) const { return m_Iter->first; }
00159 
00161     const Element& Value(void) const { return m_Iter->second; }
00162 
00163   private:
00164     MapConstIterator m_Iter;
00165     friend class Iterator;
00166   };
00167 
00168   /* Declare the public interface routines. */
00169 
00177   Element& ElementAt(ElementIdentifier);
00178 
00183   const Element& ElementAt(ElementIdentifier) const;
00184 
00192   Element& CreateElementAt(ElementIdentifier);
00193 
00198   Element GetElement(ElementIdentifier) const;
00199 
00204   void SetElement(ElementIdentifier, Element);
00205 
00210   void InsertElement(ElementIdentifier, Element);
00211 
00216   bool IndexExists(ElementIdentifier) const;
00217 
00223   bool GetElementIfIndexExists(ElementIdentifier, Element*) const;
00224 
00230   void CreateIndex(ElementIdentifier);
00231 
00236   void DeleteIndex(ElementIdentifier);
00237 
00241   ConstIterator Begin(void) const;
00242 
00246   ConstIterator End(void) const;  
00247 
00251   Iterator Begin(void);
00252 
00256   Iterator End(void);  
00257 
00261   unsigned long Size(void) const;
00262 
00269   void Reserve(ElementIdentifier);
00270 
00276   void Squeeze(void);
00277 
00282   void Initialize(void);
00283 
00284 };
00285 
00286 } // end namespace itk
00287 
00288 // Define instantiation macro for this template.
00289 #define ITK_TEMPLATE_MapContainer(_, EXPORT, x, y) namespace itk { \
00290   _(2(class EXPORT MapContainer< ITK_TEMPLATE_2 x >)) \
00291   namespace Templates { typedef MapContainer< ITK_TEMPLATE_2 x > \
00292                                                   MapContainer##y; } \
00293   }
00294 
00295 #if ITK_TEMPLATE_EXPLICIT
00296 # include "Templates/itkMapContainer+-.h"
00297 #endif
00298 
00299 #if ITK_TEMPLATE_TXX
00300 # include "itkMapContainer.txx"
00301 #endif
00302 
00303 #endif
00304 

Generated at Wed Nov 5 22:43:21 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000