OpenADFortTk (basic)
src/lib/support/XAIFSymToSymbolMap.cxx
Go to the documentation of this file.
00001 // -*-Mode: C++;-*-
00002 // $Header: /m_home/m_utkej/Argonne/cvs2svn/cvs/OpenADFortTk/src/lib/support/XAIFSymToSymbolMap.cxx,v 1.1 2007-10-08 18:28:33 utke Exp $
00003 
00004 #include "Open64IRInterface/Open64BasicTypes.h"
00005 #include "Open64IRInterface/stab_attr.h"
00006 #include "Open64IRInterface/wn_attr.h"
00007 #include "Diagnostics.h"
00008 #include "XAIFSymToSymbolMap.h"
00009 #include "Symbol.h"
00010 
00011 namespace fortTkSupport{
00012 
00013   XAIFSymToSymbolMap::XAIFSymToSymbolMap()
00014   {
00015   }
00016 
00017   XAIFSymToSymbolMap::~XAIFSymToSymbolMap()
00018   {
00019     // Clear table
00020     StringToSymMapIt it = strToSymMap.begin();
00021     for ( ; it != strToSymMap.end(); ++it) {
00022       delete (*it).second; // Symbol*
00023     }
00024     strToSymMap.clear();
00025   }
00026 
00027   Symbol*
00028   XAIFSymToSymbolMap::Find(const char* scopeid, const char* symid) const
00029   {
00030     std::string key = MakeKey(scopeid, symid);
00031   
00032     StringToSymMapItC it = strToSymMap.find(key);
00033     Symbol* sym = (it == strToSymMap.end()) ? NULL : (*it).second;
00034     return sym;
00035   }
00036 
00037   bool
00038   XAIFSymToSymbolMap::Insert(const char* scopeid, const char* symid, 
00039                              const Symbol* sym_)
00040   {
00041     std::string key = MakeKey(scopeid, symid);
00042     Symbol* sym = const_cast<Symbol*>(sym_); // the map uses non const types
00043   
00044     StringToSymMapVal val = StringToSymMapVal(key, sym);
00045     pair<StringToSymMapIt, bool> p = strToSymMap.insert(val);
00046     return p.second;
00047   }
00048 
00049   std::string 
00050   XAIFSymToSymbolMap::MakeKey(const char* scopeid, const char* symid)
00051   {
00052     // Reserve enough space for null terminators and concatination char
00053     std::string key;
00054     key.reserve(strlen(scopeid) + strlen(symid) + 3);
00055 
00056     key += scopeid;
00057     key += ".";
00058     key += symid;
00059     return key;
00060   }
00061 
00062 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines