00001 // This is core/vgui/vgui_message.h 00002 #ifndef vgui_message_h_ 00003 #define vgui_message_h_ 00004 //: 00005 // \file 00006 // \author fsm 00007 // \brief Used to send messages from observables to observers. 00008 // 00009 // \verbatim 00010 // Modifications 00011 // pcp - I removed the type and user fields and replaced them with 00012 // a vcl_string. this is because I think the types of message that 00013 // will be sent are much more diverse than the event types 00014 // and so shouldn't follow that model. It is more difficult 00015 // to create a unique user tag than it is to put a different msg into the 00016 // vcl_string. 00017 // Also I have changed the pointer to a vgui_observable to a void* 00018 // This is because the observable class doesn't contain any useful info 00019 // as far as the observer is concerned and a static cast to another class 00020 // (usually some tableau subclass) would be necessary - and would be 00021 // based on the contents of the message. Observable is only useful as a 00022 // mixin class to provide observer management. I don't think it should 00023 // actually store observers though as some classes may not store their 00024 // observers locally. 00025 // 00026 // fsm - I have a license from pcp to put them back in, so I might do that 00027 // without warning. 00028 // 00029 // fsm - now I've done it. 00030 // 10-SEP-2004 Peter Vanroose Inlined all 1-line methods in class decl 00031 // \endverbatim 00032 00033 //: Used to send messages from observables to observers. 00034 // 00035 // example : 00036 // 00037 // \code 00038 // class sender : public vgui_observable 00039 // { 00040 // static const char begin[]; 00041 // static const char end[]; 00042 // void f() 00043 // { 00044 // vcl_string moo="moo moo moo"; 00045 // vgui_message m; 00046 // m.from = this; 00047 // m.user = sender::begin; 00048 // m.data = &moo; 00049 // notify(m); 00050 // } 00051 // void g() 00052 // { 00053 // vgui_message m; 00054 // m.from = this; 00055 // m.user = sender::end; 00056 // m.data = 0; 00057 // notify(m); 00058 // } 00059 // }; 00060 // 00061 // class receiver : public vgui_observer 00062 // { 00063 // void update(const vgui_message &m) 00064 // { 00065 // if (m.user == sender::begin) 00066 // { 00067 // vcl_string *s = static_cast<vcl_string*>(m.data); 00068 // vcl_cerr << "begin : " << *s << vcl_endl; 00069 // } 00070 // else if (m.user == sender::end) 00071 // { 00072 // sender *s = static_cast<sender*>(m.from); 00073 // vcl_cerr << "end\n"; 00074 // } 00075 // else 00076 // { 00077 // // dunno 00078 // } 00079 // } 00080 // }; 00081 // \endcode 00082 class vgui_message 00083 { 00084 public: 00085 vgui_message() : from(0), user(0), data(0) {} 00086 00087 //: Pointer to sender. 00088 // When the message was broadcast from a vgui_observer 00089 // via the notify() method, this will point to the observer. 00090 const void *from; 00091 00092 //: This field must uniquely identify the type of message sent. 00093 // Usually it will point to some static POD somewhere. 00094 const void *user; 00095 00096 //: Extra data can be packaged into this. 00097 // It is up to the sender of the message to ensure that 'data' can be 00098 // safely cast to whatever the receiver expects when receiving a message 00099 // with a particular value of 'user' set. 00100 const void *data; 00101 }; 00102 00103 #endif // vgui_message_h_