GUIGlObjectStorage Class Reference

#include <GUIGlObjectStorage.h>


Detailed Description

A storage for of displayed objects via their numerical id.

This is a container for GUIGlObject - objects, which may be displayed and due to this may generate tooltips or be grapped in other ways.

As in case of vehicles (other, later implemented objects may have this property, too) they may be deleted by the simulation while being accessed

Definition at line 66 of file GUIGlObjectStorage.h.


Public Member Functions

void clear () throw ()
 Clears this container.
GUIGlObject *const getNetObject () const throw ()
 Returns the network object.
GUIGlObjectgetObjectBlocking (GLuint id) throw ()
 Returns the object from the container locking it.
GLuint getUniqueID () throw ()
 retrieves a unique id for an object to display
 GUIGlObjectStorage () throw ()
 Constructor.
void registerObject (GUIGlObject *object) throw ()
 Registers an object.
bool remove (GLuint id) throw ()
 Removes the named object from this container.
void setNetObject (GUIGlObject *object) throw ()
 Sets the given object as the "network" object.
void unblockObject (GLuint id) throw ()
 Marks an object as unblocked.
 ~GUIGlObjectStorage () throw ()
 Destructor.

Static Public Attributes

static GUIGlObjectStorage gIDStorage
 A single static instance of this class.

Private Types

typedef std::map< size_t,
GUIGlObject * > 
ObjectMap
 Definition of a container from numerical ids to objects.

Private Member Functions

 GUIGlObjectStorage (const GUIGlObjectStorage &s)
 invalidated copy constructor
GUIGlObjectStorageoperator= (const GUIGlObjectStorage &s)
 invalidate assignment operator

Private Attributes

ObjectMap my2Delete
 Objects to delete.
GLuint myAktID
 The next id to give; initially zero, increased by one with each object registration.
ObjectMap myBlocked
 The currently accessed objects.
MFXMutex myLock
 A lock to avoid parallel access on the storages.
ObjectMap myMap
 The known objects which are not accessed currently.
GUIGlObjectmyNetObject
 The network object.

Member Typedef Documentation

typedef std::map<size_t, GUIGlObject *> GUIGlObjectStorage::ObjectMap [private]

Definition of a container from numerical ids to objects.

Definition at line 152 of file GUIGlObjectStorage.h.


Constructor & Destructor Documentation

GUIGlObjectStorage::GUIGlObjectStorage (  )  throw ()

Constructor.

Definition at line 50 of file GUIGlObjectStorage.cpp.

00051         : myAktID(1) {}

GUIGlObjectStorage::~GUIGlObjectStorage (  )  throw ()

Destructor.

Definition at line 54 of file GUIGlObjectStorage.cpp.

00054 {}

GUIGlObjectStorage::GUIGlObjectStorage ( const GUIGlObjectStorage s  )  [private]

invalidated copy constructor


Member Function Documentation

void GUIGlObjectStorage::clear (  )  throw ()

Clears this container.

The objects are not deleted.

Definition at line 118 of file GUIGlObjectStorage.cpp.

References MFXMutex::lock(), myAktID, myLock, myMap, and MFXMutex::unlock().

Referenced by GUINet::~GUINet().

00118                                   {
00119     myLock.lock();
00120     myMap.clear();
00121     myAktID = 0;
00122     myLock.unlock();
00123 }

GUIGlObject* const GUIGlObjectStorage::getNetObject (  )  const throw () [inline]

Returns the network object.

Returns:
The network object

Definition at line 141 of file GUIGlObjectStorage.h.

References myNetObject.

Referenced by GUISUMOAbstractView::openObjectDialog().

00141                                                      {
00142         return myNetObject;
00143     }

GUIGlObject * GUIGlObjectStorage::getObjectBlocking ( GLuint  id  )  throw ()

Returns the object from the container locking it.

The lock prevents the object from being deleted while it is accessed. The object is moved from "myMap" to "myBlocked".

Parameters:
[in] id The id of the object to return
Returns:
The object with the given id or 0 if no such object is known

Definition at line 76 of file GUIGlObjectStorage.cpp.

References MFXMutex::lock(), myBlocked, myLock, myMap, and MFXMutex::unlock().

Referenced by GUISelectedStorage::deselect(), GUISUMOAbstractView::getObjectUnderCursor(), GUISelectedStorage::isSelected(), GUISUMOAbstractView::openObjectDialog(), GUISUMOAbstractView::paintGL(), GUIDialog_GLChosenEditor::rebuildList(), GUISelectedStorage::save(), GUISelectedStorage::SingleTypeSelections::save(), GUISelectedStorage::select(), GUISUMOAbstractView::showToolTipFor(), and GUISelectedStorage::toggleSelection().

00076                                                        {
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 }

GLuint GUIGlObjectStorage::getUniqueID (  )  throw ()

retrieves a unique id for an object to display

Returns:
The next free gl-id

Definition at line 67 of file GUIGlObjectStorage.cpp.

References MFXMutex::lock(), myAktID, myLock, and MFXMutex::unlock().

00067                                         {
00068     myLock.lock();
00069     GLuint ret = myAktID++;
00070     myLock.unlock();
00071     return ret;
00072 }

GUIGlObjectStorage& GUIGlObjectStorage::operator= ( const GUIGlObjectStorage s  )  [private]

invalidate assignment operator

void GUIGlObjectStorage::registerObject ( GUIGlObject object  )  throw ()

Registers an object.

This done within the constructor of the GUIGlObject; The object's "setGLID" method is called giving the next free id.

Parameters:
[in] object The object to register

Definition at line 58 of file GUIGlObjectStorage.cpp.

References MFXMutex::lock(), myAktID, myLock, myMap, and MFXMutex::unlock().

00058                                                               {
00059     myLock.lock();
00060     object->setGlID(myAktID);
00061     myMap[myAktID++] = object;
00062     myLock.unlock();
00063 }

bool GUIGlObjectStorage::remove ( GLuint  id  )  throw ()

Removes the named object from this container.

This function returns true if the object may be deleted; otherwise it's kept in an internal storage (for visualisation etc.) and will be removed by this class

Parameters:
[in] id The id of the object to remove
Returns:
Whether the object could be removed (and may be deleted)

Definition at line 98 of file GUIGlObjectStorage.cpp.

References MFXMutex::lock(), my2Delete, myBlocked, myLock, myMap, and MFXMutex::unlock().

00098                                             {
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 }

void GUIGlObjectStorage::setNetObject ( GUIGlObject object  )  throw () [inline]

Sets the given object as the "network" object.

Parameters:
[in] object The object to set as network object

Definition at line 133 of file GUIGlObjectStorage.h.

References myNetObject.

Referenced by GUINet::GUINet().

00133                                                    {
00134         myNetObject = object;
00135     }

void GUIGlObjectStorage::unblockObject ( GLuint  id  )  throw ()

Marks an object as unblocked.

The object is moved from "myBlocked" to "myMap".

Parameters:
[in] id The id of the object to unblock

Definition at line 127 of file GUIGlObjectStorage.cpp.

References MFXMutex::lock(), myBlocked, myLock, myMap, and MFXMutex::unlock().

Referenced by GUISelectedStorage::deselect(), GUISUMOAbstractView::getObjectUnderCursor(), GUISelectedStorage::isSelected(), GUIDialog_GLChosenEditor::rebuildList(), GUISelectedStorage::save(), GUISelectedStorage::SingleTypeSelections::save(), GUISelectedStorage::select(), GUISUMOAbstractView::showToolTipFor(), and GUISelectedStorage::toggleSelection().

00127                                                    {
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 }


Field Documentation

Objects to delete.

Definition at line 161 of file GUIGlObjectStorage.h.

Referenced by remove().

GLuint GUIGlObjectStorage::myAktID [private]

The next id to give; initially zero, increased by one with each object registration.

Definition at line 164 of file GUIGlObjectStorage.h.

Referenced by clear(), getUniqueID(), and registerObject().

The currently accessed objects.

Definition at line 158 of file GUIGlObjectStorage.h.

Referenced by getObjectBlocking(), remove(), and unblockObject().

A lock to avoid parallel access on the storages.

Definition at line 167 of file GUIGlObjectStorage.h.

Referenced by clear(), getObjectBlocking(), getUniqueID(), registerObject(), remove(), and unblockObject().

The known objects which are not accessed currently.

Definition at line 155 of file GUIGlObjectStorage.h.

Referenced by clear(), getObjectBlocking(), registerObject(), remove(), and unblockObject().

The network object.

Definition at line 170 of file GUIGlObjectStorage.h.

Referenced by getNetObject(), and setNetObject().


The documentation for this class was generated from the following files:

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