SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // A storage for displayed objects via their numerical id 00010 /****************************************************************************/ 00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00013 /****************************************************************************/ 00014 // 00015 // This file is part of SUMO. 00016 // SUMO is free software: you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation, either version 3 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 00023 00024 // =========================================================================== 00025 // included modules 00026 // =========================================================================== 00027 #ifdef _MSC_VER 00028 #include <windows_config.h> 00029 #else 00030 #include <config.h> 00031 #endif 00032 00033 #include <map> 00034 #include <iostream> 00035 #include <cassert> 00036 #include <utils/foxtools/MFXMutex.h> 00037 #include "GUIGlObject.h" 00038 #include "GUIGlObjectStorage.h" 00039 00040 #ifdef CHECK_MEMORY_LEAKS 00041 #include <foreign/nvwa/debug_new.h> 00042 #endif // CHECK_MEMORY_LEAKS 00043 00044 00045 // =========================================================================== 00046 // static variables (instances in this case) 00047 // =========================================================================== 00048 GUIGlObjectStorage GUIGlObjectStorage::gIDStorage; 00049 00050 00051 // =========================================================================== 00052 // method definitions 00053 // =========================================================================== 00054 GUIGlObjectStorage::GUIGlObjectStorage() 00055 : myAktID(0) {} 00056 00057 00058 GUIGlObjectStorage::~GUIGlObjectStorage() {} 00059 00060 00061 GUIGlID 00062 GUIGlObjectStorage::registerObject(GUIGlObject* object, const std::string& fullName) { 00063 myLock.lock(); 00064 GUIGlID id = myAktID++; 00065 myMap[id] = object; 00066 myFullNameMap[fullName] = object; 00067 myLock.unlock(); 00068 return id; 00069 } 00070 00071 00072 GUIGlObject* 00073 GUIGlObjectStorage::getObjectBlocking(GUIGlID id) { 00074 myLock.lock(); 00075 ObjectMap::iterator i = myMap.find(id); 00076 if (i == myMap.end()) { 00077 i = myBlocked.find(id); 00078 if (i != myBlocked.end()) { 00079 GUIGlObject* o = (*i).second; 00080 myLock.unlock(); 00081 return o; 00082 } 00083 myLock.unlock(); 00084 return 0; 00085 } 00086 GUIGlObject* o = (*i).second; 00087 myMap.erase(id); 00088 myBlocked[id] = o; 00089 myLock.unlock(); 00090 return o; 00091 } 00092 00093 00094 GUIGlObject* 00095 GUIGlObjectStorage::getObjectBlocking(const std::string& fullName) { 00096 myLock.lock(); 00097 if (myFullNameMap.count(fullName)) { 00098 GUIGlID id = myFullNameMap[fullName]->getGlID(); 00099 myLock.unlock(); 00100 return getObjectBlocking(id); 00101 } else { 00102 myLock.unlock(); 00103 return 0; 00104 } 00105 } 00106 00107 00108 bool 00109 GUIGlObjectStorage::remove(GUIGlID id) { 00110 myLock.lock(); 00111 ObjectMap::iterator i = myMap.find(id); 00112 if (i == myMap.end()) { 00113 i = myBlocked.find(id); 00114 assert(i != myBlocked.end()); 00115 GUIGlObject* o = (*i).second; 00116 myFullNameMap.erase(o->getFullName()); 00117 myBlocked.erase(id); 00118 my2Delete[id] = o; 00119 myLock.unlock(); 00120 return false; 00121 } else { 00122 myFullNameMap.erase(i->second->getFullName()); 00123 myMap.erase(id); 00124 myLock.unlock(); 00125 return true; 00126 } 00127 } 00128 00129 00130 void 00131 GUIGlObjectStorage::clear() { 00132 myLock.lock(); 00133 myMap.clear(); 00134 myAktID = 0; 00135 myLock.unlock(); 00136 } 00137 00138 00139 void 00140 GUIGlObjectStorage::unblockObject(GUIGlID id) { 00141 myLock.lock(); 00142 ObjectMap::iterator i = myBlocked.find(id); 00143 if (i == myBlocked.end()) { 00144 myLock.unlock(); 00145 return; 00146 } 00147 GUIGlObject* o = (*i).second; 00148 myBlocked.erase(id); 00149 myMap[id] = o; 00150 myLock.unlock(); 00151 } 00152 00153 00154 std::set<GUIGlID> 00155 GUIGlObjectStorage::getAllIDs() const { 00156 std::set<GUIGlID> result; 00157 for (ObjectMap::const_iterator it = myMap.begin(); it != myMap.end(); it++) { 00158 result.insert(it->first); 00159 } 00160 return result; 00161 } 00162 /****************************************************************************/ 00163