ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkOneWayEquivalencyTable.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkOneWayEquivalencyTable_h
00019 #define __itkOneWayEquivalencyTable_h
00020 
00021 
00022 #include "itkProcessObject.h"
00023 #include "itksys/hash_map.hxx"
00024 
00025 namespace itk
00026 {
00045 class ITK_EXPORT OneWayEquivalencyTable:public DataObject
00046 {
00047 public:
00049   typedef OneWayEquivalencyTable     Self;
00050   typedef DataObject                 Superclass;
00051   typedef SmartPointer< Self >       Pointer;
00052   typedef SmartPointer< const Self > ConstPointer;
00053   itkNewMacro(Self);
00054   itkTypeMacro(OneWayEquivalencyTable, DataObject);
00056 
00058   typedef itksys::hash_map< unsigned long, unsigned long,
00059                             itksys::hash< unsigned long > > HashTableType;
00060 
00061   typedef HashTableType::iterator       Iterator;
00062   typedef HashTableType::const_iterator ConstIterator;
00063   typedef HashTableType::value_type     ValueType;
00064 
00068   void Flatten();
00069 
00077   bool Add(unsigned long a, unsigned long b);
00078 
00082   unsigned long Lookup(const unsigned long a) const
00083   {
00084     ConstIterator result = m_HashMap.find(a);
00085 
00086     if ( result == m_HashMap.end() ) { return a; }
00087     else { return ( *result ).second; }
00088   }
00089 
00094   unsigned long RecursiveLookup(const unsigned long a) const;
00095 
00098   bool IsEntry(const unsigned long a) const
00099   {
00100     if ( m_HashMap.find(a) == m_HashMap.end() ) { return false; }
00101     else { return true; }
00102   }
00104 
00106   void Erase(const unsigned long a)
00107   {  m_HashMap.erase(a); }
00108 
00110   void Clear()
00111   {      m_HashMap.clear();    }
00112 
00114   bool Empty() const
00115   {      return m_HashMap.empty();    }
00116 
00119   Iterator Begin() { return m_HashMap.begin(); }
00120 
00123   Iterator End()   { return m_HashMap.end();   }
00124 
00126   //  void PrintHashTable();
00127 protected:
00128   OneWayEquivalencyTable()  {}
00129   virtual ~OneWayEquivalencyTable() {}
00130   OneWayEquivalencyTable(const Self &); // purposely not implemented
00131   void operator=(const Self &);         // purposely not implemented
00133 
00134   void PrintSelf(std::ostream & os, Indent indent) const;
00135 
00136   HashTableType m_HashMap;
00137 };
00138 } // end namespace itk
00139 
00140 #endif
00141