mi32/delegate.h File Reference

Common delegate type definitions. More...

#include <mi32/stddefns.h>
#include <mi32/fastdelegate.h>
Include dependency graph for delegate.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef
fastdelegate::FastDelegate
< bool(INT32)> 
DELEGATE_BOOL_INT32
typedef
fastdelegate::FastDelegate
< bool()> 
DELEGATE_BOOL_NOPARMS
typedef
fastdelegate::FastDelegate
< bool(UINT32)> 
DELEGATE_BOOL_UINT32
typedef
fastdelegate::FastDelegate
< double()> 
DELEGATE_DOUBLE_NOPARMS
typedef
fastdelegate::FastDelegate
< ERRVALUE(bool)> 
DELEGATE_ERRVALUE_BOOL
typedef
fastdelegate::FastDelegate
< ERRVALUE(double)> 
DELEGATE_ERRVALUE_DOUBLE
typedef
fastdelegate::FastDelegate
< ERRVALUE()> 
DELEGATE_ERRVALUE_NOPARMS
typedef
fastdelegate::FastDelegate
< ERRVALUE(const POLYLINE &)> 
DELEGATE_ERRVALUE_POLYLINE
typedef
fastdelegate::FastDelegate
< const RVC::OBJITEM &()> 
DELEGATE_OBJITEM_NOPARMS
typedef
fastdelegate::FastDelegate
< void(bool)> 
DELEGATE_VOID_BOOL
typedef
fastdelegate::FastDelegate
< void(const DPOINT2D &)> 
DELEGATE_VOID_DPOINT2D
typedef
fastdelegate::FastDelegate
< void(INT32)> 
DELEGATE_VOID_INT32
typedef
fastdelegate::FastDelegate
< void(const MISTRING &)> 
DELEGATE_VOID_MISTRING
typedef
fastdelegate::FastDelegate
< void()> 
DELEGATE_VOID_NOPARMS

Detailed Description

Common delegate type definitions.

A delegate is a type-safe way to call a function without the caller knowing anything about the whether the function being called is a class method, a virtual method or a static function. This allows classes to be loosely coupled without use of virtual overrides. One common example of this is in user interface controls where a 'containing' class such as a form or dialog has functions to be called based on interaction with controls contained in the dialog. Instead of requiring a virtual override for each control, a delegate may be set when the control is created which will call a function in the containing class.

A delegate instance may be constructed for any function which matches the delegate signature, including virtual, non-virtual and static class methods as well as global functions. Construction for virtual and non-virtual class methods also requires the pointer to the class instance.

For example:

      // Class with methods to set delegates.
      class SOMECLASS {
         public:
            void SetDelegateGetSomething (
               DELEGATE_DOUBLE_NOPARMS delegate
               ) { m_DelegateGetSomething = delegate; }
            void SetDelegateNotifySomething (
               DELEGATE_VOID_NOPARMS delegate
               ) { m_DelegateNotifySomething = delegate; }
         private:
            DELEGATE_DOUBLE_NOPARMS m_DelegateGetSomething;
            DELEGATE_VOID_NOPARMS m_DelegateNotifySomething;
            // Invoke DelegateGetSomething (would be called internally to class)
            double GetSomething (
               ) { if (m_DelegateGetSomething) return (m_DelegateGetSomething(); else return (0.0); }
            // Invoke DelegateNotifySomething (would be called internally to class)
            void NotifySomething (
               ) { if (m_DelegateNotifySomething) m_DelegateNotifySomething(); }
         };
         
      // Class containing delegate methods to call.
      class TARGETCLASS {
         public:
            void Create (
               ) {
               m_SomeClass.SetDelegateGetSomething(DELEGATE_DOUBLE_NOPARMS(&TARGETCLASS::GetSomething));
               m_SomeClass.SetDelegateNotifySomething(DELEGATE_VOID_NOPARMS(this,&TARGETCLASS::OnNotifySomething));
               }
         private:
            SOMECLASS m_SomeClass;
            // Static method returning double.
            static double GetSomething ();
            // Normal method returning void.
            void OnNotifySomething ();
         };

      // Global function returning double.
      static double GlobalGetSomething ();

      void MyFunc (
         ) {
         SOMECLASS SomeClass;
         SomeClass.SetDelegateGetSomething(&GlobalGetSomething);
         ...
         }

Typedef Documentation

typedef fastdelegate::FastDelegate<bool(INT32)> DELEGATE_BOOL_INT32

Delegate for function returning bool and taking an INT32.

typedef fastdelegate::FastDelegate<bool()> DELEGATE_BOOL_NOPARMS

Delegate for function returning bool and having no parameters.

typedef fastdelegate::FastDelegate<bool(UINT32)> DELEGATE_BOOL_UINT32

Delegate for function returning bool and taking a UINT32.

typedef fastdelegate::FastDelegate<double()> DELEGATE_DOUBLE_NOPARMS

Delegate for function returning double and having no parameters.

typedef fastdelegate::FastDelegate<ERRVALUE(bool)> DELEGATE_ERRVALUE_BOOL

Delegate for function returning ERRVALUE and having "bool" parameter.

typedef fastdelegate::FastDelegate<ERRVALUE(double)> DELEGATE_ERRVALUE_DOUBLE

Delegate for function returning ERRVALUE and having "double" parameter.

Typically used for progress reporting.

typedef fastdelegate::FastDelegate<ERRVALUE()> DELEGATE_ERRVALUE_NOPARMS

Delegate for function returning ERRVALUE and having no parameters.

typedef fastdelegate::FastDelegate<ERRVALUE(const POLYLINE&)> DELEGATE_ERRVALUE_POLYLINE

Delegate for function returning ERRVALUE and taking a const POLYLINE reference.

typedef fastdelegate::FastDelegate<const RVC::OBJITEM&()> DELEGATE_OBJITEM_NOPARMS

Delegate for function returning const RVC::OBJITEM reference and taking no parameters.

typedef fastdelegate::FastDelegate<void(bool)> DELEGATE_VOID_BOOL

Delegate for function returning void and taking a bool parameter.

typedef fastdelegate::FastDelegate<void(const DPOINT2D&)> DELEGATE_VOID_DPOINT2D

Delegate for function returning void and taking a const DPOINT2D reference.

typedef fastdelegate::FastDelegate<void(INT32)> DELEGATE_VOID_INT32

Delegate for function returning void and taking a INT32 parameter.

typedef fastdelegate::FastDelegate<void(const MISTRING&)> DELEGATE_VOID_MISTRING

Delegate for function returning void and taking a const MISTRING reference.

typedef fastdelegate::FastDelegate<void()> DELEGATE_VOID_NOPARMS

Delegate for function returning void and having no parameters.


Generated on Sun Oct 7 21:26:01 2012 for TNTsdk 2012 by  doxygen 1.6.1