BaseMap.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef BaseMap_H
00021 #define BaseMap_H
00022
00023
00024
00025 #include <map>
00026
00027
00028
00029 #include "Diagnostics.h"
00030
00031
00032
00033
00034
00035
00036
00037 namespace fortTkSupport {
00038
00039
00040
00041 template <class FromTy, class ToTy>
00042 class BaseMap : public std::map<FromTy, ToTy>
00043 {
00044 public:
00045 BaseMap() { }
00046 virtual ~BaseMap() { }
00047
00048
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 : (*it).second;
00054
00055 if (mustFind && y == 0 ) {
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
00065
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));
00070 return p.second;
00071 }
00072
00073
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 }
00092
00093
00094
00095 #endif