00001 00032 #ifndef LL_LLMEMBERLISTENER_H 00033 #define LL_LLMEMBERLISTENER_H 00034 00035 #include "llevent.h" 00036 00037 // T *mPtr is the object that this listener manipulates 00038 template <class T> 00039 class LLMemberListener : public LLSimpleListener 00040 { 00041 public: 00042 LLMemberListener() : mPtr(NULL), mRegisteredName() { } 00043 00044 void registerListener(T *pointer, const LLString& register_name) 00045 { 00046 mPtr = pointer; 00047 mRegisteredName = register_name; 00048 pointer->registerEventListener(register_name, this); 00049 } 00050 00051 // This is what you have to override to handle this event 00052 virtual bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata) = 0; 00053 00054 T *mPtr; 00055 LLString mRegisteredName; 00056 }; 00057 00058 // Example usage: 00059 00060 // (in header) 00061 00062 // class T { 00063 // class LLDoTest : public LLMemberListener<LLInventoryView> 00064 // { 00065 // bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata); 00066 // }; 00067 // LLDoTest mDoTest; 00068 // } 00069 00070 // (in cpp) 00071 00072 // T::T() { 00073 // mDoTest.registerListener(this, "T.Test"); 00074 // } 00075 // 00076 // T::LLDoTest::handleEvent(LLPointer<LLEvent> event, const LLSD& userdata) 00077 // { 00078 // T *self = mPtr; 00079 // ... 00080 // } 00081 00082 #endif // LL_LLMEMBERLISTENER_H