notifier.h

Go to the documentation of this file.
00001 /*
00002  * notifier.h
00003  *
00004  * Notified type safe function pointer class.
00005  *
00006  * Portable Tools Library
00007  *
00008  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Windows Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Contributor(s): ______________________________________.
00025  *
00026  * $Revision: 21788 $
00027  * $Author: rjongbloed $
00028  * $Date: 2008-12-11 23:42:13 -0600 (Thu, 11 Dec 2008) $
00029  */
00030 
00031 #ifndef PTLIB_NOTIFIER_H
00032 #define PTLIB_NOTIFIER_H
00033 
00034 #include <ptlib.h>
00035 #include <ptlib/smartptr.h>
00036 
00038 // General notification mechanism from one object to another
00039 
00062 class PNotifierFunction : public PSmartObject
00063 {
00064   PCLASSINFO(PNotifierFunction, PSmartObject);
00065 
00066   public:
00068     PNotifierFunction(
00069       void * obj    
00070     ) { object = PAssertNULL(obj); }
00071 
00075     virtual void Call(
00076       PObject & notifier,  
00077       INT extra            
00078     ) const = 0;
00079 
00080   protected:
00081     // Member variables
00083     void * object;
00084 };
00085 
00086 
00105 class PNotifier : public PSmartPointer
00106 {
00107   PCLASSINFO(PNotifier, PSmartPointer);
00108 
00109   public:
00111     PNotifier(
00112       PNotifierFunction * func = NULL   
00113     ) : PSmartPointer(func) { }
00114 
00120     virtual void operator()(
00121       PObject & notifier,  
00122       INT extra            
00123     ) const {
00124       if (PAssertNULL(object) != NULL)
00125         ((PNotifierFunction*)object)->Call(notifier,extra);
00126     }
00127 };
00128 
00129 
00153 #define PDECLARE_NOTIFIER(notifier, notifiee, func) \
00154   class func##_PNotifier : public PNotifierFunction { \
00155     public: \
00156       func##_PNotifier(notifiee * obj) : PNotifierFunction(obj) { } \
00157       virtual void Call(PObject & note, INT extra) const \
00158         { ((notifiee*)object)->func((notifier &)note, extra); } \
00159   }; \
00160   friend class func##_PNotifier; \
00161   virtual void func(notifier & note, INT extra)
00162 
00171 #define PCREATE_NOTIFIER2(obj, func) PNotifier(new func##_PNotifier(obj))
00172 
00181 #define PCREATE_NOTIFIER(func) PCREATE_NOTIFIER2(this, func)
00182 
00183 
00184 #endif // PTLIB_NOTIFIER_H
00185 
00186 
00187 // End Of File ///////////////////////////////////////////////////////////////

Generated on Thu May 27 01:36:48 2010 for PTLib by  doxygen 1.4.7