SUMO - Simulation of Urban MObility
ODDistrictCont Class Reference

A container for districts. More...

#include <ODDistrictCont.h>

Inheritance diagram for ODDistrictCont:
Inheritance graph
Collaboration diagram for ODDistrictCont:
Collaboration graph

Public Types

typedef std::map< std::string, ODDistrict * > IDMap
 Definition of the key to pointer map type. More...
 

Public Member Functions

virtual bool add (const std::string &id, ODDistrict *item)
 Adds an item. More...
 
const std::vector< ODDistrict * > & buildAndGetStaticVector () const
 
void clear ()
 Removes all items from the container (deletes them, too) More...
 
bool erase (const std::string &id)
 Removes the named item from the container. More...
 
ODDistrictget (const std::string &id) const
 Retrieves an item. More...
 
const IDMapgetMyMap () const
 
std::string getRandomSinkFromDistrict (const std::string &name) const
 Returns the id of a random sink from the named district. More...
 
std::string getRandomSourceFromDistrict (const std::string &name) const
 Returns the id of a random source from the named district. More...
 
std::vector< ODDistrict * > getTempVector () const
 
void insertIDs (std::vector< std::string > &into) const
 
void loadDistricts (std::vector< std::string > files)
 load districts from files More...
 
void makeDistricts (const std::map< std::string, std::pair< std::vector< std::string >, std::vector< std::string > > > &districts)
 create districts from description More...
 
 ODDistrictCont ()
 Constructor. More...
 
virtual bool remove (const std::string &id)
 Removes an item. More...
 
unsigned int size () const
 Returns the number of items within the container. More...
 
 ~ODDistrictCont ()
 Destructor. More...
 

Private Member Functions

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

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 49 of file ODDistrictCont.h.

Member Typedef Documentation

typedef std::map< std::string, ODDistrict * > NamedObjectCont< ODDistrict * >::IDMap
inherited

Definition of the key to pointer map type.

Definition at line 57 of file NamedObjectCont.h.

Constructor & Destructor Documentation

ODDistrictCont::ODDistrictCont ( )

Constructor.

Definition at line 54 of file ODDistrictCont.cpp.

ODDistrictCont::~ODDistrictCont ( )

Destructor.

Definition at line 57 of file ODDistrictCont.cpp.

ODDistrictCont::ODDistrictCont ( const ODDistrictCont s)
private

invalidated copy constructor

Member Function Documentation

virtual bool NamedObjectCont< ODDistrict * >::add ( const std::string &  id,
ODDistrict item 
)
inlinevirtualinherited

Adds an item.

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

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

Definition at line 80 of file NamedObjectCont.h.

Referenced by makeDistricts().

const std::vector<ODDistrict * >& NamedObjectCont< ODDistrict * >::buildAndGetStaticVector ( ) const
inlineinherited

Definition at line 179 of file NamedObjectCont.h.

void NamedObjectCont< ODDistrict * >::clear ( )
inlineinherited

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

Definition at line 123 of file NamedObjectCont.h.

bool NamedObjectCont< ODDistrict * >::erase ( const std::string &  id)
inlineinherited

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]idThe id of the item to delete
Returns
Whether the object could be deleted (was within the map)

Definition at line 151 of file NamedObjectCont.h.

ODDistrict * NamedObjectCont< ODDistrict * >::get ( const std::string &  id) const
inlineinherited

Retrieves an item.

Returns 0 when no item with the given id is stored within the container

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

Definition at line 113 of file NamedObjectCont.h.

const IDMap& NamedObjectCont< ODDistrict * >::getMyMap ( ) const
inlineinherited

Definition at line 224 of file NamedObjectCont.h.

std::string ODDistrictCont::getRandomSinkFromDistrict ( const std::string &  name) const

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]nameThe id of the district to get a random sink from
Returns
The id of a randomly chosen sink
Exceptions
InvalidArgumentIf the named district is not known
OutOfBoundsExceptionIf the named district has no sinks
See also
ODDistrict::getRandomSink

Definition at line 71 of file ODDistrictCont.cpp.

References ODDistrict::getRandomSink().

Referenced by ODMatrix::computeDeparts().

std::string ODDistrictCont::getRandomSourceFromDistrict ( const std::string &  name) const

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]nameThe id of the district to get a random source from
Returns
The id of a randomly chosen source
Exceptions
InvalidArgumentIf the named district is not known
OutOfBoundsExceptionIf the named district has no sources
See also
ODDistrict::getRandomSource

Definition at line 61 of file ODDistrictCont.cpp.

References ODDistrict::getRandomSource().

Referenced by ODMatrix::computeDeparts().

std::vector<ODDistrict * > NamedObjectCont< ODDistrict * >::getTempVector ( ) const
inlineinherited

Definition at line 199 of file NamedObjectCont.h.

void NamedObjectCont< ODDistrict * >::insertIDs ( std::vector< std::string > &  into) const
inlineinherited

Definition at line 212 of file NamedObjectCont.h.

void ODDistrictCont::loadDistricts ( std::vector< std::string >  files)

load districts from files

Definition at line 81 of file ODDistrictCont.cpp.

References FileHelpers::isReadable(), PROGRESS_BEGIN_MESSAGE, PROGRESS_DONE_MESSAGE, PROGRESS_FAILED_MESSAGE, and XMLSubSys::runParser().

Referenced by main().

void ODDistrictCont::makeDistricts ( const std::map< std::string, std::pair< std::vector< std::string >, std::vector< std::string > > > &  districts)

create districts from description

Definition at line 100 of file ODDistrictCont.cpp.

References NamedObjectCont< ODDistrict * >::add(), ODDistrict::addSink(), ODDistrict::addSource(), and Named::getID().

Referenced by main().

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

invalidated assignment operator

virtual bool NamedObjectCont< ODDistrict * >::remove ( const std::string &  id)
inlinevirtualinherited

Removes an item.

Parameters
[in]idThe 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 94 of file NamedObjectCont.h.

unsigned int NamedObjectCont< ODDistrict * >::size ( ) const
inlineinherited

Returns the number of items within the container.

Returns
The number of stored items

Definition at line 137 of file NamedObjectCont.h.


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