|
OpenADFortTk (basic)
|
00001 // ########################################################## 00002 // # This file is part of OpenADFortTk. # 00003 // # The full COPYRIGHT notice can be found in the top # 00004 // # level directory of the OpenADFortTk source tree. # 00005 // # For more information visit # 00006 // # http://www.mcs.anl.gov/openad # 00007 // ########################################################## 00008 #ifndef BaseMap_H 00009 #define BaseMap_H 00010 00011 #include <map> 00012 00013 #include "Diagnostics.h" 00014 00015 namespace fortTkSupport { 00016 00017 // BaseMap: abstract map routines 00018 // Note: FromTy and ToTy should be pointers (or unsigned integers)! 00019 template <class FromTy, class ToTy> 00020 class BaseMap : public std::map<FromTy, ToTy> 00021 { 00022 public: 00023 BaseMap() { } 00024 virtual ~BaseMap() { } 00025 00026 // Find: Given x, find y if x --> y. 00027 virtual ToTy 00028 Find(const FromTy x, bool mustFind = false) const 00029 { 00030 typename std::map<FromTy, ToTy>::const_iterator it = std::map<FromTy, ToTy>::find(x); 00031 ToTy y = (it == this->end()) ? 0 /*NULL*/ : (*it).second; 00032 00033 if (mustFind && y == 0 /*NULL*/) { 00034 FORTTK_MSG(0,"BaseMap: Could not find entry for key '" << x << "' dumping map"); 00035 Dump(); 00036 FORTTK_DIE("BaseMap: Could not find entry for key '" << x << "'"); 00037 } 00038 00039 return y; 00040 } 00041 00042 // Insert: insert the <x,y> pair in the map and return true; if 00043 // x is already a member, the operation fails and returns false. 00044 virtual bool 00045 Insert(FromTy x, ToTy y) { 00046 pair<typename std::map<FromTy, ToTy>::iterator, bool> p = 00047 this->insert(make_pair(x, y)); // std::map<FromTy, ToTy>::value_type 00048 return p.second; 00049 } 00050 00051 // Dump: Dump that integer values in the map 00052 virtual void Dump(std::ostream& o = std::cerr) const { 00053 o << "{ Map (" << this << ")\n"; 00054 for (typename std::map<FromTy, ToTy>::const_iterator it = this->begin(); 00055 it != this->end(); ++it) { 00056 o << "(" << it->first << " --> " << it->second << ")\n"; 00057 } 00058 o << "}\n"; 00059 o.flush(); 00060 } 00061 00062 virtual void DDump() const { 00063 Dump(std::cerr); 00064 } 00065 00066 protected: 00067 }; 00068 00069 } 00070 00071 #endif