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: 2002/03/25 18:22:44 $
00007   Version:   $Revision: 1.41 $
00008 
00009   Copyright (c) 2002 Insight 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   private 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   class Iterator;
00092   class ConstIterator;
00093   friend class Iterator;
00094   friend class ConstIterator;
00095   
00097   class Iterator
00098   {
00099   public:
00100     Iterator() {}
00101     Iterator( const MapIterator& i ): m_Iter(i) {}
00102     
00103     Iterator& operator* ()    { return *this; }
00104     Iterator* operator-> ()   { return this; }
00105     Iterator& operator++ ()   { ++m_Iter; return *this; }
00106     Iterator operator++ (int) { Iterator temp(*this);  ++m_Iter; return temp; }
00107     Iterator& operator-- ()   { --m_Iter; return *this; }
00108     Iterator operator-- (int) { Iterator temp(*this); --m_Iter; return temp; }
00109 
00110     bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
00111     bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
00112     bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
00113     bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
00114  
00116     ElementIdentifier Index(void) const { return m_Iter->first; }
00117 
00119     Element& Value(void) { return m_Iter->second; }
00120   private:
00121     MapIterator      m_Iter;
00122     friend class     ConstIterator;
00123   };
00124   
00126   class ConstIterator
00127   {
00128   public:
00129     ConstIterator() {}
00130     ConstIterator(const MapConstIterator& ci): m_Iter(ci) {}
00131     ConstIterator(const Iterator& r) { m_Iter = r.m_Iter; }
00132 
00133     ConstIterator& operator* ()    { return *this; }
00134     ConstIterator* operator-> ()   { return this; }
00135     ConstIterator& operator++ ()   { ++m_Iter; return *this; }
00136     ConstIterator operator++ (int) { ConstIterator temp(*this);  ++m_Iter; return temp; }
00137     ConstIterator& operator-- ()   { --m_Iter; return *this; }
00138     ConstIterator operator-- (int) { ConstIterator temp(*this); --m_Iter; return temp; }
00139 
00140     bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
00141     bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
00142     bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
00143     bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
00144     
00146     ElementIdentifier Index(void) const { return m_Iter->first; }
00147 
00149     const Element& Value(void) const { return m_Iter->second; }
00150 
00151   private:
00152     MapConstIterator m_Iter;
00153     friend class Iterator;
00154   };
00155 
00157   Element& ElementAt(ElementIdentifier);
00158   const Element& ElementAt(ElementIdentifier) const;
00159   Element& CreateElementAt(ElementIdentifier);
00160   Element GetElement(ElementIdentifier) const;
00161   void SetElement(ElementIdentifier, Element);
00162   void InsertElement(ElementIdentifier, Element);
00163   bool IndexExists(ElementIdentifier) const;
00164   bool GetElementIfIndexExists(ElementIdentifier, Element*) const;
00165   void CreateIndex(ElementIdentifier);
00166   void DeleteIndex(ElementIdentifier);
00167   ConstIterator Begin(void) const;
00168   ConstIterator End(void) const;  
00169   Iterator Begin(void);
00170   Iterator End(void);  
00171   unsigned long Size(void) const;
00172   void Reserve(ElementIdentifier);
00173   void Squeeze(void);
00174   void Initialize(void);
00175     
00176 };
00177 
00178 } // end namespace itk
00179 
00180 #ifndef ITK_MANUAL_INSTANTIATION
00181 #include "itkMapContainer.txx"
00182 #endif
00183 
00184 #endif

Generated at Wed Mar 12 01:13:05 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000