AndroMeta  2.0.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Friends
Meta::MMLEntity Class Reference

The central actor base class in an MML program. More...

#include <MMLEntity.h>

Inheritance diagram for Meta::MMLEntity:
Meta::MObject Meta::MProcessor Meta::MObjectBase Meta::MDLDomain Meta::MMLGrid Meta::MMLRoot Meta::MMLSharedVar

List of all members.

Public Member Functions

 MMLEntity ()
 MMLEntity (int id)
 MMLEntity (const MMLEntity &entity, bool recursive=false)
 MMLEntity (const mvar &v, RestoreOpt opt, MMLRoot *root=0)
 MMLEntity (MMLRoot *root)
virtual ~MMLEntity ()
virtual void store (mvar &v) const
virtual void store (mvar &v, bool recursive) const
virtual MObjectclone () const
virtual mnode process (mnode n, uint32_t flags=0)
virtual bool instanceOf (ClassIdType classId) const
virtual void assignId ()
virtual void releaseId ()
virtual mvar init ()
void setId (int id)
int id () const
void setTag (const mvar &tag)
const mvartag () const
virtual mstr name () const
bool isThreaded () const
void setThreaded (bool flag)
virtual MMessageBufferinitPrivateBuffer ()
virtual MMessageBufferinitSharedBuffer ()
MMessageBufferprivateBuffer () const
MMessageBuffersharedBuffer () const
void connect (MMLEntity *ent, const mvar &data=undef, const mstr &edgeTag="")
void connect (const mvar &ent, const mvar &data=undef, const mstr &edgeTag="")
virtual void onConnect (MMLEntity *ent, const mstr &edgeTag)
void disconnect (MMLEntity *ent, const mstr &edgeTag)
void disconnect (const mvar &ent, const mstr &edgeTag)
void disconnect (MMLEntity *ent)
void disconnect (const mvar &ent)
void disconnect ()
void addLocality (const mstr &attribute, double radius)
void addLocality (const mstr &attribute, double radius, MMLEntity *ent)
void addLocality (const mstr &attribute, double radius, const mvar &ent)
size_t localityCount () const
const mstrlocalityAttribute (size_t i) const
double localityRadius (size_t i) const
MMLEntitylocalityEntity (size_t i) const
void removeLocality (const mstr &attribute)
virtual void onDisconnect (MMLEntity *ent, const mstr &edgeTag)
const mvaredgeData (const MMLEntity *ent, const mstr &edgeTag="") const
const mvaredgeData (const mvar &ent, const mstr &edgeTag="") const
void setEdgeData (const mvar &ent, const mvar &edgeData, const mstr &edgeTag="")
void setEdgeData (const MMLEntity *ent, const mvar &edgeData, const mstr &edgeTag="")
virtual void onAttach (MMLEntity *ent, const mstr &edgeTag)
void detach ()
virtual void onDetach (MMLEntity *ent, const mstr &edgeTag)
void signal (MMLEntity *ent, const mstr &edgeTag="")
void signal (const mvar &ent, const mstr &edgeTag="")
void signal (MMLEntity *ent, const mvar &v, const mstr &edgeTag)
void signal (const mvar &ent, const mvar &v, const mstr &edgeTag)
void signalAll ()
void signalAll (const mvar &v)
size_t outEdgeCount () const
size_t inEdgeCount () const
void outEdges (mvec &ents, mvec &edgeTags) const
void outEdges (mvec &ents) const
mvec outEdges () const
void setActive (bool flag)
bool isActive () const
void queue ()
void queue (MProcTask *task, MProc::SignalMap *signalMap=0, double priority=0, const mtime *time=0)
mvar time () const
mvar interval () const
virtual mvar run ()
void setRunAll (bool flag)
bool runAll () const
bool isRunCycle () const
virtual mvar endRun ()
const mvarstate () const
void setKept (bool kept)
bool isKept () const
void query (mnode func, mvec &results, bool recursive, bool self, bool error) const
mvar query (mnode func, bool recursive=false, bool self=true, bool error=true) const
void execute (mnode func, bool recursive=false, bool self=true, bool error=true) const
void find (const mstr &name, mvec &results, bool recursive, bool self) const
mvar find (const mstr &name, bool recursive=false, bool self=true) const
void await ()
bool await (const mtime &timeout)
void handleEvents ()
virtual mvar handleEvent (const mvar &evt)
void send (MMLEntity *ent, const mvar &evt, const mvar &delay)
void send (const mvar &ent, const mvar &evt, const mvar &delay)
void send (MMLEntity *ent, const mvar &evt)
void send (const mvar &ent, const mvar &evt)
void relay (const mvar &evt, const mvar &delay)
void relay (const mvar &evt)
void post (MMLEntity *ent, const mvar &evt, const mvar &delay)
void post (const mvar &ent, const mvar &evt, const mvar &delay)
void post (MMLEntity *ent, const mvar &evt)
void post (const mvar &ent, const mvar &evt)
void log (const mvar &msg, bool concise=true) const
void listen (MMLEntity *ent)
void listen (const mvar &ent)
virtual mvar end ()
mvar getLinks (mnode f=mfunc("List"))
void lock ()
void unlock ()
MMLRootrootPtr ()

Static Public Member Functions

static MMLEntityptr (const mvar &v, bool dynamic=false)

Static Public Attributes

static const ClassIdType ClassId

Protected Attributes

mvar root

Friends

class MMLEntity_
class MMLRoot_

Detailed Description

The central actor base class in an MML program.

MML entities form the basis of an MML program, providing abstractions which facilitate modeling and simulation: event communication and handling, graph-based chaining and signalling for concurrent execution (using MProc), synchronization methods, time management, recursive querying/execution, and more. MML entities and the "networks" formed by their interconnections are fully storeable and restoreable.


Constructor & Destructor Documentation

Constructor.

Constructor.

In most cases this variant of the constructor is not needed -- it is primarily used for store/restore.

Meta::MMLEntity::MMLEntity ( const MMLEntity entity,
bool  recursive = false 
)

Copy constructor.

Parameters:
recursiveIf true, recursively copy all connected entities.
Meta::MMLEntity::MMLEntity ( const mvar v,
RestoreOpt  opt,
MMLRoot root = 0 
)

Restore constructor.

Parameters:
rootIf non-null, the root to use for this entity, else the default root.

Ctor with specifed root. Used when multiple roots exist simultaneously.

virtual Meta::MMLEntity::~MMLEntity ( ) [virtual]

Destructor.


Member Function Documentation

void Meta::MMLEntity::addLocality ( const mstr attribute,
double  radius 
)

Add a locality attribute to be triggered at root.

void Meta::MMLEntity::addLocality ( const mstr attribute,
double  radius,
MMLEntity ent 
)

Add a locality attribute to be triggered at the specified entity.

void Meta::MMLEntity::addLocality ( const mstr attribute,
double  radius,
const mvar ent 
)

Add a locality attribute to be triggered at the specified entity.

virtual void Meta::MMLEntity::assignId ( ) [virtual]

Called when this entity needs to have an id assigned to it. Should not be re-implemented under normal circumstances.

Block until after completion of this entity's next run.

bool Meta::MMLEntity::await ( const mtime timeout)

Block until after completion of this entity's next run or until timeout is reached.

Returns:
true on success, i.e: did not time out.
virtual MObject* Meta::MMLEntity::clone ( ) const [virtual]
Returns:
A copy of this entity (non-recursive).

Reimplemented from Meta::MObject.

void Meta::MMLEntity::connect ( MMLEntity ent,
const mvar data = undef,
const mstr edgeTag = "" 
)

Form an outward connection to ent.

Parameters:
entThe entity to connect to.
dataThe edge data to attach to this edge.
edgeTagThe edge tag
void Meta::MMLEntity::connect ( const mvar ent,
const mvar data = undef,
const mstr edgeTag = "" 
)

Form an outward connection to ent.

Parameters:
entThe entity to connect to.
dataThe edge data to attach to this edge.
edgeTagThe edge tag

Detach all inward connections.

void Meta::MMLEntity::disconnect ( MMLEntity ent,
const mstr edgeTag 
)

Disconnect outward connection to ent referred to by edgeTag.

void Meta::MMLEntity::disconnect ( const mvar ent,
const mstr edgeTag 
)

Disconnect outward connection to ent referred to by edgeTag.

Disconnect all outward connections to ent.

void Meta::MMLEntity::disconnect ( const mvar ent)

Disconnect all outward connections to ent.

Disconnect all outward connections.

const mvar& Meta::MMLEntity::edgeData ( const MMLEntity ent,
const mstr edgeTag = "" 
) const
Returns:
The edge data associated with the outward connection to ent.
const mvar& Meta::MMLEntity::edgeData ( const mvar ent,
const mstr edgeTag = "" 
) const
Returns:
The edge data associated with the outward connection to ent.
virtual mvar Meta::MMLEntity::end ( ) [virtual]

An application-specific method that is called when this entity is reclaimed by root.

Reimplemented in Meta::MDLDomain.

virtual mvar Meta::MMLEntity::endRun ( ) [virtual]

Application-specific method called after run() completes and events have been handled.

Reimplemented in Meta::MMLRoot.

void Meta::MMLEntity::execute ( mnode  func,
bool  recursive = false,
bool  self = true,
bool  error = true 
) const

Similar to query(), execute a function (recursively) on all outward connections but do not gather the results.

Parameters:
funcThe function to run on each entity.
recursiveIf true, run query recursively.
selftrue if query should be run on self.
errorfalse if MProcessError's should be suppressed.
void Meta::MMLEntity::find ( const mstr name,
mvec results,
bool  recursive,
bool  self 
) const

A common type of query(), (recursively) find all outward connections whose name() matches name.

Parameters:
nameThe name to match.
resultsOn exit, the results on the search.
recursiveIf true, run query recursively.
selftrue if find should include self.
mvar Meta::MMLEntity::find ( const mstr name,
bool  recursive = false,
bool  self = true 
) const

A common type of query(), (recursively) find all outward connections matching a name.

Parameters:
nameThe name to match.
recursiveIf true, run query recursively.
selftrue if find should include self.
Returns:
Results of search as an mvar vector. The mvar head is set to the first entity found.
mvar Meta::MMLEntity::getLinks ( mnode  f = mfunc("List"))

Get links in M format.

Parameters:
fOn output, the links in M format as the specified sequence.
Returns:
The links as an mvar.
virtual mvar Meta::MMLEntity::handleEvent ( const mvar evt) [virtual]

Application-specific event handler. Re-implement to determine how this entity responds to events.

Reimplemented in Meta::MDLDomain.

Explicitly handle events. Usually this is called at some point in run(). However, it is done implicitly after run() if omitted.

int Meta::MMLEntity::id ( ) const

Get this entity's id.

size_t Meta::MMLEntity::inEdgeCount ( ) const
Returns:
The number of inward connections.
virtual mvar Meta::MMLEntity::init ( ) [virtual]

Application-specific initialization function.

Reimplemented in Meta::MDLDomain.

Returns:
A message buffer to be used for events directly solely to this entity.
Returns:
A message buffer to be used for events communicated to outwardly connected entities.
virtual bool Meta::MMLEntity::instanceOf ( ClassIdType  classId) const [virtual]
Returns:
true if this is an instance of a specified classId.

Reimplemented from Meta::MObject.

Returns:
Run cycle interval.
bool Meta::MMLEntity::isActive ( ) const
Returns:
Whether or not this entity may be activated.
bool Meta::MMLEntity::isKept ( ) const

Set whether this entity is reclaimed by root.

Returns:
true if run() was invoked by a run cycle interval.
Returns:
true if this entity may use threaded execution.

Subscribe to the specified entity's shared buffer.

void Meta::MMLEntity::listen ( const mvar ent)

Subscribe to the specified entity's shared buffer.

const mstr& Meta::MMLEntity::localityAttribute ( size_t  i) const
Returns:
attribute name for locality i.
Returns:
count of locality attributes
Returns:
attribute locality entity for locality i.
double Meta::MMLEntity::localityRadius ( size_t  i) const
Returns:
attribute locality radius for locality i.

Lock this entity's general purpose mutex.

void Meta::MMLEntity::log ( const mvar msg,
bool  concise = true 
) const

Logs entity time, name, and message. Ensures that output does not get interleaved when multiple threads log simultaneously.

Parameters:
msgMessage to display.
conciseWhether to use concise numerics.
virtual mstr Meta::MMLEntity::name ( ) const [virtual]

The name of the entity used for such things as logging, or queries, e.g: find(). By default name is the entity's tag converted to a string.

virtual void Meta::MMLEntity::onAttach ( MMLEntity ent,
const mstr edgeTag 
) [virtual]

Called when forming an outward connection.

Parameters:
entThe entity this entity is attaching to.
virtual void Meta::MMLEntity::onConnect ( MMLEntity ent,
const mstr edgeTag 
) [virtual]

Called when forming an outward connection.

Parameters:
entThe entity connected.
virtual void Meta::MMLEntity::onDetach ( MMLEntity ent,
const mstr edgeTag 
) [virtual]

Called when severing an inward connection.

Parameters:
entThe entity this entity is detaching from.
virtual void Meta::MMLEntity::onDisconnect ( MMLEntity ent,
const mstr edgeTag 
) [virtual]

Called when severing an outward connection.

Parameters:
entThe entity disconnected.
Returns:
The number of outward connections.
void Meta::MMLEntity::outEdges ( mvec ents,
mvec edgeTags 
) const

Get a vector containing the entities and edge tags all outward connections.

void Meta::MMLEntity::outEdges ( mvec ents) const

Get a vector containing the entities of all outward connections. The ents vector contains one entity for each edge even though there may exist multiple edges to that entity.

Return a vector containing the entities of all outward connections. The ents vector contains one entity for each edge even though there may exist multiple edges to that entity.

void Meta::MMLEntity::post ( MMLEntity ent,
const mvar evt,
const mvar delay 
)

Send an event to the target entity's shared buffer.

Parameters:
entTarget entity.
evtThe event to send.
delayDelivery time delay.
void Meta::MMLEntity::post ( const mvar ent,
const mvar evt,
const mvar delay 
)

Send an event to the target entity's shared buffer.

Parameters:
entTarget entity.
evtThe event to send.
delayDelivery time delay.
void Meta::MMLEntity::post ( MMLEntity ent,
const mvar evt 
)

Send an event to the target entity's shared buffer. The delay is the current MML time advance rate (interval).

Parameters:
entTarget entity.
evtThe event to send.
void Meta::MMLEntity::post ( const mvar ent,
const mvar evt 
)

Send an event to the target entity's shared buffer. The delay is the current MML time advance rate (interval).

Parameters:
entTarget entity.
evtThe event to send.
Returns:
The message buffer used for events directly solely to this entity.
virtual mnode Meta::MMLEntity::process ( mnode  n,
uint32_t  flags = 0 
) [virtual]

Process method.

Reimplemented from Meta::MObject.

Reimplemented in Meta::MMLGrid, Meta::MMLRoot, Meta::MMLSharedVar, and Meta::MDLDomain.

static MMLEntity* Meta::MMLEntity::ptr ( const mvar v,
bool  dynamic = false 
) [static]

Convenience method to perform a cast on v to MMLEntity.

Parameters:
dynamicIf true perform a dynamic cast and ensure type is MMLEntity.
Returns:
Pointer to successfully casted entity or null in case of failure.

Reimplemented in Meta::MMLRoot, and Meta::MDLDomain.

void Meta::MMLEntity::query ( mnode  func,
mvec results,
bool  recursive,
bool  self,
bool  error 
) const

Execute a query (recursively) on all outward connections and gather the results.

Parameters:
funcThe function to run on each entity.
resultsOn completion, a vector of the results of the query.
recursiveIf true, run query recursively.
selftrue if query should be run on self.
errorfalse if MProcessError's should be suppressed.
mvar Meta::MMLEntity::query ( mnode  func,
bool  recursive = false,
bool  self = true,
bool  error = true 
) const

Execute a query (recursively) on all outward connections and gather the results.

Parameters:
funcThe function to run on each entity.
recursiveIf true, run query recursively.
selftrue if query should be run on self.
errorfalse if MProcessError's should be suppressed.
Returns:
An mvar containing a vector of the results of the query.

Queue the entity for execution. Normally this is only called once on the top-level entity.

void Meta::MMLEntity::queue ( MProcTask task,
MProc::SignalMap signalMap = 0,
double  priority = 0,
const mtime time = 0 
)

Queue the entity for execution using MProc::queue() parameters.

void Meta::MMLEntity::relay ( const mvar evt,
const mvar delay 
)

Relay an event to this entity's shared buffer.

Parameters:
evtThe event to send.
delayDelivery time delay.
void Meta::MMLEntity::relay ( const mvar evt)

Relay an event to this entity's shared buffer. The delay is the current MML time advance rate (interval).

Parameters:
evtThe event to send.
virtual void Meta::MMLEntity::releaseId ( ) [virtual]

Called upon entity destruction to release its id. Should not be re-implemented under normal circumstances.

void Meta::MMLEntity::removeLocality ( const mstr attribute)

Remove the specified attribute locality.

Returns:
this entity's root.
virtual mvar Meta::MMLEntity::run ( ) [virtual]

Application-specific run method.

Returns:
Entity "state". Normally state is unused and an entity simply returns 0.

Reimplemented in Meta::MMLGrid.

bool Meta::MMLEntity::runAll ( ) const

Return the flag that specifies if this entity's run() method called all the time as opposed to only during a run cycle interval.

void Meta::MMLEntity::send ( MMLEntity ent,
const mvar evt,
const mvar delay 
)

Send an event to a specific entity. The event gets posted in the target entity's private buffer.

Parameters:
entThe target entity.
evtThe event to send.
delayDelivery time delay.
void Meta::MMLEntity::send ( const mvar ent,
const mvar evt,
const mvar delay 
)

Send an event to a specific entity. The event gets posted in the target entity's private buffer.

Parameters:
entThe target entity.
evtThe event to send.
delayDelivery time delay.
void Meta::MMLEntity::send ( MMLEntity ent,
const mvar evt 
)

Send an event to a specific entity. The event gets posted in the target entity's private buffer. The delay is the current MML time advance rate.

Parameters:
entThe target entity.
evtThe event to send.
void Meta::MMLEntity::send ( const mvar ent,
const mvar evt 
)

Send an event to a specific entity. The event gets posted in the target entity's private buffer. The delay is the current MML time advance rate (interval).

Parameters:
entThe target entity.
evtThe event to send.
void Meta::MMLEntity::setActive ( bool  flag)

Set whether or not this entity may be activated.

void Meta::MMLEntity::setEdgeData ( const mvar ent,
const mvar edgeData,
const mstr edgeTag = "" 
)

Set the edge data associated with the outward connection to ent.

void Meta::MMLEntity::setEdgeData ( const MMLEntity ent,
const mvar edgeData,
const mstr edgeTag = "" 
)

Set the edge data associated with the outward connection to ent.

void Meta::MMLEntity::setId ( int  id)

Explicitly set this entity's id.

void Meta::MMLEntity::setKept ( bool  kept)

Set whether this entity is reclaimed by root. Normally an entity is reclaimed when it has no inward connections. The default is true.

void Meta::MMLEntity::setRunAll ( bool  flag)

Set flag to true to have this entity's run() method called all the time as opposed to only during a run cycle interval. Default is false.

void Meta::MMLEntity::setTag ( const mvar tag)

Set tag data. By default, an entity's tag is its id.

void Meta::MMLEntity::setThreaded ( bool  flag)

Set whether this entity potentially uses threaded execution. This is needed because some operations, such as GUI calls, must run on the main thread.

Returns:
The message buffer used for events communicated to outwardly connected entities.
void Meta::MMLEntity::signal ( MMLEntity ent,
const mstr edgeTag = "" 
)

Signal an outward connection by entity. The signal gets value of its edge data.

void Meta::MMLEntity::signal ( const mvar ent,
const mstr edgeTag = "" 
)

Signal an outward connection by entity. The signal gets the value of its edge data.

void Meta::MMLEntity::signal ( MMLEntity ent,
const mvar v,
const mstr edgeTag 
)

Signal an outward connection by entity. The signal gets value v.

void Meta::MMLEntity::signal ( const mvar ent,
const mvar v,
const mstr edgeTag 
)

Signal an outward connection by entity. The signal gets value v.

Signal all outward connections.

void Meta::MMLEntity::signalAll ( const mvar v)

Signal all outward connections with value v.

const mvar& Meta::MMLEntity::state ( ) const
Returns:
The entity state which was set by last time run() was called.
virtual void Meta::MMLEntity::store ( mvar v) const [virtual]

Store this entity to v.

Reimplemented from Meta::MObject.

Reimplemented in Meta::MMLRoot, and Meta::MDLDomain.

virtual void Meta::MMLEntity::store ( mvar v,
bool  recursive 
) const [virtual]

Store this entity to v.

Parameters:
recursiveIf true, recursively store all connected entities.
const mvar& Meta::MMLEntity::tag ( ) const

Get tag data.

Returns:
Global MML time.

Unlock this entity's general purpose mutex.


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