Eclipse SUMO - Simulation of Urban MObility
ODDistrictCont Class Reference

A container for districts. More...

#include <ODDistrictCont.h>

Inheritance diagram for ODDistrictCont:
Collaboration diagram for ODDistrictCont:

Public Types

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

Public Member Functions

bool add (const std::string &id, ODDistrict * item)
 Adds an item. More...
 
IDMap::const_iterator begin () const
 Returns a reference to the begin iterator for the internal map. More...
 
bool changeID (const std::string &oldId, const std::string &newId)
 change ID of a stored object More...
 
void clear ()
 Removes all items from the container (deletes them, too) More...
 
IDMap::const_iterator end () const
 Returns a reference to the end iterator for the internal map. More...
 
ODDistrictget (const std::string &id) const
 Retrieves an item. More...
 
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...
 
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...
 
bool remove (const std::string &id, const bool del=true)
 Removes an item. More...
 
int size () const
 Returns the number of stored 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 42 of file ODDistrictCont.h.

Member Typedef Documentation

◆ IDMap

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

Definition of the key to pointer map type.

Definition at line 47 of file NamedObjectCont.h.

Constructor & Destructor Documentation

◆ ODDistrictCont() [1/2]

ODDistrictCont::ODDistrictCont ( )

Constructor.

Definition at line 43 of file ODDistrictCont.cpp.

◆ ~ODDistrictCont()

ODDistrictCont::~ODDistrictCont ( )

Destructor.

Definition at line 46 of file ODDistrictCont.cpp.

◆ ODDistrictCont() [2/2]

ODDistrictCont::ODDistrictCont ( const ODDistrictCont s)
private

invalidated copy constructor

Member Function Documentation

◆ add()

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

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 66 of file NamedObjectCont.h.

Referenced by makeDistricts().

◆ begin()

IDMap::const_iterator NamedObjectCont< ODDistrict * >::begin ( ) const
inlineinherited

Returns a reference to the begin iterator for the internal map.

Definition at line 145 of file NamedObjectCont.h.

◆ changeID()

bool NamedObjectCont< ODDistrict * >::changeID ( const std::string &  oldId,
const std::string &  newId 
)
inlineinherited

change ID of a stored object

Definition at line 131 of file NamedObjectCont.h.

◆ clear()

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

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

Definition at line 109 of file NamedObjectCont.h.

◆ end()

IDMap::const_iterator NamedObjectCont< ODDistrict * >::end ( ) const
inlineinherited

Returns a reference to the end iterator for the internal map.

Definition at line 150 of file NamedObjectCont.h.

◆ get()

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 99 of file NamedObjectCont.h.

◆ getRandomSinkFromDistrict()

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 60 of file ODDistrictCont.cpp.

References ODDistrict::getRandomSink().

Referenced by ODMatrix::computeDeparts().

◆ getRandomSourceFromDistrict()

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 50 of file ODDistrictCont.cpp.

References ODDistrict::getRandomSource().

Referenced by ODMatrix::computeDeparts().

◆ insertIDs()

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

Definition at line 124 of file NamedObjectCont.h.

◆ loadDistricts()

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

load districts from files

Definition at line 70 of file ODDistrictCont.cpp.

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

Referenced by main().

◆ makeDistricts()

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 89 of file ODDistrictCont.cpp.

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

Referenced by main().

◆ operator=()

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

invalidated assignment operator

◆ remove()

bool NamedObjectCont< ODDistrict * >::remove ( const std::string &  id,
const bool  del = true 
)
inlineinherited

Removes an item.

Parameters
[in]idThe id of the item to remove
[in]deldelete item after removing of container
Returns
If the item could been removed (an item with the id was within the container before)

Definition at line 79 of file NamedObjectCont.h.

◆ size()

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

Returns the number of stored items within the container.

Definition at line 117 of file NamedObjectCont.h.


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