#include <base.h>

Public Member Functions | |
| Base (const std::string &name="base") | |
| Constructor. | |
| void | SetName (const std::string &name) |
| Sets the name of this instance. | |
| const std::string & | GetName () const |
| Returns the name of this instance. | |
| void | SetUniqueId (const UniqueId &id) |
| This sets the unique ID, for general purposes this should not be used. | |
| const UniqueId & | GetUniqueId () const |
| This class returns an instance the the UniqueID. | |
| virtual void | OnMessage (MessageData *data) |
| Override to receive messages. | |
| void | AddSender (Base *sender) |
| Receive all messages from the supplied sender instance. | |
| void | RemoveSender (Base *sender) |
| Stop receiving messages from the supplied sender instance. | |
| void | SendMessage (const std::string &message="", void *data=0) |
| Send a message to any instances that are subscribed to this instance. | |
Protected Member Functions | |
| virtual | ~Base () |
| Destructor. | |
Classes | |
| struct | MessageData |
| Data that gets passed through SendMessage. More... | |
The Base class handles things that are required by most of the dtCore classes such as naming, RTTI, and message passing. To name an instance, call SetName() or pass it to the constructor.
Inter-class message passing is handled by "subscribing" the instance to a sender using AddSender(). Anytime the sender calls SendMessage(), the receiver class' OnMessage() will get triggered. The MessageData that gets passed to OnMessage() contains a pointer to the sender, and optionally, a text message and pointer to user data.
This class is also reference counted using the osg::Referenced class. To safely keep the reference count up-to-date, pointers to Base classes should be stored in a RefPtr template. For example:
RefPtr<Base> mPointerToMyBase;
| dtCore::Base::Base | ( | const std::string & | name = "base" |
) |
Constructor.
| name | the instance name |
| dtCore::Base::~Base | ( | ) | [protected, virtual] |
Destructor.
| void dtCore::Base::SetName | ( | const std::string & | name | ) |
Sets the name of this instance.
| name | the new name |
| const std::string & dtCore::Base::GetName | ( | ) | const |
Returns the name of this instance.
Reimplemented in dtCore::ShaderParameter.
| void dtCore::Base::SetUniqueId | ( | const UniqueId & | id | ) | [inline] |
This sets the unique ID, for general purposes this should not be used.
| const UniqueId& dtCore::Base::GetUniqueId | ( | ) | const [inline] |
This class returns an instance the the UniqueID.
| virtual void dtCore::Base::OnMessage | ( | MessageData * | data | ) | [inline, virtual] |
Override to receive messages.
Reimplemented in dtABC::Action, dtABC::BaseABC, dtABC::StateManager, dtABC::Trigger, dtABC::Widget, dtAnim::CharDrawable, dtAudio::AudioManager, dtAudio::Sound, dtCore::Camera, dtCore::EffectManager, dtCore::FlyMotionModel, dtCore::FPSMotionModel, dtCore::Recorder< RecordableT, FrameDataT >, dtCore::Scene, dtCore::ShaderManager, dtCore::ShaderParamOscillator, dtCore::Tripod, dtCore::UFOMotionModel, dtCore::WalkMotionModel, dtGame::GameManager, dtGUI::CEUIDrawable, and dtTerrain::Terrain.
| void dtCore::Base::AddSender | ( | Base * | sender | ) |
Receive all messages from the supplied sender instance.
Subscribe this instance to the supplied sender.
Any message that sender sends, will be received in the OnMessage() method.
| sender | The sender that this instance should listen to |
| void dtCore::Base::RemoveSender | ( | Base * | sender | ) |
Stop receiving messages from the supplied sender instance.
| void dtCore::Base::SendMessage | ( | const std::string & | message = "", |
|
| void * | data = 0 | |||
| ) |
Send a message to any instances that are subscribed to this instance.
Send a message to any instance thats subscribed to us.
Any supplied string or void* data will be passed to the receiver's OnMessage() method.
| message | Optional string message | |
| data | Optional pointer to user data | |
| message | Optional text message (def = "") | |
| data | Optional void pointer to any user data (def = 0) |