MACE
1.0.0
|
00001 #ifndef _MACE_RPC_FILTER_HPP_ 00002 #define _MACE_RPC_FILTER_HPP_ 00003 #include <boost/function.hpp> 00004 namespace mace { namespace rpc { 00005 00011 struct default_filter { 00012 template<typename T> 00013 void operator()( T& r, T& v )const { v = r; } 00014 00015 template<typename T> 00016 const bool is_filtered(const T*)const { return false; } 00017 00018 template<typename T> 00019 inline const T& operator()( const T& v )const { return v; } 00020 00021 template<typename T> 00022 inline T operator()( T&& v )const { return v; } 00023 }; 00024 00032 template<typename Connection> 00033 struct function_filter : default_filter { 00034 function_filter( Connection& c ):m_con(c){} 00035 00036 using default_filter::operator(); 00037 using default_filter::is_filtered; 00038 00039 template<typename Signature> 00040 auto operator()( const boost::function<Signature>& v ) -> decltype( ((Connection*)0)->add_method(v)) { 00041 return m_con.add_method( v ); 00042 } 00043 00044 template<typename Signature, typename R> 00045 void operator()( const R& r, boost::function<Signature>& v ) { 00046 v = m_con.template create_callback<Signature>(r); 00047 } 00048 00049 template<typename Signature> 00050 const bool is_filtered(const boost::function<Signature>*)const { return true; } 00051 private: 00052 Connection& m_con; 00053 }; 00054 00055 } } // namespace boost::rpc 00056 00057 #endif //_MACE_RPC_FILTER_HPP_