BaseMap.h

Go to the documentation of this file.
00001 // -*-Mode: C++;-*-
00002 // $Header: /Volumes/cvsrep/developer/OpenADFortTk/src/lib/support/BaseMap.h,v 1.4 2004/12/08 22:09:28 eraxxon Exp $
00003 
00004 // * BeginCopyright *********************************************************
00005 // *********************************************************** EndCopyright *
00006 
00007 //***************************************************************************
00008 //
00009 // File:
00010 //   $Source: /Volumes/cvsrep/developer/OpenADFortTk/src/lib/support/BaseMap.h,v $
00011 //
00012 // Purpose:
00013 //   [The purpose of this file]
00014 //
00015 // Description:
00016 //   [The set of functions, macros, etc. defined in the file]
00017 //
00018 //***************************************************************************
00019 
00020 #ifndef BaseMap_H 
00021 #define BaseMap_H
00022 
00023 //************************** System Include Files ***************************
00024 
00025 #include <map>
00026 
00027 //*************************** User Include Files ****************************
00028 
00029 #include "Diagnostics.h"
00030 
00031 //************************** Forward Declarations ***************************
00032 
00033 //***************************************************************************
00034 // BaseMap
00035 //***************************************************************************
00036 
00037 namespace fortTkSupport {
00038 
00039 // BaseMap: abstract map routines
00040 // Note: FromTy and ToTy should be pointers (or unsigned integers)!
00041 template <class FromTy, class ToTy>
00042 class BaseMap : public std::map<FromTy, ToTy>
00043 {
00044 public:
00045   BaseMap() { }
00046   virtual ~BaseMap() { }
00047   
00048   // Find: Given x, find y if x --> y.
00049   virtual ToTy 
00050   Find(const FromTy x, bool mustFind = false) const
00051   {
00052     typename std::map<FromTy, ToTy>::const_iterator it = std::map<FromTy, ToTy>::find(x);
00053     ToTy y = (it == this->end()) ? 0 /*NULL*/ : (*it).second;
00054     
00055     if (mustFind && y == 0 /*NULL*/) {
00056       FORTTK_MSG(0,"BaseMap: Could not find entry for key '" << x << "' dumping map");
00057       Dump();
00058       FORTTK_DIE("BaseMap: Could not find entry for key '" << x << "'");
00059     }
00060     
00061     return y;
00062   }
00063   
00064   // Insert: insert the <x,y> pair in the map and return true; if
00065   // x is already a member, the operation fails and returns false.
00066   virtual bool 
00067   Insert(FromTy x, ToTy y) {
00068     pair<typename std::map<FromTy, ToTy>::iterator, bool> p = 
00069       insert(make_pair(x, y)); // std::map<FromTy, ToTy>::value_type
00070     return p.second;
00071   }
00072   
00073   // Dump: Dump that integer values in the map
00074   virtual void Dump(std::ostream& o = std::cerr) const {
00075     o << "{ Map (" << this << ")\n";
00076     for (typename std::map<FromTy, ToTy>::const_iterator it = this->begin(); 
00077          it != this->end(); ++it) {
00078       o << "(" << it->first << " --> " << it->second << ")\n";
00079     }
00080     o << "}\n";
00081     o.flush();
00082   }
00083   
00084   virtual void DDump() const {
00085     Dump(std::cerr);
00086   }
00087 
00088 protected:
00089 };
00090 
00091 } // FortTk
00092 
00093 //***************************************************************************
00094 
00095 #endif 

Generated on Fri Jul 24 04:29:02 2009 for OpenADFortTk (extended to Open64) by  doxygen 1.5.7.1