00001 /* 00002 * Copyright (c) 2001 The AUTHORS 00003 * Romeu Andre' Pieritz, Ph.D. - romeu_pieritz@hotmail.com 00004 * Rafael Mendes, Eng. – mendes_rafael@yahoo.com 00005 * Rodrigo Ferraz de Andrade, Eng. – rferraz@iname.com 00006 * All rights reserved. 00007 * 00008 * Permission to use, copy and distribute this software and its 00009 * documentation for educational and personal use, without fee is hereby granted, 00010 * provided that the above copyright notice and the following 00011 * two paragraphs appear in all copies of this software. 00012 * 00013 * IN NO EVENT SHALL THE AUTHORS BE LIABLE TO ANY PARTY FOR 00014 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 00015 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS 00016 * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00017 * 00018 * THE AUTHORS SPECIFICALLY DISCLAIMS ANY WARRANTIES, 00019 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00020 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HERE UNDER IS 00021 * ON AN "AS IS" BASIS, AND THE AUTHORS HAVE NO OBLIGATION TO 00022 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 00023 * 00024 * SINMEC Lab. - CFD Sinflow Project - http://www.sinmec.ufsc.br/cfd 00025 */ 00026 00027 00028 // File Define 00029 #ifndef __CSFL_SYS_CORE_ACTION_H__ 00030 #define __CSFL_SYS_CORE_ACTION_H__ 00031 00032 00033 // Include 00034 #include <csfl/sys/core/sflobject.h> 00035 00036 00037 // Namespace 00038 namespace csfl { 00039 00040 00041 //============================================================================== 00042 // template IMethod 00043 //============================================================================== 00044 00045 class IMethod 00046 { 00047 // ----------------------------------------------------------------------- C & D 00048 public: 00049 IMethod( void *_receiver = NULL ) : 00050 receiver( _receiver ) 00051 {} 00052 00053 // -------------------------------------------------------------------- Receiver 00054 public: 00055 void *receiver; 00056 }; 00057 00058 //============================================================================== 00059 // template IMethod1Of 00060 //============================================================================== 00061 00062 template <class H, class T1> 00063 class IMethod1Of : public IMethod 00064 { 00065 public: 00066 typedef void (H::*Method)( T1 ); 00067 00068 // ----------------------------------------------------------------------- C & D 00069 public: 00070 IMethod1Of( void *_receiver = NULL, Method _method = NULL ) : 00071 IMethod( _receiver ), 00072 method( _method ) 00073 {} 00074 00075 // ----------------------------------------------------------------------------- 00076 public: 00077 bool Call( T1 ) const; 00078 00079 // ----------------------------------------------------------------------------- 00080 public: 00081 IMethod1Of<H,T1> & operator = ( const IMethod1Of<H,T1> & ); 00082 00083 inline bool operator == ( const IMethod1Of<H,T1> &_method ) const 00084 { return receiver==_method.receiver && method==_method.method; } 00085 00086 // ----------------------------------------------------------------------------- 00087 public: 00088 Method method; 00089 }; 00090 00091 //============================================================================== 00092 // template class IActionBaseOf 00093 //============================================================================== 00094 00095 template <class P_Method> 00096 class IActionBaseOf 00097 { 00098 // ----------------------------------------------------------------------- C & D 00099 public: 00100 IActionBaseOf() : 00101 method() 00102 {} 00103 00104 IActionBaseOf( const P_Method &_method ) : 00105 method( _method ) 00106 {} 00107 00108 // ---------------------------------------------------------------------- Method 00109 public: 00110 IActionBaseOf<P_Method> & Set( const P_Method & ); 00111 00112 bool IsAssigned() const 00113 { return method.receiver != 0 && method.method != 0; } 00114 00115 public: 00116 void Clear() 00117 { method.receiver = 0; method.method = NULL; } 00118 00119 public: // Attributes 00120 P_Method method; 00121 00122 // --------------------------------------------------------------------- Compare 00123 public: 00124 bool operator ==( const IActionBaseOf<P_Method> &_action ) const 00125 { return method == _action.method; } 00126 bool operator ==( const P_Method &_method ) const 00127 { return method == _method; } 00128 }; 00129 00130 // IMethod1Of ================================================================== 00131 00132 template <class H, class T1> 00133 bool IMethod1Of<H,T1>::Call( T1 _arg1 ) const 00134 { 00135 bool result( receiver && method ); 00136 if (result) 00137 (((H *)receiver)->*method)( _arg1 ); 00138 return result; 00139 } 00140 00141 template <class H, class T1> 00142 IMethod1Of<H,T1> & IMethod1Of<H,T1>::operator = ( 00143 const IMethod1Of<H,T1> & _method ) 00144 { 00145 receiver = _method.receiver; 00146 method = _method.method; 00147 return *this; 00148 } 00149 00150 template <class C, class R, class T1> 00151 inline IMethod1Of<ISFLObject,T1> ExecuteMethod( void (C::*method)(T1), R *receiver ) 00152 { 00153 IMethod1Of<ISFLObject,T1> result; 00154 C *cReceiver = receiver; 00155 result.receiver = cReceiver; 00156 memcpy( &result.method, &method, sizeof result.method ); 00157 return result; 00158 } 00159 00160 //============================================================================== 00161 // template class IAction1Of<Handler> 00162 //============================================================================== 00163 00164 template <class H, class T1> 00165 class IAction1Of : 00166 public IActionBaseOf< IMethod1Of<H,T1> > 00167 { 00168 // ----------------------------------------------------------------------- C & D 00169 public: 00170 IAction1Of() : 00171 IActionBaseOf< IMethod1Of<H,T1> >() 00172 {} 00173 00174 IAction1Of( const IMethod1Of<H,T1> &_method ) : 00175 IActionBaseOf< IMethod1Of<H,T1> >( _method ) 00176 {} 00177 00178 // --------------------------------------------------------------------- Methods 00179 public: 00180 bool Call( T1 _arg1 ) const 00181 { return method.Call( _arg1 ); } 00182 00183 // -------------------------------------------------------------------- Operator 00184 public: 00185 IActionBaseOf< IMethod1Of<H,T1> > & operator =( 00186 const IMethod1Of<H,T1> &_method ) 00187 { return Set( _method ); } 00188 }; 00189 00190 00191 // Implementations ============================================================= 00192 00193 template <class P_Method> 00194 IActionBaseOf<P_Method> & IActionBaseOf<P_Method>::Set( 00195 const P_Method &_method ) 00196 { 00197 method = _method; 00198 return *this; 00199 } 00200 00201 00202 00203 typedef IAction1Of<ISFLObject, ISFLObject *> IAction; 00204 00205 00206 } // csfl namespace 00207 00208 #endif // __CSFL_SYS_CORE_ACTION_H__ 00209
CFD Project
|
Documents |
Downloads |
Contact us |
Use Terms |
|
|||
© SINMEC/EMC/UFSC,
2001. |
All rights
reserved. |
Last Update: Jan. 18, 2002 |
|