home *** CD-ROM | disk | FTP | other *** search
- #ifndef _ICALLBK_
- #define _ICALLBK_
- /*******************************************************************************
- * FILE NAME: icallbk.hpp *
- * *
- * DESCRIPTION: *
- * Declaration of the class(es): *
- * I0ArgCallback - 0 argument "callback object" *
- * I0ArgCallbackMemberFn - "callback object" wrapper for a C++ member *
- * callback accepting no arguments *
- * I0ArgCallbackFn - "callback object" wrapper for a plain C or C++ *
- * callback accepting no arguments *
- * I1ArgCallback - 1 argument "callback object" *
- * I1ArgCallbackMemberFn - "callback object" wrapper for a C++ member *
- * callback accepting one argument *
- * I1ArgCallbackFn - "callback object" wrapper for a plain C or C++ *
- * callback accepting one argument *
- * I2ArgCallback - 2 argument "callback object" *
- * I2ArgCallbackMemberFn - "callback object" wrapper for a C++ member *
- * callback accepting two arguments *
- * I2ArgCallbackFn - "callback object" wrapper for a plain C or C++ *
- * callback accepting two arguments *
- * *
- * COPYRIGHT: *
- * (C) Copyright IBM Corporation 1992, 1993 *
- * All Rights Reserved *
- * Licensed Materials - Property of IBM *
- * *
- * US Government Users Restricted Rights - *
- * Use, duplication, or disclosure restricted *
- * by GSA ADP Schedule Contract with IBM Corp. *
- * *
- *$Log: R:/IBMCLASS/IBASE/VCS/ICALLBK.HPV $ *
- //
- // Rev 1.2 25 Oct 1992 16:46:22 nunn
- //changed library name to ICLUI
- //
- // Rev 1.1 19 Oct 1992 16:08:42 law
- //Made callbacks reference counted.
- *******************************************************************************/
- #ifndef _IRECNT_
- #include <irefcnt.hpp>
- #endif
-
- class ICallbackBase : public IRefCounted {
- /*******************************************************************************
- * This class serves as the base for all the real callback classes. It *
- * inherits from IRefCounted in order to permit objects that use them to *
- * participate in the control of the destruction of such objects. That is, *
- * the destruction of the callbacks must be deferred until the objects that *
- * might call them no longer will do so. *
- * *
- * In addition, this class is used as a convenient place to declare some *
- * enumeration values used throughout the callback hierarchy. *
- *******************************************************************************/
- protected:
- typedef enum
- {
- optlink,
- system
- } LinkageType;
- };
-
- template < class Result >
- class I0ArgCallback : public ICallbackBase {
- /*******************************************************************************
- * This template class is used to define abstract callbacks that accept zero *
- * arguments and have return type of Result. Objects of such classes are used *
- * as arguments to various member functions in the ICLUI library that *
- * require "callbacks", or, that permit the application of user-provided code. *
- * *
- * This template class requires a single template argument: *
- * Result - return type of the "callback object" *
- * *
- * This template generates abstract superclasses. Two concrete subclass *
- * implementations are defined below: *
- * I0ArgCallbackMemberFn - wrapper for a C++ member callback of this "type" *
- * I0ArgCallbackFn - wrapper for a plain C or C++ function of *
- * this "type" *
- * *
- * Each of these classes implements the pure virtual callback f() as *
- * appropriate (by invocation of the specified callback or member function). *
- * *
- * This class has no other functions. *
- *******************************************************************************/
- public:
- virtual Result
- f ( ) const = 0;
- }; // I0ArgCallback
-
- template < class Result >
- class I0ArgCallbackFn : public I0ArgCallback<Result> {
- public:
- virtual Result
- f ( ) const
- {
- Result result;
- switch ( this->linkage )
- {
- case optlink;
- result = pOpt();
- break;
- case system:
- result = pSys();
- break;
- }
- return result;
- }
- I0ArgCallbackFn ( Result (* _Optlink p)() )
- : linkage( optlink ), pOpt( p )
- {
- }
- I0ArgCallbackFn ( Result (* _System p)() )
- : linkage( system ), pSys( p )
- {
- }
- union
- {
- Result (* _Optlink pOpt)();
- Result (* _System pSys)();
- };
- LinkageType
- linkage;
- }; // I0ArgCallbackFn
-
- template < class Class, class Result >
- class I0ArgCallbackMemberFn : public I0ArgCallback<Result> {
- public:
- virtual Result
- f ( ) const
- {
- return (object.*member)();
- }
- I0ArgCallbackMemberFn ( Class &anObject, Result (Class::*p)() )
- : object( anObject ), member( p )
- {
- }
- Class
- &object;
- Result (Class::*member)();
- }; // I0ArgCallbackMemberFn
-
- template < class Result, class Arg >
- class I1ArgCallback : public ICallbackBase {
- /*******************************************************************************
- * This template class is used to define abstract callbacks that accept one *
- * argument and have return type of Result. Objects of such classes are used *
- * as arguments to various member functions in the ICLUI library that *
- * require "callbacks", or, that permit the application of user-provided code. *
- * *
- * This template class requires two template arguments: *
- * Result - return type of the "callback object" *
- * Arg - argument type *
- * *
- * This template generates abstract superclasses. Two concrete subclass *
- * implementations are defined below: *
- * I1ArgCallbackMemberFn - wrapper for a C++ member callback of this "type" *
- * I1ArgCallbackFn - wrapper for a plain C or C++ function of *
- * this "type" *
- * *
- * Each of these classes implements the pure virtual callback f() as *
- * appropriate (by invocation of the specified callback or member function). *
- * *
- * This class has no other functions. *
- *******************************************************************************/
- public:
- virtual Result
- f ( Arg anArg ) const = 0;
- }; // I1ArgCallback
-
- template < class Result, class Arg >
- class I1ArgCallbackFn : public I1ArgCallback<Result,Arg> {
- public:
- virtual Result
- f ( Arg anArg ) const
- {
- Result result;
- switch ( this->linkage )
- {
- case optlink;
- result = pOpt( anArg );
- break;
- case system:
- result = pSys( anArg );
- break;
- }
- return result;
- }
- I1ArgCallbackFn ( Result (* _Optlink p)(Arg) )
- : linkage( optlink ), pOpt( p )
- {
- }
- I1ArgCallbackFn ( Result (* _System p)(Arg) )
- : linkage( system ), pSys( p )
- {
- }
- union
- {
- Result (* _Optlink pOpt)(Arg);
- Result (* _System pSys)(Arg);
- };
- LinkageType
- linkage;
- }; // I1ArgCallbackFn
-
- template < class Class, class Result, class Arg >
- class I1ArgCallbackMemberFn : public I1ArgCallback<Result,Arg> {
- public:
- virtual Result
- f ( Arg anArg ) const
- {
- return (object.*member)( anArg );
- }
- I1ArgCallbackMemberFn ( Class &anObject, Result (Class::*p)(Arg) )
- : object( anObject ), member( p )
- {
- }
- Class
- &object;
- Result (Class::*member)(Arg);
- }; // I1ArgCallbackMemberFn
-
- template < class Result, class Arg1, class Arg2 >
- class I2ArgCallback : public ICallbackBase {
- /*******************************************************************************
- * This template class is used to define abstract callbacks that accept two *
- * arguments and have return type of Result. Objects of such classes are used *
- * as arguments to various member functions in the ICLUI library that *
- * require "callbacks", or, that permit the application of user-provided code. *
- * *
- * This template class requires two template arguments: *
- * Result - return type of the "callback object" *
- * Arg1 - argument 1 type *
- * Arg2 - argument 2 type *
- * *
- * This template generates abstract superclasses. Two concrete subclass *
- * implementations are defined below: *
- * I2ArgCallbackMemberFn - wrapper for a C++ member callback of this "type" *
- * I2ArgCallbackFn - wrapper for a plain C or C++ function of *
- * this "type" *
- * *
- * Each of these classes implements the pure virtual callback f() as *
- * appropriate (by invocation of the specified callback or member function). *
- * *
- * This class has no other functions. *
- *******************************************************************************/
- public:
- virtual Result
- f ( Arg1 arg1,
- Arg2 arg2 ) const = 0;
- }; // I2ArgCallback
-
- template < class Result, class Arg1, class Arg2 >
- class I2ArgCallbackFn : public I2ArgCallback<Result,Arg1,Arg2> {
- public:
- virtual Result
- f ( Arg1 arg1,
- Arg2 arg2 ) const
- {
- Result result;
- switch ( this->linkage )
- {
- case optlink;
- result = pOpt( arg1, arg2 );
- break;
- case system:
- result = pSys( arg1, arg2 );
- break;
- }
- return result;
- }
- I2ArgCallbackFn ( Result (* _Optlink p)(Arg1,Arg2) )
- : linkage( optlink ), pOpt( p )
- {
- }
- I2ArgCallbackFn ( Result (* _System p)(Arg1,Arg2) )
- : linkage( system ), pSys( p )
- {
- }
- union
- {
- Result (* _Optlink pOpt)(Arg1,Arg2);
- Result (* _System pSys)(Arg1,Arg2);
- };
- LinkageType
- linkage;
- }; // I2ArgCallbackFn
-
- template < class Class, class Result, class Arg1, class Arg2 >
- class I2ArgCallbackMemberFn : public I2ArgCallback<Result,Arg1,Arg2> {
- public:
- virtual Result
- f ( Arg1 arg1,
- Arg2 arg2 ) const
- {
- return (object.*member)( arg1, arg2 );
- }
- I2ArgCallbackMemberFn ( Class &anObject, Result (Class::*p)(Arg1,Arg2) )
- : object( anObject ), member( p )
- {
- }
- Class
- &object;
- Result (Class::*member)(Arg1,Arg2);
- }; // I2ArgCallbackMemberFn
-
- #endif /* _ICALLBK_ */