PopLooper

The class PopLooper is a container for populations used by the simulation. Apart from implementing the interface PopFinder, it has methods for managing the populations.

Code:

Type definitions

typedef std::map<int, PopBase *> popmap;
typedef std::vector<PopBase *>   popvec;

Public Methods

constructor

PopLooper();

Initializes some variables.

destructor

virtual ~PopLooper();

The destructor deletes all population managed by the PopLooper object.

tryMerge

int tryMerge();

Tries to merge as many populations as possible. Two populations can be merged if they have the same name, the same species ID, the same agent type and the same actions.

addPop

int addPop(PopBase *pPop);
pPop

Pointer to population to be added.

Adds the specified population to the collection of populations.

removePopByName

PopBase *removePopByName(const std::string sSpeciesName, bool bAddToExtinct);
sSpeciesName

Name of population to remove.

bAddToExtinct

If true, the population is added to the vector of extinct populations.

Removes the secified population from the collection of populations.

removePopByIndex

PopBase *removePopByIndex(int iIndex, bool bAddToExtinct);
iIndex

Index of population to be removed.

bAddToExtinct

If true, the population is added to the vector of extinct populations.

Removes the secified population from the collection of populations.

doStep

int doStep(float fStep);
fStep

Current simulation step.

Calls the initializeStep() method of all managed populations, then loops through all priority levels, calling all managed populations’ doActions() method, and finally calls the finalizeStep() method for all populations.

preLoop

virtual int  preLoop();

Calls the preLoop() method of all managed populations.

postLoop

virtual int  postLoop();

Calls the postLoop() method of all managed populations.

preWrite

virtual int  preWrite(float fTime);

Calls the preWrite() method of all managed populations.

getNumPops

size_t  getNumPops();

Returns the number of managed populations.

getDead

const popvec  &getDead();

Returns the vector of extinct populations.,

getMaxID

idtype  getMaxID();

Returns the highest ID used by this population.

getPopByName

virtual PopBase *getPopByName(const std::string sSpeciesName);
sSpecies

Name of wanted population.

(Implementation of PopFinder::getPopByName())

This method returns a pointer to the population with the specified name, or NULL if it can’t be found or doesn’t exist.