#include <NamedObjectCont.h>
An associative storage (map) for objects (pointers to them to be exact), which do have a name. In order to get the stored objects as a list, each insertion/deletion sets the internal state value "myHaveChanged" to true, indicating the list must be rebuild.
Definition at line 51 of file NamedObjectCont.h.
Public Member Functions | |
| virtual bool | add (const std::string &id, T item) throw () |
| Adds an item. | |
| const std::vector< T > & | buildAndGetStaticVector () const throw () |
| void | clear () throw () |
| Removes all items from the container (deletes them, too). | |
| bool | erase (const std::string &id) throw () |
| Removes the named item from the container. | |
| T | get (const std::string &id) const throw () |
| Retrieves an item. | |
| const std::map< std::string, T > & | getMyMap () const throw () |
| std::vector< T > | getTempVector () const throw () |
| void | insertIDs (std::vector< std::string > &into) const throw () |
| NamedObjectCont () throw () | |
| Constructor. | |
| virtual bool | remove (const std::string &id) throw () |
| Removes an item. | |
| unsigned int | size () const throw () |
| Returns the number of items within the container. | |
| virtual | ~NamedObjectCont () throw () |
| Destructor. | |
Private Types | |
| typedef std::map< std::string, T > | IDMap |
| Definition of the key to pointer map type. | |
| typedef IDMap::iterator | myContIt |
| Definition of the container type iterator. | |
| typedef std::vector< T > | ObjectVector |
| Definition objects vector. | |
Private Attributes | |
| bool | myHaveChanged |
| Information whether the vector is out of sync with the map. | |
| IDMap | myMap |
| The map from key to object. | |
| ObjectVector | myVector |
| The stored vector of all known items. | |
typedef std::map< std::string, T > NamedObjectCont< T >::IDMap [private] |
typedef IDMap::iterator NamedObjectCont< T >::myContIt [private] |
typedef std::vector<T> NamedObjectCont< T >::ObjectVector [private] |
| NamedObjectCont< T >::NamedObjectCont | ( | ) | throw () [inline] |
| virtual NamedObjectCont< T >::~NamedObjectCont | ( | ) | throw () [inline, virtual] |
Destructor.
Definition at line 58 of file NamedObjectCont.h.
00058 { 00059 for (typename IDMap::iterator i=myMap.begin(); i!=myMap.end(); i++) { 00060 delete(*i).second; 00061 } 00062 }
| virtual bool NamedObjectCont< T >::add | ( | const std::string & | id, | |
| T | item | |||
| ) | throw () [inline, virtual] |
Adds an item.
If another item with the same name is already known, false is reported and the item is not added.
| [in] | id | The id of the item to add |
| [in] | item | The item to add |
Reimplemented in ROVehicleCont.
Definition at line 74 of file NamedObjectCont.h.
Referenced by MSDetectorControl::add(), RONet::addEdge(), RONet::addNode(), RONet::addRouteDef(), RONet::addVehicleType(), ODDistrictHandler::closeDistrict(), and NLJunctionControlBuilder::closeJunction().
00074 { 00075 if (myMap.find(id)!=myMap.end()) { 00076 return false; 00077 } 00078 myMap.insert(std::make_pair(id, item)); 00079 myHaveChanged = true; 00080 return true; 00081 }
| const std::vector<T>& NamedObjectCont< T >::buildAndGetStaticVector | ( | ) | const throw () [inline] |
Definition at line 173 of file NamedObjectCont.h.
Referenced by MSDetectorControl::updateDetectors().
00173 { 00174 if (myHaveChanged) { 00175 myVector.clear(); 00176 typename IDMap::const_iterator i; 00177 for (i=myMap.begin(); i!=myMap.end(); ++i) { 00178 myVector.push_back((*i).second); 00179 } 00180 myHaveChanged = false; 00181 } 00182 return myVector; 00183 }
| void NamedObjectCont< T >::clear | ( | ) | throw () [inline] |
Removes all items from the container (deletes them, too).
Reimplemented in ROVehicleCont.
Definition at line 117 of file NamedObjectCont.h.
Referenced by ROVehicleCont::clear(), MSDetectorControl::~MSDetectorControl(), and RONet::~RONet().
00117 { 00118 for (typename IDMap::iterator i=myMap.begin(); i!=myMap.end(); i++) { 00119 delete(*i).second; 00120 } 00121 myMap.clear(); 00122 myVector.clear(); 00123 myHaveChanged = true; 00124 }
| bool NamedObjectCont< T >::erase | ( | const std::string & | id | ) | throw () [inline] |
Removes the named item from the container.
If the named object exists, it is deleted, the key is removed from the map, and true is returned. If the id was not known, false is returned.
| [in] | id | The id of the item to delete |
Reimplemented in ROVehicleCont.
Definition at line 145 of file NamedObjectCont.h.
00145 { 00146 typename IDMap::iterator i=myMap.find(id); 00147 if (i==myMap.end()) { 00148 return false; 00149 } 00150 T o = (*i).second; 00151 myMap.erase(i); 00152 // and from the vector 00153 typename ObjectVector::iterator i2 = 00154 find(myVector.begin(), myVector.end(), o); 00155 myHaveChanged = true; 00156 if (i2!=myVector.end()) { 00157 myVector.erase(i2); 00158 } 00159 delete o; 00160 return true; 00161 }
| T NamedObjectCont< T >::get | ( | const std::string & | id | ) | const throw () [inline] |
Retrieves an item.
Returns 0 when no item with the given id is stored within the container
| [in] | id | The id of the item to retrieve |
Definition at line 107 of file NamedObjectCont.h.
Referenced by ODMatrix::add(), RONet::getEdge(), GUINet::getJunctionPosition(), RONet::getNode(), RONet::getRouteDef(), RONet::getVehicleTypeSecure(), traci::TraCIServer::handleTrafficLightDomain(), and TraCIServerAPI_Junction::processGet().
00107 { 00108 typename std::map<std::string, T>::const_iterator i = myMap.find(id); 00109 if (i==myMap.end()) { 00110 return 0; 00111 } 00112 return (*i).second; 00113 }
| const std::map<std::string, T>& NamedObjectCont< T >::getMyMap | ( | ) | const throw () [inline] |
Definition at line 218 of file NamedObjectCont.h.
Referenced by RONet::checkSourceAndDestinations(), RONet::getEdgeMap(), and GUINet::initGUIStructures().
00218 { 00219 return myMap; 00220 }
| std::vector<T> NamedObjectCont< T >::getTempVector | ( | ) | const throw () [inline] |
Definition at line 193 of file NamedObjectCont.h.
00193 { 00194 std::vector<T> ret; 00195 typename IDMap::const_iterator i; 00196 for (i=myMap.begin(); i!=myMap.end(); ++i) { 00197 ret.push_back((*i).second); 00198 } 00199 return ret; 00200 }
| void NamedObjectCont< T >::insertIDs | ( | std::vector< std::string > & | into | ) | const throw () [inline] |
Definition at line 206 of file NamedObjectCont.h.
Referenced by TraCIServerAPI_Junction::processGet().
00206 { 00207 typename IDMap::const_iterator i; 00208 for (i=myMap.begin(); i!=myMap.end(); ++i) { 00209 into.push_back((*i).first); 00210 } 00211 }
| virtual bool NamedObjectCont< T >::remove | ( | const std::string & | id | ) | throw () [inline, virtual] |
Removes an item.
| [in] | id | The id of the item to remove |
Definition at line 88 of file NamedObjectCont.h.
00088 { 00089 if (myMap.find(id)==myMap.end()) { 00090 return false; 00091 } 00092 typename std::map<std::string, T>::iterator i = myMap.find(id); 00093 delete i->second; 00094 myMap.erase(i); 00095 myHaveChanged = true; 00096 return true; 00097 }
| unsigned int NamedObjectCont< T >::size | ( | ) | const throw () [inline] |
Returns the number of items within the container.
Definition at line 131 of file NamedObjectCont.h.
Referenced by RONet::furtherStored(), RONet::getEdgeNo(), GUINet::initGUIStructures(), main(), and RONet::saveAndRemoveRoutesUntil().
00131 { 00132 return (unsigned int) myMap.size(); 00133 }
bool NamedObjectCont< T >::myHaveChanged [mutable, private] |
Information whether the vector is out of sync with the map.
Definition at line 240 of file NamedObjectCont.h.
Referenced by NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::add(), NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::buildAndGetStaticVector(), NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::clear(), NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::erase(), and NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::remove().
IDMap NamedObjectCont< T >::myMap [private] |
The map from key to object.
Definition at line 231 of file NamedObjectCont.h.
Referenced by NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::add(), NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::buildAndGetStaticVector(), NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::clear(), NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::erase(), NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::get(), NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::getMyMap(), NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::getTempVector(), NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::insertIDs(), NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::remove(), NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::size(), and NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::~NamedObjectCont().
ObjectVector NamedObjectCont< T >::myVector [mutable, private] |
The stored vector of all known items.
Definition at line 237 of file NamedObjectCont.h.
Referenced by NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::buildAndGetStaticVector(), NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::clear(), and NamedObjectCont< MS_E2_ZS_CollectorOverLanes * >::erase().
1.5.6