april  1.0.0
...
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
april::World Class Reference

A world hosts agents, events, environment. More...

#include <world.h>

+ Inheritance diagram for april::World:

Public Member Functions

 World (const QString &name, quint64 tot_energ)
 constructor; general use
const QString & name (void) const
 the name of this world
quint64 currentTime (void) const
 current time in this world
void advance (void)
 one unit of time passed
virtual QString factoryName (void) const
 name of the factory that created this instance
const QString & associatedFile (void) const
 associated file
bool hasAssociatedFile (void) const
 has associated file
void setAssociatedFile (const QString &s_val)
 change associated file
void actorDies (Actor *actor)
 informed when the life of an actor ended
Director
Directordirector (void) const
 get the director
bool setDirector (Director *new_val)
 change the director (the world will get a new reference for it)
Factories
const QMap< ID, ActorFactory * > & actorFactories (void) const
 the list of actor factories
const QMap< ID,
ActuatorFactory * > & 
actuatorFactories (void) const
 the list of actuator factories
const QMap< ID, BrainFactory * > & brainFactories (void) const
 the list of brain factories
const QMap< ID, SensorFactory * > & sensorFactories (void) const
 the list of sensor factories
const QMap< ID, EventFactory * > & eventFactories (void) const
 the list of event factories
const QMap< ID, ReflexFactory * > & reflexFactories (void) const
 the list of reflex factories
ActorFactoryactorFactory (ID id) const
 the actor factory for specified ID
ActuatorFactoryactuatorFactory (ID id) const
 the actuator factory for specified ID
BrainFactorybrainFactory (ID id) const
 the brain factory for specified ID
SensorFactorysensorFactory (ID id) const
 the sensor factory for specified ID
EventFactoryeventFactory (ID id) const
 the event factory for specified ID
ReflexFactoryreflexFactory (ID id) const
 the event factory for specified ID
Unique Id's
ID idValue (const QString &s_name)
 get the id associated with a name
void insertId (ID id, const QString &s_name)
 insert a new ID or update the string associated with one
ID addNewId (const QString &s_name=QString())
 allocate a new unique id and assign provided description
ID checkAddId (const QString &s_name)
 check if provided description exists; create a new one if not
void checkAddId (ID id, const QString &s_name)
 check if provided description exists; set this one if not
QString nameForId (ID id)
 get the string associated with an identifier
bool sameUId (World *other) const
 tell if the two unique ID provides are the same
QString createIdName (const QString &s_pattern)
 generate an unique name based on a pattern
QList< ID > allocatedIds (void) const
 allocated ids
bool isIDAssigned (ID id) const
 tell if an ID is assigned
Factories added, removed and searched here
bool addActorFactory (ActorFactory *factory, ID id)
 add one to the list of actor factories
bool addActuatorFactory (ActuatorFactory *factory, ID id)
 add one to the list of actuator factories
bool addSensorFactory (SensorFactory *factory, ID id)
 add one to the list of sensor factories
bool addBrainFactory (BrainFactory *factory, ID id)
 add one to the list of brain factories
bool addEventFactory (EventFactory *factory, ID id)
 add one to the list of event factories
bool addReflexFactory (ReflexFactory *factory, ID id)
 add one to the list of event factories
bool remActorFactory (ActorFactory *factory, ID id)
 add one to the list of actor factories
bool remActuatorFactory (ActuatorFactory *factory, ID id)
 add one to the list of actuator factories
bool remSensorFactory (SensorFactory *factory, ID id)
 add one to the list of sensor factories
bool remBrainFactory (BrainFactory *factory, ID id)
 add one to the list of brain factories
bool remEventFactory (EventFactory *factory, ID id)
 add one to the list of event factories
bool remReflexFactory (ReflexFactory *factory, ID id)
 add one to the list of event factories
ActorFactoryfindActorFactory (const QString &s_name)
 add one to the list of actor factories
ActuatorFactoryfindActuatorFactory (const QString &s_name)
 add one to the list of actuator factories
SensorFactoryfindSensorFactory (const QString &s_name)
 add one to the list of sensor factories
BrainFactoryfindBrainFactory (const QString &s_name)
 add one to the list of brain factories
EventFactoryfindEventFactory (const QString &s_name)
 add one to the list of event factories
ReflexFactoryfindReflexFactory (const QString &s_name)
 add one to the list of event factories
Components are created here
ActorcreateActor (ID id_kind)
 create an actor
ActuatorcreateActuator (Actor *actor, ID id)
 create an actuator
BraincreateBrain (Actor *actor, ID id)
 create a brain
SensorcreateSensor (Actor *actor, ID id)
 create a brain
EventSourcecreateEvent (ID id)
 create a brain
ReflexcreateReflex (Actor *actor, ID id)
 create a reflex
Save and load the world
virtual bool save (QSettings &stg) const
 save the world (only when the world is stopped)
virtual bool load (QSettings &stg)
 load the world (only when the world is stopped)
virtual bool saveAsStg (const QString &s_file, QString &s_err) const
 save the world (only when the world is stopped)
- Public Member Functions inherited from april::Component
 Component (void)
 constructor;
Amorph & payload (void)
 associated data
virtual ID identificator (void) const
 associated ID, if any
virtual Factoryfactory (void) const
 associated factory, if any

Static Public Member Functions

static Q_REQUIRED_RESULT WorldfromStg (QSettings &s)
 constructor method; creates and loads a world from QSettings
static Q_REQUIRED_RESULT WorldfromStg (const QString &s_file, QString &s_err)
 constructor method; creates and loads a world from a file

Protected Member Functions

virtual ~World (void)
 destructor;
- Protected Member Functions inherited from april::Component
virtual ~Component (void)
 destructor;
virtual void inserted (void)
 the instance is informed that the parent attached it

Friends

class Actor
class Director
class EventSource
class Factory
class EventLine
class ActorFactory
class ActuatorFactory
class BrainFactory
class SensorFactory
class EventFactory
class ReflexFactory

Running

bool start (void)
 starts this world
void stop (void)
 stops this world
bool isRunning (void) const
 tell if this world is running
void stepTime (void)
 director uses this method to update the time

Energy

quint64 energy (void) const
 ammount of energy in this world
quint64 energyFree (void) const
 ammount of free energy in this world
quint64 energyBounded (void) const
 ammount of bounded energy in this world
bool setTotEnergy (quint64 new_val)
 sets the total ammout of energy in this world
bool setEnergy (ActorComp *comp, quint64 energy, quint64 cost)
 set the packed energy and the ammount of energy consumed on each time unit

Actor related methods

ActorfirstActor (void) const
 first in the list of actors (alive or recently dead)
ActoractorAt (int i) const
 get nth actor (NULL if out of bounds)
bool killActor (Actor *a)
 an actor is being killed and its energy transferred to world
bool addActor (Actor *act)
 used by the Actor class to insert itself
bool remActor (Actor *act)
 used by the Actor class to remove itself

EventSource related methods

EventSourcefirstEvent (void) const
 first in the list of events (alive or recently dead)
bool addEvent (EventSource *act)
 used by the EventSource class to insert itself
bool remEvent (EventSource *act)
 used by the EventSource class to remove itself

Eventlines related methods

EventLineeventLine (ID id)
 used by the EventLine class to insert itself
bool addEventLine (EventLine *el, ID id)
 used by the EventLine class to insert itself
bool remEventLine (EventLine *el, ID id)
 used by the EventLine class to remove itself
QMap< ID, EventLine * >
::ConstIterator 
firstEventLine (void)
 access to event lines in the world - first
QMap< ID, EventLine * >
::ConstIterator 
endEventLine (void)
 access to event lines in the world - end

Detailed Description

A world hosts agents, events, environment.

Member Function Documentation

Actor * World::createActor ( ID  id_kind)

create an actor

A factory is searched for this ID and, if found, it is requested to create an Actor.

Parameters
id_kindthe id to search
Returns
NULL for error, an actor otherwise
ID april::World::idValue ( const QString &  s_name)
inline

get the id associated with a name

Parameters
s_namethe string to search (case sensitive)
Returns
the id that was found or InvalidId
bool World::killActor ( Actor a)

an actor is being killed and its energy transferred to world

This is simply a shortcut to Actor::killMe

Parameters
aThe actor to kill
Returns
true if everything went well (well, bad for the actor)
bool World::setEnergy ( ActorComp comp,
quint64  energy,
quint64  cost 
)
protected

set the packed energy and the ammount of energy consumed on each time unit

If the world does not have that much energy the opperation is dropped.

Parameters
compthe component where this is to be set
energypacked energy (will be substracted from world's free energy)
costenergy consumed on each step by this component
Returns
true if the opperation succeded

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