#include <ROVehicleCont.h>

A map of vehicle-ids to the vehicles themselves. Besides the functionality implemented in NamedObjectCont, this class stores vehicles sorted by their departure time.
Definition at line 52 of file ROVehicleCont.h.
Public Member Functions | |
| virtual bool | add (const std::string &id, ROVehicle *item) throw () |
| Adds a vehicle to the container. | |
| const std::vector< ROVehicle * > & | buildAndGetStaticVector () const throw () |
| void | clear () throw () |
| Deletes all vehicles stored; clears the lists. | |
| bool | erase (const std::string &id) throw () |
| Tries to remove (and delete) the named vehicle. | |
| ROVehicle * | get (const std::string &id) const throw () |
| Retrieves an item. | |
| const std::map< std::string, ROVehicle * > & | getMyMap () const throw () |
| std::vector< ROVehicle * > | getTempVector () const throw () |
| const ROVehicle *const | getTopVehicle () const throw () |
| Returns the vehicle that departs most early. | |
| void | insertIDs (std::vector< std::string > &into) const throw () |
| virtual bool | remove (const std::string &id) throw () |
| Removes an item. | |
| ROVehicleCont () throw () | |
| Constructor. | |
| unsigned int | size () const throw () |
| Returns the number of items within the container. | |
| ~ROVehicleCont () throw () | |
| Destructor. | |
Private Member Functions | |
| ROVehicleCont & | operator= (const ROVehicleCont &src) |
| Invalidated assignment operator. | |
| void | rebuildSorted () throw () |
| Rebuild the internal, sorted list. | |
| ROVehicleCont (const ROVehicleCont &src) | |
| Invalidated copy constructor. | |
Private Attributes | |
| std::priority_queue< ROVehicle *, std::vector< ROVehicle * > , ROVehicleByDepartureComperator > | mySorted |
| The sorted vehicle list. | |
| ROVehicleCont::ROVehicleCont | ( | ) | throw () |
| ROVehicleCont::~ROVehicleCont | ( | ) | throw () |
| ROVehicleCont::ROVehicleCont | ( | const ROVehicleCont & | src | ) | [private] |
Invalidated copy constructor.
Adds a vehicle to the container.
Tries to add the vehicle to the container using NamedObjectCont::add. If this succeeds, the vehicle is also added to the internal sorted list of vehicles.
Returns the value from NamedObjectCont::add.
| [in] | id | The id of the vehicle to add |
| [in] | item | The vehicle to add |
Reimplemented from NamedObjectCont< ROVehicle * >.
Definition at line 61 of file ROVehicleCont.cpp.
References mySorted.
Referenced by RONet::addVehicle().
00061 { 00062 if (NamedObjectCont<ROVehicle*>::add(id, item)) { 00063 mySorted.push(item); 00064 return true; 00065 } 00066 return false; 00067 }
| const std::vector<ROVehicle * >& NamedObjectCont< ROVehicle * >::buildAndGetStaticVector | ( | ) | const throw () [inline, inherited] |
Definition at line 173 of file NamedObjectCont.h.
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 ROVehicleCont::clear | ( | ) | throw () |
Deletes all vehicles stored; clears the lists.
Calls NamedObjectCont::clear and replaces the internal, sorted list by an empty one.
Reimplemented from NamedObjectCont< ROVehicle * >.
Definition at line 71 of file ROVehicleCont.cpp.
References NamedObjectCont< T >::clear(), and mySorted.
Referenced by RONet::~RONet().
00071 { 00072 mySorted = std::priority_queue<ROVehicle*, std::vector<ROVehicle*>, ROVehicleByDepartureComperator>(); 00073 NamedObjectCont<ROVehicle*>::clear(); 00074 }
| bool ROVehicleCont::erase | ( | const std::string & | id | ) | throw () |
Tries to remove (and delete) the named vehicle.
Calls NamedObjectCont::erase. If this succeeds, the vehicle is removed from the internal sorted list. This method takes care whether the vehicle to remove is the top-most one (the one with the earliest depart time). If not, the internal list is rebuild.
| [in] | id | The id of the vehicle to remove |
Reimplemented from NamedObjectCont< ROVehicle * >.
Definition at line 78 of file ROVehicleCont.cpp.
References ROVehicle::getID(), getTopVehicle(), mySorted, and rebuildSorted().
Referenced by RONet::saveAndRemoveRoutesUntil().
00078 { 00079 const ROVehicle * const topVeh = getTopVehicle(); 00080 bool wasTop = topVeh!=0&&topVeh->getID()==id; 00081 if (!NamedObjectCont<ROVehicle*>::erase(id)) { 00082 return false; 00083 } 00084 if (wasTop) { 00085 mySorted.pop(); 00086 } else { 00087 rebuildSorted(); 00088 } 00089 return true; 00090 }
| ROVehicle * NamedObjectCont< ROVehicle * >::get | ( | const std::string & | id | ) | const throw () [inline, inherited] |
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.
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, ROVehicle * >& NamedObjectCont< ROVehicle * >::getMyMap | ( | ) | const throw () [inline, inherited] |
Definition at line 218 of file NamedObjectCont.h.
Referenced by rebuildSorted().
00218 { 00219 return myMap; 00220 }
| std::vector<ROVehicle * > NamedObjectCont< ROVehicle * >::getTempVector | ( | ) | const throw () [inline, inherited] |
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 }
| const ROVehicle *const ROVehicleCont::getTopVehicle | ( | ) | const throw () |
Returns the vehicle that departs most early.
Returns the first vehicle from the internal list of sorted vehicles or 0 if this list is empty.
Definition at line 52 of file ROVehicleCont.cpp.
References mySorted, and NamedObjectCont< ROVehicle * >::size().
Referenced by erase(), and RONet::saveAndRemoveRoutesUntil().
| void NamedObjectCont< ROVehicle * >::insertIDs | ( | std::vector< std::string > & | into | ) | const throw () [inline, inherited] |
Definition at line 206 of file NamedObjectCont.h.
00206 { 00207 typename IDMap::const_iterator i; 00208 for (i=myMap.begin(); i!=myMap.end(); ++i) { 00209 into.push_back((*i).first); 00210 } 00211 }
| ROVehicleCont& ROVehicleCont::operator= | ( | const ROVehicleCont & | src | ) | [private] |
Invalidated assignment operator.
| void ROVehicleCont::rebuildSorted | ( | ) | throw () [private] |
Rebuild the internal, sorted list.
Rebuilds the internal, sorted list by clearing it, first, and then adding all vehicles stored.
Definition at line 94 of file ROVehicleCont.cpp.
References NamedObjectCont< ROVehicle * >::getMyMap(), and mySorted.
Referenced by erase().
00094 { 00095 mySorted = std::priority_queue<ROVehicle*, std::vector<ROVehicle*>, ROVehicleByDepartureComperator>(); 00096 std::map<std::string, ROVehicle*>::const_iterator i; 00097 const std::map<std::string, ROVehicle*> &mmap = getMyMap(); 00098 for (i=mmap.begin(); i!=mmap.end(); ++i) { 00099 mySorted.push((*i).second); 00100 } 00101 }
| virtual bool NamedObjectCont< ROVehicle * >::remove | ( | const std::string & | id | ) | throw () [inline, virtual, inherited] |
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< ROVehicle * >::size | ( | ) | const throw () [inline, inherited] |
Returns the number of items within the container.
Definition at line 131 of file NamedObjectCont.h.
Referenced by getTopVehicle().
00131 { 00132 return (unsigned int) myMap.size(); 00133 }
std::priority_queue<ROVehicle*, std::vector<ROVehicle*>, ROVehicleByDepartureComperator> ROVehicleCont::mySorted [mutable, private] |
The sorted vehicle list.
Definition at line 125 of file ROVehicleCont.h.
Referenced by add(), clear(), erase(), getTopVehicle(), and rebuildSorted().
1.5.6