llcallbacklisth.h

Go to the documentation of this file.
00001 
00033 #ifndef LL_LLCALLBACKLISTH_H
00034 #define LL_LLCALLBACKLISTH_H
00035 
00036 #include "doublelinkedlist.h"
00037 
00038 typedef void(*LLHandleCallback)(void** handle );
00039 
00040 class LLCallbackNodeH;
00041 
00042 class LLCallbackListH
00043 {
00044 protected:
00045         class LLCallbackNodeH
00046         {
00047         public:
00048                 LLCallbackNodeH( LLHandleCallback cb, void** h ) : mCallback(cb), mHandle(h) {}
00049                 void    call()                                  { (*mCallback)(mHandle); }
00050 
00051         public:
00052                 LLHandleCallback        mCallback;
00053                 void**  mHandle;
00054         };
00055 
00056 public:
00057         ~LLCallbackListH()
00058                 { mCallbackList.deleteAllData(); }
00059 
00060         void addFunction( LLHandleCallback func, void** handle = NULL )                 // register a callback, which will be called as func(data)
00061                 { mCallbackList.addDataAtEnd( new LLCallbackNodeH( func, handle ) ); }
00062 
00063         BOOL containsFunction( LLHandleCallback func, void** handle = NULL )    // true if list already contains the function/data pair
00064                 {
00065                         for( LLCallbackNodeH *p = mCallbackList.getFirstData(); p; p = mCallbackList.getNextData() )
00066                         {
00067                                 if( p->mCallback == func && p->mHandle == handle)
00068                                 {
00069                                         return TRUE;
00070                                 }
00071                         }
00072                         return FALSE;
00073                 }
00074 
00075         BOOL deleteFunction( LLHandleCallback func, void** handle = NULL )              // removes the first instance of this function/data pair from the list, false if not found
00076                 {
00077                         for( LLCallbackNodeH *p = mCallbackList.getFirstData(); p; p = mCallbackList.getNextData() )
00078                         {
00079                                 if( p->mCallback == func && p->mHandle == handle)
00080                                 {
00081                                         mCallbackList.deleteCurrentData();
00082                                         return TRUE;
00083                                 }
00084                         }
00085                         return FALSE;
00086                 }
00087 
00088         void callFunctions()                                                                                                    // calls all functions
00089                 {
00090                         for( LLCallbackNodeH *p = mCallbackList.getFirstData(); p; p = mCallbackList.getNextData() )
00091                         {
00092                                 p->call();
00093                         }
00094                 }
00095 
00096         void deleteAllFunctions()
00097                 { mCallbackList.deleteAllData(); }
00098 
00099 protected:
00100         LLDoubleLinkedList<LLCallbackNodeH>     mCallbackList;
00101 };
00102 
00103 #endif  // LL_LLCALLBACKLISTH_H

Generated on Thu Jul 1 06:08:20 2010 for Second Life Viewer by  doxygen 1.4.7