OSDN Git Service

method_pointer.hpp: とりあえず2パラメータ版
authormyun2 <myun2@nwhite.info>
Wed, 11 Jul 2012 17:34:56 +0000 (02:34 +0900)
committermyun2 <myun2@nwhite.info>
Wed, 11 Jul 2012 17:35:13 +0000 (02:35 +0900)
roast/include/roast/tp/method_pointer.hpp

index 686672d..3bce100 100644 (file)
@@ -55,6 +55,47 @@ namespace roast
        };
        
        /////////////////////////////////////////////////////////////
+       
+       template <typename _Ret, typename _Class, typename T1, typename T2>
+       class method_pointer<_Ret,_Class,T1,T2>
+       {
+       public:
+               typedef typename method_pointer_type<_Ret,_Class,T1,T2>::type type, pointer_type, method_pointer_type;
+               _Class *class_ptr;
+               method_pointer_type func_ptr;
+               
+               method_pointer() : class_ptr(0), func_ptr(0){}
+               method_pointer(method_pointer_type p) : class_ptr(0), func_ptr(p){}
+               method_pointer(_Class &class_ref, method_pointer_type p_func) : class_ptr(&class_ref), func_ptr(p_func){}
+               method_pointer(_Class *p_class, method_pointer_type p_func) : class_ptr(p_class), func_ptr(p_func){}
+
+               _Ret call(T1 t1, T2 t2){
+                       if ( func_ptr == 0 )
+                               throw ::roast::exception("method_pointer::call() Not initialized function pointer.");
+                       if ( class_ptr == 0 )
+                               throw ::roast::exception("method_pointer::call() Not initialized class pointer.");
+                       return (class_ptr->*func_ptr)(t1,t2);
+               }
+               _Ret call(method_pointer_type p_func, T1 t1, T2 t2){
+                       func_ptr = p_func;
+                       return call(t1,t2);
+               }
+               _Ret call(_Class *p_class, T1 t1, T2 t2){
+                       class_ptr = p_class;
+                       return call(t1,t2);
+               }
+               _Ret call(_Class &class_ref, T1 t1, T2 t2){
+                       class_ptr = &class_ref;
+                       return call(t1,t2);
+               }
+
+               _Ret operator()( T1 t1, T2 t2)
+               {
+                       return call(t1,t2);
+               }
+       };
+       
+       /////////////////////////////////////////////////////////////
 }
 
 #include "roast/tp/method_pointer_make.hpp"