Public Member Functions | Public Attributes
vgui_message Class Reference

Used to send messages from observables to observers. More...

#include <vgui_message.h>

List of all members.

Public Member Functions

 vgui_message ()

Public Attributes

const void * from
 Pointer to sender.
const void * user
 This field must uniquely identify the type of message sent.
const void * data
 Extra data can be packaged into this.

Detailed Description

Used to send messages from observables to observers.

example :

 class sender : public vgui_observable
 {
   static const char begin[];
   static const char end[];
   void f()
   {
     vcl_string moo="moo moo moo";
     vgui_message m;
     m.from = this;
     m.user = sender::begin;
     m.data = &moo;
     notify(m);
   }
   void g()
   {
     vgui_message m;
     m.from = this;
     m.user = sender::end;
     m.data = 0;
     notify(m);
   }
 };

 class receiver : public vgui_observer
 {
   void update(const vgui_message &m)
   {
     if (m.user == sender::begin)
     {
       vcl_string *s = static_cast<vcl_string*>(m.data);
       vcl_cerr << "begin : " << *s << vcl_endl;
     }
     else if (m.user == sender::end)
     {
       sender *s = static_cast<sender*>(m.from);
       vcl_cerr << "end\n";
     }
     else
     {
       // dunno
     }
   }
 };

Definition at line 82 of file vgui_message.h.


Constructor & Destructor Documentation

vgui_message::vgui_message ( ) [inline]

Definition at line 85 of file vgui_message.h.


Member Data Documentation

const void* vgui_message::data

Extra data can be packaged into this.

It is up to the sender of the message to ensure that 'data' can be safely cast to whatever the receiver expects when receiving a message with a particular value of 'user' set.

Definition at line 100 of file vgui_message.h.

const void* vgui_message::from

Pointer to sender.

When the message was broadcast from a vgui_observer via the notify() method, this will point to the observer.

Definition at line 90 of file vgui_message.h.

const void* vgui_message::user

This field must uniquely identify the type of message sent.

Usually it will point to some static POD somewhere.

Definition at line 94 of file vgui_message.h.


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