00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef __METHODPROXY_HPP
00032 #define __METHODPROXY_HPP
00033
00034 #include "libecs.hpp"
00035
00036
00037 template < class CLASS, typename RET, typename ARG1 = void >
00038 class MethodProxy;
00039
00040 template < class CLASS, typename RET >
00041 class MethodProxy<CLASS,RET>
00042 {
00043 private:
00044
00045 typedef const RET (* Invoker )( CLASS* const );
00046
00047 public:
00048
00049 inline const RET operator()( CLASS* const anObject ) const
00050 {
00051 return theInvoker( anObject );
00052 }
00053
00054 inline const RET operator()( const CLASS* const anObject ) const
00055 {
00056 return theInvoker( const_cast<CLASS* const>( anObject ) );
00057 }
00058
00059 template < const RET (CLASS::*METHOD)() const >
00060 static MethodProxy create()
00061 {
00062 #if defined( LIBECS_USE_PMF_CONVERSIONS )
00063 return MethodProxy( Invoker( METHOD ));
00064 #else
00065 return MethodProxy( invoke<METHOD> );
00066 #endif
00067 }
00068
00069 private:
00070
00071 MethodProxy()
00072 :
00073 theInvoker( 0 )
00074 {
00075 ;
00076 }
00077
00078 MethodProxy( Invoker anInvoker )
00079 :
00080 theInvoker( anInvoker )
00081 {
00082 ;
00083 }
00084
00085 template < const RET (CLASS::*METHOD)() const >
00086 inline static const RET invoke( CLASS* const anObject )
00087 {
00088 return ( anObject->*METHOD )();
00089 }
00090
00091 private:
00092
00093 Invoker theInvoker;
00094
00095 };
00096
00097
00098
00099 template < typename RET, typename ARG1 = void >
00100 class ObjectMethodProxy;
00101
00102 template < typename RET >
00103 class ObjectMethodProxy<RET>
00104 {
00105 private:
00106
00107 typedef const RET (* Invoker )( void* const );
00108
00109 public:
00110
00111 inline const RET operator()() const
00112 {
00113 return theInvoker( theObject );
00114 }
00115
00116 template < class T, const RET (T::*TMethod)() const >
00117 static ObjectMethodProxy create( T* const anObject )
00118 {
00119 #if defined( LIBECS_USE_PMF_CONVERSIONS )
00120 return ObjectMethodProxy( Invoker( TMethod ), anObject );
00121 #else
00122 return ObjectMethodProxy( invoke<T,TMethod>, anObject );
00123 #endif
00124 }
00125
00126 private:
00127
00128 ObjectMethodProxy()
00129 :
00130 theInvoker( 0 ),
00131 theObject( 0 )
00132 {
00133 ;
00134 }
00135
00136 ObjectMethodProxy( Invoker anInvoker, void* anObject )
00137 :
00138 theInvoker( anInvoker ),
00139 theObject( anObject )
00140 {
00141 ;
00142 }
00143
00144 template < class T, const RET (T::*TMethod)() const >
00145 inline static const RET invoke( void* const anObject )
00146 {
00147 return ( static_cast<T*>(anObject)->*TMethod )();
00148 }
00149
00150 private:
00151
00152 Invoker theInvoker;
00153 void* theObject;
00154
00155 };
00156
00157
00158
00159
00160 #endif