All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
notifier.h
Go to the documentation of this file.
/*
* notifier.h
*
* Notified type safe function pointer class.
*
* Portable Tools Library
*
* Copyright (c) 1993-1998 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Contributor(s): ______________________________________.
*
* $Revision: 24177 $
* $Author: rjongbloed $
* $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
*/
#ifndef PTLIB_NOTIFIER_H
#define PTLIB_NOTIFIER_H
#include <ptlib.h>
#include <ptlib/smartptr.h>
// General notification mechanism from one object to another
template <typename ParmType>
class PNotifierFunctionTemplate : public PSmartObject
{
PCLASSINFO(PNotifierFunctionTemplate, PSmartObject);
public:
PNotifierFunctionTemplate(
void * obj
) { object = PAssertNULL(obj); }
virtual void Call(
PObject & notifier,
ParmType extra
) const = 0;
protected:
// Member variables
void * object;
};
typedef PNotifierFunctionTemplate<INT> PNotifierFunction;
template <typename ParmType>
class PNotifierTemplate : public PSmartPointer
{
PCLASSINFO(PNotifierTemplate, PSmartPointer);
public:
PNotifierTemplate(
PNotifierFunctionTemplate<ParmType> * func = NULL
) : PSmartPointer(func) { }
virtual void operator()(
PObject & notifier,
ParmType extra
) const {
if (PAssertNULL(object) != NULL)
((PNotifierFunctionTemplate<ParmType>*)object)->Call(notifier,extra);
}
};
typedef PNotifierTemplate<INT> PNotifier;
#define PDECLARE_NOTIFIER2(notifier, notifiee, func, type) \
class func##_PNotifier : public PNotifierFunctionTemplate<type> { \
public: \
func##_PNotifier(notifiee * obj) : PNotifierFunctionTemplate<type>(obj) { } \
virtual void Call(PObject & note, type extra) const \
{ ((notifiee*)object)->func((notifier &)note, extra); } \
}; \
friend class func##_PNotifier; \
virtual void func(notifier & note, type extra)
#define PDECLARE_NOTIFIER(notifier, notifiee, func) \
PDECLARE_NOTIFIER2(notifier, notifiee, func, INT)
#define PCREATE_NOTIFIER2_EXT(obj, notifiee, func, type) PNotifierTemplate<type>(new notifiee::func##_PNotifier(obj))
#define PCREATE_NOTIFIER_EXT( obj, notifiee, func) PCREATE_NOTIFIER2_EXT(obj, notifiee, func, INT)
#define PCREATE_NOTIFIER2(func, type) PNotifierTemplate<type>(new func##_PNotifier(this))
#define PCREATE_NOTIFIER(func) PCREATE_NOTIFIER2(func, INT)
#endif // PTLIB_NOTIFIER_H
// End Of File ///////////////////////////////////////////////////////////////
PNotifierTemplate::PNotifierTemplate
PNotifierTemplate(PNotifierFunctionTemplate< ParmType > *func=NULL)
Create a new notification function smart pointer.
Definition: notifier.h:115
smartptr.h
PNotifierFunctionTemplate::object
void * object
Object instance to receive the notification function call.
Definition: notifier.h:84
PSmartPointer
This is the class for pointers to objects that use the smart pointer system.
Definition: smartptr.h:88
PNotifierFunctionTemplate::Call
virtual void Call(PObject &notifier, ParmType extra) const =0
Execute the call to the actual notification function on the object instance contained in this object...
PNotifierFunction
PNotifierFunctionTemplate< INT > PNotifierFunction
Definition: notifier.h:87
PNotifier
PNotifierTemplate< INT > PNotifier
Definition: notifier.h:136
PNotifierTemplate
The PNotifier and PNotifierFunction classes build a completely type safe mechanism for calling arbitr...
Definition: notifier.h:109
PNotifierFunctionTemplate::PNotifierFunctionTemplate
PNotifierFunctionTemplate(void *obj)
Create a notification function instance.
Definition: notifier.h:69
PAssertNULL
#define PAssertNULL(ptr)
This macro is used to assert that a pointer must be non-null.
Definition: object.h:220
PSmartObject
This is the base class for objects that use the smart pointer system.
Definition: smartptr.h:52
PNotifierFunctionTemplate
This is an abstract class for which a descendent is declared for every function that may be called...
Definition: notifier.h:63
PObject
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PNotifierTemplate::operator()
virtual void operator()(PObject &notifier, ParmType extra) const
Execute the call to the actual notification function on the object instance contained in this object...
Definition: notifier.h:124