ODDistrictCont Class Reference

#include <ODDistrictCont.h>

Inheritance diagram for ODDistrictCont:

NamedObjectCont< ODDistrict * >

Detailed Description

A container for districts.

Besides the inherited methods for adding/removing districts, this container allows to retrieve a random source or sink from a named district.

Definition at line 46 of file ODDistrictCont.h.


Public Member Functions

virtual bool add (const std::string &id, ODDistrict *item) throw ()
 Adds an item.
const std::vector< ODDistrict * > & 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.
ODDistrictget (const std::string &id) const throw ()
 Retrieves an item.
const std::map< std::string,
ODDistrict * > & 
getMyMap () const throw ()
std::string getRandomSinkFromDistrict (const std::string &name) const throw (OutOfBoundsException, InvalidArgument)
 Returns the id of a random sink from the named district.
std::string getRandomSourceFromDistrict (const std::string &name) const throw (OutOfBoundsException, InvalidArgument)
 Returns the id of a random source from the named district.
std::vector< ODDistrict * > getTempVector () const throw ()
void insertIDs (std::vector< std::string > &into) const throw ()
 ODDistrictCont () 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.
 ~ODDistrictCont () throw ()
 Destructor.

Private Member Functions

 ODDistrictCont (const ODDistrictCont &s)
 invalidated copy constructor
ODDistrictContoperator= (const ODDistrictCont &s)
 invalidated assignment operator

Constructor & Destructor Documentation

ODDistrictCont::ODDistrictCont (  )  throw ()

Constructor.

Definition at line 45 of file ODDistrictCont.cpp.

00045 {}

ODDistrictCont::~ODDistrictCont (  )  throw ()

Destructor.

Definition at line 48 of file ODDistrictCont.cpp.

00048 {}

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

invalidated copy constructor


Member Function Documentation

virtual bool NamedObjectCont< ODDistrict * >::add ( const std::string &  id,
ODDistrict *   item 
) throw () [inline, virtual, inherited]

Adds an item.

If another item with the same name is already known, false is reported and the item is not added.

Parameters:
[in] id The id of the item to add
[in] item The item to add
Returns:
If the item could been added (no item with the same id was within the container before)

Definition at line 74 of file NamedObjectCont.h.

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<ODDistrict * >& NamedObjectCont< ODDistrict * >::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 NamedObjectCont< ODDistrict * >::clear (  )  throw () [inline, inherited]

Removes all items from the container (deletes them, too).

Definition at line 117 of file NamedObjectCont.h.

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< ODDistrict * >::erase ( const std::string &  id  )  throw () [inline, inherited]

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.

Parameters:
[in] id The id of the item to delete
Returns:
Whether the object could be deleted (was within the map)

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     }

ODDistrict * NamedObjectCont< ODDistrict * >::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

Parameters:
[in] id The id of the item to retrieve
Returns:
The item stored under the given id, or 0 if no such item exists

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, ODDistrict * >& NamedObjectCont< ODDistrict * >::getMyMap (  )  const throw () [inline, inherited]

Definition at line 218 of file NamedObjectCont.h.

00218                                                          {
00219         return myMap;
00220     }

std::string ODDistrictCont::getRandomSinkFromDistrict ( const std::string &  name  )  const throw (OutOfBoundsException, InvalidArgument)

Returns the id of a random sink from the named district.

At first, the named district is retrieved. If this fails, an InvalidArgument-exception is thrown. Otherwise, a sink (edge) is chosen randomly from this district using this district's getRandomSink-method which throws an OutOfBoundsException-exception if this district does not contain a sink.

Parameters:
[in] name The id of the district to get a random sink from
Returns:
The id of a randomly chosen sink
Exceptions:
InvalidArgument If the named district is not known
OutOfBoundsException If the named district has no sinks
See also:
ODDistrict::getRandomSink

Definition at line 62 of file ODDistrictCont.cpp.

References ODDistrict::getRandomSink().

Referenced by ODMatrix::computeEmissions().

00062                                                                                                                   {
00063     ODDistrict *district = get(name);
00064     if (district==0) {
00065         throw InvalidArgument("There is no district '" + name + "'.");
00066     }
00067     return district->getRandomSink();
00068 }

std::string ODDistrictCont::getRandomSourceFromDistrict ( const std::string &  name  )  const throw (OutOfBoundsException, InvalidArgument)

Returns the id of a random source from the named district.

At first, the named district is retrieved. If this fails, an InvalidArgument-exception is thrown. Otherwise, a source (edge) is chosen randomly from this district using this district's getRandomSource-method which throws an OutOfBoundsException-exception if this district does not contain a source.

Parameters:
[in] name The id of the district to get a random source from
Returns:
The id of a randomly chosen source
Exceptions:
InvalidArgument If the named district is not known
OutOfBoundsException If the named district has no sources
See also:
ODDistrict::getRandomSource

Definition at line 52 of file ODDistrictCont.cpp.

References ODDistrict::getRandomSource().

Referenced by ODMatrix::computeEmissions().

00052                                                                                                                     {
00053     ODDistrict *district = get(name);
00054     if (district==0) {
00055         throw InvalidArgument("There is no district '" + name + "'.");
00056     }
00057     return district->getRandomSource();
00058 }

std::vector<ODDistrict * > NamedObjectCont< ODDistrict * >::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     }

void NamedObjectCont< ODDistrict * >::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     }

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

invalidated assignment operator

virtual bool NamedObjectCont< ODDistrict * >::remove ( const std::string &  id  )  throw () [inline, virtual, inherited]

Removes an item.

Parameters:
[in] id The id of the item to remove
Returns:
If the item could been removed (an item with the id was within the container before)

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< ODDistrict * >::size (  )  const throw () [inline, inherited]

Returns the number of items within the container.

Returns:
The number of stored items

Definition at line 131 of file NamedObjectCont.h.

00131                                       {
00132         return (unsigned int) myMap.size();
00133     }


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

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