CppCMS
|
00001 00002 // 00003 // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com> 00004 // 00005 // See accompanying file COPYING.TXT file for licensing details. 00006 // 00008 #ifndef CPPCMS_UTIL_MEM_BIND_H 00009 #define CPPCMS_UTIL_MEM_BIND_H 00010 00011 namespace cppcms { namespace util { 00012 00014 namespace details { 00015 template<typename C,typename P> 00016 struct binder0 { 00017 void (C::*member)(); 00018 P object; 00019 void operator()() const { ((*object).*member)(); } 00020 }; 00021 template<typename C,typename P,typename P1> 00022 struct binder1 { 00023 void (C::*member)(P1); 00024 P object; 00025 void operator()(P1 p1) const { ((*object).*member)(p1); } 00026 }; 00027 template<typename C,typename P,typename P1,typename P2> 00028 struct binder2 { 00029 void (C::*member)(P1,P2); 00030 P object; 00031 void operator()(P1 p1,P2 p2) const { ((*object).*member)(p1,p2); } 00032 }; 00033 template<typename C,typename P,typename P1,typename P2,typename P3> 00034 struct binder3 { 00035 void (C::*member)(P1,P2,P3); 00036 P object; 00037 void operator()(P1 p1,P2 p2,P3 p3) const { ((*object).*member)(p1,p2,p3); } 00038 }; 00039 template<typename C,typename P,typename P1,typename P2,typename P3,typename P4> 00040 struct binder4 { 00041 void (C::*member)(P1,P2,P3,P4); 00042 P object; 00043 void operator()(P1 p1,P2 p2,P3 p3,P4 p4) const { ((*object).*member)(p1,p2,p3,p4); } 00044 }; 00045 } 00046 00048 00053 template<typename C,typename P> 00054 details::binder0<C,P> mem_bind(void (C::*mem)(),P obj) 00055 { 00056 details::binder0<C,P> tmp={mem,obj}; 00057 return tmp; 00058 } 00063 template<typename C,typename P,typename P1> 00064 details::binder1<C,P,P1> mem_bind(void (C::*mem)(P1),P obj) 00065 { 00066 details::binder1<C,P,P1> tmp={mem,obj}; 00067 return tmp; 00068 } 00073 template<typename C,typename P,typename P1,typename P2> 00074 details::binder2<C,P,P1,P2> mem_bind(void (C::*mem)(P1,P2),P obj) 00075 { 00076 details::binder2<C,P,P1,P2> tmp={mem,obj}; 00077 return tmp; 00078 } 00083 template<typename C,typename P,typename P1,typename P2,typename P3> 00084 details::binder3<C,P,P1,P2,P3> mem_bind(void (C::*mem)(P1,P2,P3),P obj) 00085 { 00086 details::binder3<C,P,P1,P2,P3> tmp={mem,obj}; 00087 return tmp; 00088 } 00093 template<typename C,typename P,typename P1,typename P2,typename P3,typename P4> 00094 details::binder4<C,P,P1,P2,P3,P4> mem_bind(void (C::*mem)(P1,P2,P3,P4),P obj) 00095 { 00096 details::binder4<C,P,P1,P2,P3,P4> tmp={mem,obj}; 00097 return tmp; 00098 } 00099 00100 00101 } } // cppcms::util 00102 00103 #endif