Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/mapmanip is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_mapmanip
0005 #define tools_mapmanip
0006 
0007 #include <map>
0008 
0009 namespace tools {
0010 
0011 template <class K,class V>
0012 inline void safe_clear(std::map<K,V*>& a_m){
0013   // the below takes into account the case in
0014   // which "delete entry" could modify a_m.
0015   typedef typename std::map<K,V*>::iterator it_t;
0016   while(!a_m.empty()) {
0017     it_t it = a_m.begin();
0018     V* entry  = (*it).second;
0019     a_m.erase(it);
0020     delete entry;
0021   }
0022 }
0023 
0024 template <class K,class V>
0025 inline void find_and_remove_value(std::map<K,V*>& a_m,V* a_value){
0026   typedef typename std::map<K,V*>::iterator it_t;
0027   while(true) {
0028     bool found = false;
0029     for(it_t it=a_m.begin();it!=a_m.end();++it) {
0030       if((*it).second==a_value) {
0031         a_m.erase(it);
0032         found = true;
0033         break;
0034       }
0035     }
0036     if(!found) break;
0037   }
0038 }
0039 
0040 template <class K,class V>
0041 inline bool delete_key(std::map<K,V*>& a_m,const K& a_key){
0042   typedef typename std::map<K,V*>::iterator it_t;
0043   it_t it = a_m.find(a_key);
0044   if(it==a_m.end()) return false;
0045   V* obj = (*it).second;
0046   a_m.erase(it);
0047   delete obj;
0048   return true;
0049 }
0050 
0051 }
0052 
0053 #endif