Object. More...

#include <robject.h>

Collaboration diagram for RObject:
[legend]

Public Member Functions

 RObject (const RString &name=RString::Null)
 
int Compare (const RObject &obj) const
 
RString GetName (void) const
 
virtual void HandlerNotFound (const RNotification &notification)
 
virtual RCString GetClassName (void) const
 
void PostNotification (const hNotification handle)
 
void PostNotification (const RCString &name)
 
template<class T >
void PostNotification (const hNotification handle, T data)
 
template<class T >
void PostNotification (const RCString &name, T data)
 
void InsertObserver (tNotificationHandler handler, const hNotification handle, RObject *object)
 
void InsertObserver (tNotificationHandler handler, const RCString &name, RObject *object)
 
void InsertObserver (tNotificationHandler handler, const hNotification handle)
 
void InsertObserver (tNotificationHandler handler, const RCString &name)
 
void InsertObserver (tNotificationHandler handler, RObject *object)
 
void InsertObserver (tNotificationHandler handler)
 
void DeleteObserver (void)
 
void DeleteObserver (const hNotification handle, RObject *object)
 
void DeleteObserver (const RCString &name, RObject *object)
 
hNotification GetNotificationHandle (const RCString &name) const
 
RCString GetNotificationName (const hNotification handle) const
 
virtual ~RObject (void)
 

Protected Attributes

RString Name
 

Private Attributes

void * Handlers
 

Detailed Description

Object.

The RObject class provides a representation for a generic object that can send and receive notifications. The deriving objects should overload the GetClassName method.

class MyObject : public RObject
{
public:
MyObject(const RString& name) : RObject(name)
{
InsertObserver(HANDLER(MyObject::Handle),"Example");
}
virtual RCString GetClassName(void) const {return("MyObject");}
void Handle(const RNotification& notification)
{
cout<<"From "<<notification.GetName()<<" : "<<GetData<long>(notification)<<endl;
}
};
int main(int argc, char *argv[])
{
MyObject Obj1("Object 1");
MyObject Obj2("Object 2");
}

It may append that a call to a method InsertObserver does not work well when objects inheriting from RObject also inherit from other objects libraries (such as Qt). The results is that the 'this' may not point to the real address. To avoid this, you must explicitly cast 'this':

MyObject(const RString& name) : RObject(name)
{
reinterpret_cast<RObject*>(this)->InsertObserver(HANDLER(MyObject::Handle),"Example");
}

Constructor & Destructor Documentation

RObject ( const RString name = RString::Null)

Constructor of the object.

Parameters
nameName given to the object.
virtual ~RObject ( void  )
virtual

Destruct the object.

Member Function Documentation

int Compare ( const RObject obj) const

Compare method used by R::RContainer.

Parameters
objObject to compare with.
RString GetName ( void  ) const

Get the name of the object.

virtual void HandlerNotFound ( const RNotification notification)
virtual

This is the handler that is called when an object does not find any handler for a sended notification. By default, it prints the name of the message.

Parameters
notificationNotification.
virtual RCString GetClassName ( void  ) const
virtual

Get the name of the class of the object.

void PostNotification ( const hNotification  handle)

Post a notification to the notification center.

Parameters
handleHandle of the notification.
void PostNotification ( const RCString name)

Post a notification to the notification center.

Parameters
nameName of the notification.
void PostNotification ( const hNotification  handle,
data 
)

Post a notification to the notification center.

Template Parameters
TTYpe of the data to post with the notification.
Parameters
handleHandle of the notification.
dataData associated to the notification.
void PostNotification ( const RCString name,
data 
)

Post a notification to the notification center.

Template Parameters
TTYpe of the data to post with the notification.
Parameters
nameName of the notification.
dataData associated to the notification.
void InsertObserver ( tNotificationHandler  handler,
const hNotification  handle,
RObject object 
)

Add a handler for a particular notification for a particular object.

Parameters
handlerHandler of the notification.
handleHandle of the notification.
objectObject posting the notification.
Warning
The same combination of (handler,handle,object) can be inserted multiple times.
void InsertObserver ( tNotificationHandler  handler,
const RCString name,
RObject object 
)

Add a handler for a particular notification for a particular object.

Parameters
handlerHandler of the notification.
nameName of the notification.
objectObject emitting the notification.
Warning
The same combination of (handler,name,object) can be inserted multiple times.
void InsertObserver ( tNotificationHandler  handler,
const hNotification  handle 
)

Add a handler for a particular notification of every object.

Parameters
handlerHandler of the notification.
handleHandle of the notification.
Warning
The same combination of (handler,handle) can be inserted multiple times.
void InsertObserver ( tNotificationHandler  handler,
const RCString name 
)

Add a handler for a particular notification of every object.

Parameters
handlerHandler of the notification.
nameName of the notification.
Warning
The same combination of (handler,name) can be inserted multiple times.
void InsertObserver ( tNotificationHandler  handler,
RObject object 
)

Add a handler for every notification of a particular object.

Parameters
handlerHandler of the notification.
objectObject posting the notification.
Warning
The same combination of (handler,object) can be inserted multiple times.
void InsertObserver ( tNotificationHandler  handler)

Add a handler for every notification of every object.

Parameters
handlerHandler of the notification.
Warning
The same handler can be inserted multiple times.
void DeleteObserver ( void  )

Delete the object as observer.

void DeleteObserver ( const hNotification  handle,
RObject object 
)

Delete a given handler.

Parameters
handleHandle of the notification.
objectObject which notifications must be handle. Several possibilities exists:
  1. handle is not null, but object is. All handlers defined for the particular notification are deleted.
  2. handle is null, but object isn't. All handlers defined for the object are deleted.
  3. handle and object are null. All default handlers are deleted.
void DeleteObserver ( const RCString name,
RObject object 
)

Delete a given handler.

Parameters
nameName of the notification to handle.
objectObject which notifications must be handle. Several possibilities exists:
  1. name is not null, but object is. All handlers defined for the particular notification are deleted.
  2. name is null, but object isn't. All handlers defined for the object are deleted.
  3. name and object are null. All default handlers are deleted.
hNotification GetNotificationHandle ( const RCString name) const

Get a handle for a given notification.

Parameters
nameName of the notification.
Returns
Handle.
RCString GetNotificationName ( const hNotification  handle) const

Get the name of a notification.

Parameters
handleHandle of the notification.

Field Documentation

void* Handlers
private

Handlers of the object.

RString Name
protected

Name of the object.