Odyssey::Element Class Reference

This class represents a single entity within the simulation. More...

#include <Element.h>

Inheritance diagram for Odyssey::Element:

Odyssey::MessageListener Odyssey::ModelListener List of all members.

Public Types

typedef std::vector< FacetPtrFacetList
typedef ContainerIterator<
FacetList
FacetIterator
typedef ConstContainerIterator<
FacetList
ConstFacetIterator
typedef std::map< String,
Variable
UserDataMap
typedef MapContainerIterator<
UserDataMap
UserDataIterator
typedef ConstMapContainerIterator<
UserDataMap
ConstUserDataIterator
typedef std::vector< Element * > ChildList
typedef ContainerIterator<
ChildList
ChildIterator
typedef ConstContainerIterator<
ChildList
ConstChildIterator

Public Member Functions

 Element ()
 Constructs an empty Element with an empty name.
void setName (const String &name)
 Sets the name for this element.
const StringgetName () const
 Returns the name of the Element.
ElementgetParent () const
 Returns the parent of this Element, or 0 if there isn't one.
void createState (const String &name)
 Creates a new state with the given name, or fails silently if the state already exists.
void removeState (const String &name)
 Removes the state with the given name.
void removeState (const String &name, const String &newCurrent)
 Removes the state with the given name.
void setCurrentState (const String &name)
 Sets the current state to the state with the given name.
boost::optional< StringgetCurrentState () const
 Returns the name of the current state.
void clearStates ()
 Removes all the currently contained states (except the default state).
void addStateListener (StateListener *listener)
 Adds a new element state listener.
void removeStateListener (StateListener *listener)
 Removes the state listener from the element.
void clearStateListeners ()
 Removes all the state listeners.
void _notifyStateListeners (const String &newState)
 Internal method for signalling the state listeners.
FacetaddFacet (FacetPtr facet)
 Add a new facet to this Element.
void setFacet (size_t index, FacetPtr facet)
 Sets the facet at the given index.
FacetaddDynamicFacet (const String &typeID)
 Uses dynamic class construction to add a new facet.
void setDynamicFacet (size_t index, const String &typeID)
 Uses dynamic class construction to set the facet at the given index.
FacetPtr getFacet (size_t index) const
 Returns the facet at the given index.
void sendMessageToFacet (size_t index, const Message &msg)
 Send a message to the given facet, and doesn't return until it is processed.
void removeFacet (size_t index)
 Removed the given facet.
void removeFacet (Facet *facet)
 Removed the given facet.
void clearFacets ()
 Clears all facets from this Element.
size_t getFacetCount () const
 Returns the number of facets.
FacetIterator getFacetIterator ()
 Returns an iterator over the Element's facets.
ConstFacetIterator getFacetIterator () const
 Returns an iterator over the Element's facets.
ElementPtr createChild (const String &name)
 Adds a new child with the given name in the ModelManager.
ElementPtr createChild (const String &typeID, const String &name)
 Adds a new child with the given typeID and name in the ModelManager.
size_t addChild (Element *element)
 Adds a child to Element.
size_t addChild (const String &name)
 Adds a child with the given name to this Element.
size_t addChild (size_t index)
 Adds a child with the given index to this Element.
void removeChild (Element *element)
 Removes a child from this Element.
void removeChild (size_t index)
 Removes a child from the index.
bool containsChild (const String &name) const
 Check if a child with this name exists in this Element.
ElementgetChild (size_t index) const
 Returns the child at the given internal index.
void clearChildren ()
 Removes all the children from this Element.
size_t getChildCount () const
 Returns the number of children.
ChildIterator getChildIterator ()
 Returns an iterator over the Element's children.
ConstChildIterator getChildIterator () const
 Returns an iterator over the Element's children.
void setUserData (const String &name, const Variable &value)
 Sets the user data for a given name.
Variable getUserData (const String &name) const
 Returns the value of the variable with the given name.
void removeUserData (const String &name)
 Removes the variable with the given name.
void clearUserData ()
 Clears all the user data for this Element.
bool containsUserData (const String &name) const
 Returns true if the user data entry exists.
UserDataIterator getUserDataIterator ()
 Returns an iterator over all of the user data of the Element.
ConstUserDataIterator getConstUserDataIterator () const
 Returns an iterator over all of the user data of the Element.
void create ()
 Creates the Element and its facets.
void destroy ()
 Destroys the element and its facets.
bool isCreated ()
 This function returns true if the call the create completed successfully.
void setActive (bool active=true, bool cancelUpdates=true)
 Activates or deactivates the element.
bool getActive () const
 Returns the current status of the Element. True means active.
virtual void update ()
 Updates the element.
void _notifyUpdate ()
 If active, this function will notify the ElementManager for updates.
MessageQueuegetMessageQueue ()
 Gives access to this element's internal message queue.
virtual bool onAdding (Manager< ElementPtr > &) const
virtual bool onRemoving (Manager< ElementPtr > &) const

Static Public Member Functions

static void createAll (ElementPtr element)
 Creates all elements in the hierarchy.
static void createAll (Element *element)
static void destroyAll (ElementPtr element)
 Destroys all elements in the hierarchy.
static void destroyAll (Element *element)
static void setActiveAll (ElementPtr element, bool active)
 Sets the active state of all elements in the hierarchy.
static void setActiveAll (Element *element, bool active)
static void sendMessageToAll (ElementPtr element, const Message &msg)
 Sends a message to all elements in the hierarchy.
static void sendMessageToAll (Element *element, const Message &msg)
static void postMessageToAll (ElementPtr element, const Message &msg)
 Posts a message to all elements in the hierarchy.
static void postMessageToAll (Element *element, const Message &msg)

Protected Member Functions

virtual void onMessagePosted ()
 This event occurs when a message is posted to the message queue.
virtual std::pair< bool, VariableonMessage (const Message &msg)
 This event is called when a message needs to be handled (it is processed).
virtual void onRemoved (MessageQueue &queue)
 This event is called when this listener is removed as a listener from the message queue.
virtual void onNotify (Model *model)
ElementState * getElementState () const

Protected Attributes

String _name
bool _active
bool _created
MessageQueue _queue
Element_parent
ChildList _children
std::set< Element * > _childSet

Friends

class ElementManager
class ElementBuilder

Classes

class  ElementState
class  StateListener

Detailed Description

This class represents a single entity within the simulation.

This class represents a single entity that exists in the simulation. It is made up of Facets, can reference Models, and store arbitrary, user-defined data.


Member Typedef Documentation

typedef ContainerIterator<ChildList> Odyssey::Element::ChildIterator
 

typedef std::vector<Element*> Odyssey::Element::ChildList
 

typedef ConstContainerIterator<ChildList> Odyssey::Element::ConstChildIterator
 

typedef ConstContainerIterator<FacetList> Odyssey::Element::ConstFacetIterator
 

typedef ConstMapContainerIterator<UserDataMap> Odyssey::Element::ConstUserDataIterator
 

typedef ContainerIterator<FacetList> Odyssey::Element::FacetIterator
 

typedef std::vector<FacetPtr> Odyssey::Element::FacetList
 

typedef MapContainerIterator<UserDataMap> Odyssey::Element::UserDataIterator
 

typedef std::map<String,Variable> Odyssey::Element::UserDataMap
 


Constructor & Destructor Documentation

Odyssey::Element::Element  ) 
 

Constructs an empty Element with an empty name.


Member Function Documentation

void Odyssey::Element::_notifyStateListeners const String newState  ) 
 

Internal method for signalling the state listeners.

void Odyssey::Element::_notifyUpdate  ) 
 

If active, this function will notify the ElementManager for updates.

size_t Odyssey::Element::addChild size_t  index  ) 
 

Adds a child with the given index to this Element.

This function uses the index to lookup an Element in the ElementManager.

Parameters:
index the index of the child to add

size_t Odyssey::Element::addChild const String name  ) 
 

Adds a child with the given name to this Element.

This function uses the given name to lookup an Element in the ElementManager.

Parameters:
name the name of the child to add

size_t Odyssey::Element::addChild Element element  ) 
 

Adds a child to Element.

Facet* Odyssey::Element::addDynamicFacet const String typeID  ) 
 

Uses dynamic class construction to add a new facet.

Facet* Odyssey::Element::addFacet FacetPtr  facet  ) 
 

Add a new facet to this Element.

void Odyssey::Element::addStateListener StateListener listener  ) 
 

Adds a new element state listener.

void Odyssey::Element::clearChildren  ) 
 

Removes all the children from this Element.

void Odyssey::Element::clearFacets  ) 
 

Clears all facets from this Element.

void Odyssey::Element::clearStateListeners  ) 
 

Removes all the state listeners.

void Odyssey::Element::clearStates  ) 
 

Removes all the currently contained states (except the default state).

void Odyssey::Element::clearUserData  ) 
 

Clears all the user data for this Element.

bool Odyssey::Element::containsChild const String name  )  const
 

Check if a child with this name exists in this Element.

bool Odyssey::Element::containsUserData const String name  )  const
 

Returns true if the user data entry exists.

void Odyssey::Element::create  ) 
 

Creates the Element and its facets.

This function creates the Element, which forwards this to all facets. This does not set the Element to active, nor does it cause an update request.

static void Odyssey::Element::createAll Element element  )  [static]
 

static void Odyssey::Element::createAll ElementPtr  element  )  [static]
 

Creates all elements in the hierarchy.

This function traverses the hierarchy of Elements and children in order and creates each one.

Parameters:
element the top-level element to start the traversal

ElementPtr Odyssey::Element::createChild const String typeID,
const String name
 

Adds a new child with the given typeID and name in the ModelManager.

ElementPtr Odyssey::Element::createChild const String name  ) 
 

Adds a new child with the given name in the ModelManager.

void Odyssey::Element::createState const String name  ) 
 

Creates a new state with the given name, or fails silently if the state already exists.

This function will create a new state with the given name, or if the state already exists it will do nothing. In the case that a new state is created, and there is no other states but the default state, this newly-created state becomes the current state of the Element.

Parameters:
name the name for the new state

void Odyssey::Element::destroy  ) 
 

Destroys the element and its facets.

This function destroys the Element, which forwards this call to all the facets. This does not remove any facets or data, nor does it affect any statuses within the element except:

  • Update requests are cancelled
  • Active status is set to false

static void Odyssey::Element::destroyAll Element element  )  [static]
 

static void Odyssey::Element::destroyAll ElementPtr  element  )  [static]
 

Destroys all elements in the hierarchy.

This function traverses the hierarchy of Elements and children in order and destroys each one.

Parameters:
element the top-level element to start the traversal

bool Odyssey::Element::getActive  )  const
 

Returns the current status of the Element. True means active.

Element* Odyssey::Element::getChild size_t  index  )  const
 

Returns the child at the given internal index.

size_t Odyssey::Element::getChildCount  )  const
 

Returns the number of children.

ConstChildIterator Odyssey::Element::getChildIterator  )  const
 

Returns an iterator over the Element's children.

ChildIterator Odyssey::Element::getChildIterator  ) 
 

Returns an iterator over the Element's children.

ConstUserDataIterator Odyssey::Element::getConstUserDataIterator  )  const
 

Returns an iterator over all of the user data of the Element.

boost::optional<String> Odyssey::Element::getCurrentState  )  const
 

Returns the name of the current state.

This function uses the boost optional argument to return the name of the current state. The optional is not initialized if the Element contains only the default state. In that case !getCurrentState would be true.

ElementState* Odyssey::Element::getElementState  )  const [protected]
 

FacetPtr Odyssey::Element::getFacet size_t  index  )  const
 

Returns the facet at the given index.

size_t Odyssey::Element::getFacetCount  )  const
 

Returns the number of facets.

ConstFacetIterator Odyssey::Element::getFacetIterator  )  const
 

Returns an iterator over the Element's facets.

FacetIterator Odyssey::Element::getFacetIterator  ) 
 

Returns an iterator over the Element's facets.

MessageQueue& Odyssey::Element::getMessageQueue  ) 
 

Gives access to this element's internal message queue.

const String& Odyssey::Element::getName  )  const
 

Returns the name of the Element.

Element* Odyssey::Element::getParent  )  const
 

Returns the parent of this Element, or 0 if there isn't one.

Variable Odyssey::Element::getUserData const String name  )  const
 

Returns the value of the variable with the given name.

UserDataIterator Odyssey::Element::getUserDataIterator  ) 
 

Returns an iterator over all of the user data of the Element.

bool Odyssey::Element::isCreated  ) 
 

This function returns true if the call the create completed successfully.

virtual bool Odyssey::Element::onAdding Manager< ElementPtr > &   )  const [virtual]
 

virtual std::pair<bool,Variable> Odyssey::Element::onMessage const Message msg  )  [protected, virtual]
 

This event is called when a message needs to be handled (it is processed).

Implements Odyssey::MessageListener.

virtual void Odyssey::Element::onMessagePosted  )  [protected, virtual]
 

This event occurs when a message is posted to the message queue.

Implements Odyssey::MessageListener.

virtual void Odyssey::Element::onNotify Model model  )  [protected, virtual]
 

Implements Odyssey::ModelListener.

virtual void Odyssey::Element::onRemoved MessageQueue queue  )  [protected, virtual]
 

This event is called when this listener is removed as a listener from the message queue.

Implements Odyssey::MessageListener.

virtual bool Odyssey::Element::onRemoving Manager< ElementPtr > &   )  const [virtual]
 

static void Odyssey::Element::postMessageToAll Element element,
const Message msg
[static]
 

static void Odyssey::Element::postMessageToAll ElementPtr  element,
const Message msg
[static]
 

Posts a message to all elements in the hierarchy.

This function traverses the hierarchy of Elements and children in order and posts a message to each one.

Parameters:
element the top-level element to start the traversal

void Odyssey::Element::removeChild size_t  index  ) 
 

Removes a child from the index.

void Odyssey::Element::removeChild Element element  ) 
 

Removes a child from this Element.

void Odyssey::Element::removeFacet Facet facet  ) 
 

Removed the given facet.

void Odyssey::Element::removeFacet size_t  index  ) 
 

Removed the given facet.

void Odyssey::Element::removeState const String name,
const String newCurrent
 

Removes the state with the given name.

This function removes the given state, and instates the new current state as the one with the given name.

Parameters:
name the state to remove
newCurrent the name of the state to make the current state

void Odyssey::Element::removeState const String name  ) 
 

Removes the state with the given name.

The state with the given name is removed from this Element. The current state will be the next available state, or the default is none is found. The order of the states is undefined.

Parameters:
name the name of the state to remove

void Odyssey::Element::removeStateListener StateListener listener  ) 
 

Removes the state listener from the element.

void Odyssey::Element::removeUserData const String name  ) 
 

Removes the variable with the given name.

static void Odyssey::Element::sendMessageToAll Element element,
const Message msg
[static]
 

static void Odyssey::Element::sendMessageToAll ElementPtr  element,
const Message msg
[static]
 

Sends a message to all elements in the hierarchy.

This function traverses the hierarchy of Elements and children in order and sends a message to each one.

Parameters:
element the top-level element to start the traversal

void Odyssey::Element::sendMessageToFacet size_t  index,
const Message msg
 

Send a message to the given facet, and doesn't return until it is processed.

void Odyssey::Element::setActive bool  active = true,
bool  cancelUpdates = true
 

Activates or deactivates the element.

This function sets the element to active or deactive. Active elements are the elements that are being simulated.

Parameters:
active true if the element should be activated
cancelUpdates if true all pending updates are cancelled

static void Odyssey::Element::setActiveAll Element element,
bool  active
[static]
 

static void Odyssey::Element::setActiveAll ElementPtr  element,
bool  active
[static]
 

Sets the active state of all elements in the hierarchy.

This function traverses the hierarchy of Elements and children in order and sets each active state each one.

Parameters:
element the top-level element to start the traversal

void Odyssey::Element::setCurrentState const String name  ) 
 

Sets the current state to the state with the given name.

void Odyssey::Element::setDynamicFacet size_t  index,
const String typeID
 

Uses dynamic class construction to set the facet at the given index.

void Odyssey::Element::setFacet size_t  index,
FacetPtr  facet
 

Sets the facet at the given index.

void Odyssey::Element::setName const String name  ) 
 

Sets the name for this element.

void Odyssey::Element::setUserData const String name,
const Variable value
 

Sets the user data for a given name.

This function sets the variable for the given name to the given value.

Parameters:
name the name of the variable
value the value of the variable

virtual void Odyssey::Element::update  )  [virtual]
 

Updates the element.


Friends And Related Function Documentation

friend class ElementBuilder [friend]
 

friend class ElementManager [friend]
 


Member Data Documentation

bool Odyssey::Element::_active [protected]
 

ChildList Odyssey::Element::_children [protected]
 

std::set<Element*> Odyssey::Element::_childSet [protected]
 

bool Odyssey::Element::_created [protected]
 

String Odyssey::Element::_name [protected]
 

Element* Odyssey::Element::_parent [protected]
 

MessageQueue Odyssey::Element::_queue [protected]
 


The documentation for this class was generated from the following file:
Generated on Sun Jan 7 01:18:52 2007 for Odyssey Meta-Engine by  doxygen 1.4.6-NO