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: 2009-11-22 15:36:04 $
00007   Version:   $Revision: 1.50 $
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 TInputIterator>
00082   MapContainer(TInputIterator first, TInputIterator last):MapType(first, last) {}
00083   template <typename TInputIterator>
00084   MapContainer(TInputIterator first, TInputIterator 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     {
00101     return dynamic_cast<const STLContainerType &>(*this);
00102     }
00103 
00105   class Iterator;
00106   class ConstIterator;
00107   friend class Iterator;
00108   friend class ConstIterator;
00109 
00112   class Iterator {
00113   public:
00114     Iterator() {}
00115     Iterator( const MapIterator& i ): m_Iter(i) {}
00116     
00117     Iterator& operator* ()    { return *this; }
00118     Iterator* operator-> ()   { return this; }
00119     Iterator& operator++ ()   { ++m_Iter; return *this; }
00120     Iterator operator++ (int) { Iterator temp(*this);  ++m_Iter; return temp; }
00121     Iterator& operator-- ()   { --m_Iter; return *this; }
00122     Iterator operator-- (int) { Iterator temp(*this); --m_Iter; return temp; }
00123 
00124     bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
00125     bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
00126     bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
00127     bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
00128  
00130     ElementIdentifier Index(void) const { return m_Iter->first; }
00131 
00133     Element& Value(void) { return m_Iter->second; }
00134   private:
00135     MapIterator      m_Iter;
00136     friend class     ConstIterator;
00137   };
00138 
00141   class ConstIterator {
00142   public:
00143     ConstIterator() {}
00144     ConstIterator(const MapConstIterator& ci): m_Iter(ci) {}
00145     ConstIterator(const Iterator& r) { m_Iter = r.m_Iter; }
00146 
00147     ConstIterator& operator* ()    { return *this; }
00148     ConstIterator* operator-> ()   { return this; }
00149     ConstIterator& operator++ ()   { ++m_Iter; return *this; }
00150     ConstIterator operator++ (int) { ConstIterator temp(*this);  ++m_Iter; return temp; }
00151     ConstIterator& operator-- ()   { --m_Iter; return *this; }
00152     ConstIterator operator-- (int) { ConstIterator temp(*this); --m_Iter; return temp; }
00153 
00154     bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
00155     bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
00156     bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
00157     bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
00158     
00160     ElementIdentifier Index(void) const { return m_Iter->first; }
00161 
00163     const Element& Value(void) const { return m_Iter->second; }
00164 
00165   private:
00166     MapConstIterator m_Iter;
00167     friend class Iterator;
00168   };
00169 
00170   /* Declare the public interface routines. */
00171 
00179   Element& ElementAt(ElementIdentifier);
00180 
00185   const Element& ElementAt(ElementIdentifier) const;
00186 
00194   Element& CreateElementAt(ElementIdentifier);
00195 
00200   Element GetElement(ElementIdentifier) const;
00201 
00206   void SetElement(ElementIdentifier, Element);
00207 
00212   void InsertElement(ElementIdentifier, Element);
00213 
00218   bool IndexExists(ElementIdentifier) const;
00219 
00225   bool GetElementIfIndexExists(ElementIdentifier, Element*) const;
00226 
00232   void CreateIndex(ElementIdentifier);
00233 
00238   void DeleteIndex(ElementIdentifier);
00239 
00243   ConstIterator Begin(void) const;
00244 
00248   ConstIterator End(void) const;  
00249 
00253   Iterator Begin(void);
00254 
00258   Iterator End(void);  
00259 
00263   unsigned long Size(void) const;
00264 
00271   void Reserve(ElementIdentifier);
00272 
00278   void Squeeze(void);
00279 
00284   void Initialize(void);
00285 
00286 };
00287 
00288 } // end namespace itk
00289 
00290 // Define instantiation macro for this template.
00291 #define ITK_TEMPLATE_MapContainer(_, EXPORT, x, y) namespace itk { \
00292   _(2(class EXPORT MapContainer< ITK_TEMPLATE_2 x >)) \
00293   namespace Templates { typedef MapContainer< ITK_TEMPLATE_2 x > \
00294                                                   MapContainer##y; } \
00295   }
00296 
00297 #if ITK_TEMPLATE_EXPLICIT
00298 # include "Templates/itkMapContainer+-.h"
00299 #endif
00300 
00301 #if ITK_TEMPLATE_TXX
00302 # include "itkMapContainer.txx"
00303 #endif
00304 
00305 #endif
00306 

Generated at Mon Jul 12 2010 19:05:10 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000