GUIGlObjectStorage.cpp

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

Generated on Wed May 5 00:06:29 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6