diff --git a/include/fc/actor.hpp b/include/fc/actor.hpp index 558e951..2b26f6a 100644 --- a/include/fc/actor.hpp +++ b/include/fc/actor.hpp @@ -8,7 +8,7 @@ namespace fc { struct actor_member { // TODO: expand for all method arity and constness.... template - static fc::function(A1)> functor( P&& p, R (C::*mem_func)(A1), fc::thread* t = nullptr) { + static std::function(A1)> functor( P&& p, R (C::*mem_func)(A1), fc::thread* t = nullptr) { return [=](A1 a1){ return t->async( [=](){ return (p->*mem_func)(a1); } ); }; } }; diff --git a/include/fc/function.hpp b/include/fc/function.hpp index cb1c0d5..6aec96e 100644 --- a/include/fc/function.hpp +++ b/include/fc/function.hpp @@ -1,7 +1,7 @@ +#if 0 #pragma once #include #include - namespace fc { template class function { @@ -108,4 +108,5 @@ class function : public function { }; } +#endif diff --git a/include/fc/json_rpc_client.hpp b/include/fc/json_rpc_client.hpp index c97b391..826428b 100644 --- a/include/fc/json_rpc_client.hpp +++ b/include/fc/json_rpc_client.hpp @@ -9,21 +9,36 @@ namespace fc { namespace json { - //static std::function( BOOST_PP_ENUM_PARAMS(n,A) ) > namespace detail { struct rpc_member { - #define RPC_MEMBER_FUNCTOR(z,n,IS_CONST) \ - template \ - static fc::function BOOST_PP_ENUM_TRAILING_PARAMS(n,A) > \ - functor( P, R (C::*mem_func)(BOOST_PP_ENUM_PARAMS(n,A)) IS_CONST, \ - const rpc_connection::ptr& c = rpc_connection::ptr(), const char* name = nullptr ) { \ - return [=](BOOST_PP_ENUM_BINARY_PARAMS(n,A,a))->fc::future{ \ - return c->invoke( name, make_tuple(BOOST_PP_ENUM_PARAMS(n,a)) ); }; \ - } - BOOST_PP_REPEAT( 8, RPC_MEMBER_FUNCTOR, const ) - BOOST_PP_REPEAT( 8, RPC_MEMBER_FUNCTOR, BOOST_PP_EMPTY() ) - #undef RPC_MEMBER_FUNCTOR + #if BOOST_NO_VARIADIC_TEMPLATES + #define RPC_MEMBER_FUNCTOR(z,n,IS_CONST) \ + template \ + static std::function( BOOST_PP_ENUM_PARAMS(n,A) ) > \ + functor( P, R (C::*mem_func)(BOOST_PP_ENUM_PARAMS(n,A)) IS_CONST, \ + const rpc_connection::ptr& c = rpc_connection::ptr(), const char* name = nullptr ) { \ + return [=](BOOST_PP_ENUM_BINARY_PARAMS(n,A,a))->fc::future{ \ + return c->invoke( name, make_tuple(BOOST_PP_ENUM_PARAMS(n,a)) ); }; \ + } + BOOST_PP_REPEAT( 8, RPC_MEMBER_FUNCTOR, const ) + BOOST_PP_REPEAT( 8, RPC_MEMBER_FUNCTOR, BOOST_PP_EMPTY() ) + #undef RPC_MEMBER_FUNCTOR + + #else + template + static std::function(Args...)> functor( P&& p, R (C::*mem_func)(Args...), + const rpc_connection::ptr& c = rpc_connection::ptr(), const char* name = nullptr ) { + return [=](Args... args)->fc::future{ + return c->invoke( name, make_tuple(args...) ); }; + } + template + static std::function(Args...)> functor( P&& p, R (C::*mem_func)(Args...)const, + const rpc_connection::ptr& c = rpc_connection::ptr(), const char* name = nullptr ) { + return [=](Args... args)->fc::future{ + return c->invoke( name, make_tuple(args...) ); }; + } + #endif }; struct vtable_visitor { diff --git a/include/fc/json_rpc_connection.hpp b/include/fc/json_rpc_connection.hpp index 34a93ca..a968211 100644 --- a/include/fc/json_rpc_connection.hpp +++ b/include/fc/json_rpc_connection.hpp @@ -40,16 +40,13 @@ namespace fc { namespace json { }; - template + template struct rpc_server_method_impl : public rpc_server_method { - //static_assert( fc::is_tuple::type::value, "params should be a tuple" ); - rpc_server_method_impl( const fc::function& f ):func(f){} + rpc_server_method_impl( const std::function& f ):func(f){} virtual value call( const value& v ) { - // slog( "cast %s", typeid(Args).name() ); - return value( call_fused( func, fc::value_cast >( v ) ) ); - //return value( func( fc::value_cast( v )) ); + return value( call_fused(func, fc::value_cast( v ) ) ); } - fc::function func; + std::function func; }; template @@ -57,8 +54,12 @@ namespace fc { namespace json { public: add_method_visitor( const fc::ptr& p, fc::json::rpc_connection& c ):_ptr(p),_con(c){} - template - void operator()( const char* name, fc::function& meth); + template + void operator()( const char* name, std::function& meth); + template + void operator()( const char* name, std::function& meth); + template + void operator()( const char* name, std::function& meth); const fc::ptr& _ptr; fc::json::rpc_connection& _con; @@ -92,12 +93,6 @@ namespace fc { namespace json { return rtn; } - template - void add_method( const fc::string& name, const fc::function& a ) { - static_assert( is_tuple::type::value, "is tuple" ); - this->add_method( name, rpc_server_method::ptr(new detail::rpc_server_method_impl(a) ) ); - } - template void add_interface( const fc::ptr& it ) { it->template visit( detail::add_method_visitor( it, *this ) ); @@ -125,10 +120,19 @@ namespace fc { namespace json { namespace detail { template - template - void add_method_visitor::operator()( const char* name, fc::function& meth) { - _con.add_method( name, rpc_server_method::ptr( - new rpc_server_method_impl(meth) ) ); + template + void add_method_visitor::operator()( const char* name, std::function& meth) { + _con.add_method( name, rpc_server_method::ptr( new rpc_server_method_impl,R(A1) >(meth) ) ); + } + template + template + void add_method_visitor::operator()( const char* name, std::function& meth) { + _con.add_method( name, rpc_server_method::ptr( new rpc_server_method_impl,R(A1,A2) >(meth) ) ); + } + template + template + void add_method_visitor::operator()( const char* name, std::function& meth) { + _con.add_method( name, rpc_server_method::ptr( new rpc_server_method_impl,R() >(meth) ) ); } } // namespace detail diff --git a/include/fc/json_rpc_stream_connection.hpp b/include/fc/json_rpc_stream_connection.hpp index 0b1e8af..b0dab25 100644 --- a/include/fc/json_rpc_stream_connection.hpp +++ b/include/fc/json_rpc_stream_connection.hpp @@ -24,7 +24,7 @@ namespace fc { /** * When the connection is closed, call the given method */ - void on_close( const fc::function& ); + void on_close( const std::function& ); protected: ~rpc_stream_connection(); diff --git a/include/fc/json_rpc_tcp_server.hpp b/include/fc/json_rpc_tcp_server.hpp index 9e5e19d..7c334b8 100644 --- a/include/fc/json_rpc_tcp_server.hpp +++ b/include/fc/json_rpc_tcp_server.hpp @@ -30,7 +30,7 @@ namespace fc { }); } - void on_new_connection( const fc::function& c ); + void on_new_connection( const std::function& c ); void listen( uint16_t port ); diff --git a/include/fc/ptr.hpp b/include/fc/ptr.hpp index 92f0165..3e5cb62 100644 --- a/include/fc/ptr.hpp +++ b/include/fc/ptr.hpp @@ -1,15 +1,37 @@ #pragma once -#include +//#include #include +#include +#include +#include +#include +#include +#include namespace fc { namespace detail { struct identity_member { - template - static fc::function functor( P&& p, R (C::*mem_func)(Args...) ) { - return fc::function([=](Args... args){ return (p->*mem_func)(args...); }); - } + #if BOOST_NO_VARIADIC_TEMPLATES + #define RPC_MEMBER_FUNCTOR(z,n,IS_CONST) \ + template \ + static std::function \ + functor( P p, R (C::*mem_func)(BOOST_PP_ENUM_PARAMS(n,A)) IS_CONST ){ \ + return [=](BOOST_PP_ENUM_BINARY_PARAMS(n,A,a)){ return (p->*mem_func)(BOOST_PP_ENUM_PARAMS(n,a)); }; \ + } + BOOST_PP_REPEAT( 8, RPC_MEMBER_FUNCTOR, const ) + BOOST_PP_REPEAT( 8, RPC_MEMBER_FUNCTOR, BOOST_PP_EMPTY() ) + #undef RPC_MEMBER_FUNCTOR + #else + template + static std::function functor( P&& p, R (C::*mem_func)(Args...) ) { + return std::function([=](Args... args){ return (p->*mem_func)(args...); }); + } + template + static std::function functor( P&& p, R (C::*mem_func)(Args...)const ) { + return std::function([=](Args... args){ return (p->*mem_func)(args...); }); + } + #endif }; template< typename Interface, typename Transform = detail::identity_member > diff --git a/include/fc/ssh/client.hpp b/include/fc/ssh/client.hpp index d0fd10f..17465af 100644 --- a/include/fc/ssh/client.hpp +++ b/include/fc/ssh/client.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include +#include #include namespace fc { @@ -86,7 +86,7 @@ namespace fc { * transfer, the callback should return true. To cancel the callback should return false. */ void scp_send( const fc::path& local_path, const fc::path& remote_path, - fc::function progress = [](size_t,size_t){return true;} ); + std::function progress = [](size_t,size_t){return true;} ); /** diff --git a/include/fc/tuple.hpp b/include/fc/tuple.hpp index fb77a83..ed2653b 100644 --- a/include/fc/tuple.hpp +++ b/include/fc/tuple.hpp @@ -52,6 +52,21 @@ namespace fc { D d; }; */ + template struct tuple{}; + + template<> + struct tuple<> { + enum size_enum { size = 0 }; + template + void visit( V&& v)const{}; + }; + + inline tuple<> make_tuple(){ return tuple<>(); } + + template + struct is_tuple { + typedef fc::false_type type; + }; #define RREF_PARAMS(z,n,data) BOOST_PP_CAT(AA,n)&& BOOST_PP_CAT(a,n) #define ILIST_PARAMS(z,n,data) BOOST_PP_CAT(a,n)( fc::forward( BOOST_PP_CAT(a,n) ) ) @@ -83,9 +98,12 @@ namespace fc { auto call_fused( Functor f, Tuple&& t ) \ -> decltype( f( BOOST_PP_ENUM( n, LIST_MEMBERS_ON, t) ) ) { \ return f( BOOST_PP_ENUM( n, LIST_MEMBERS_ON, t) ); \ - } + } \ + template \ + struct is_tuple > { \ + typedef fc::true_type type; \ + }; - template struct tuple{}; BOOST_PP_REPEAT_FROM_TO( 1, 8, TUPLE, unused ) @@ -98,101 +116,6 @@ namespace fc { #undef MEM_PARAMS #undef TUPLE - template<> - struct tuple<> { - enum size_enum { size = 0 }; - template - void visit( V&& v)const{}; - }; - inline tuple<> make_tuple(){ return tuple<>(); } - - template - struct is_tuple { - typedef fc::false_type type; - }; - - template - struct is_tuple > { - typedef fc::true_type type; - }; - - - - /* - template - struct tuple { - enum size_enum { size = 1 }; - template - tuple( AA&& aa ):a( fc::forward(aa) ){} - tuple( const tuple& t ):a(t.a){} - tuple( tuple&& t ):a(t.a){} - tuple(){} - - template - void visit( V&& v ) { v(a); } - template - void visit( V&& v )const { v(a); } - - A a; - }; - - template - struct tuple { - enum size_enum { size = 2 }; - - template - tuple( AA&& aa, BB&& bb ) - :a( fc::forward(aa) ), - b( fc::forward(bb) ){} - - tuple(){} - - template - void visit( V&& v ) { v(a); v(b); } - template - void visit( V&& v )const { v(a); v(b); } - - A a; - B b; - }; - - template - struct tuple { - enum size_enum { size = 3 }; - tuple(){} - - template - tuple( AA&& aa, BB&& bb, CC&& cc ) - :a( fc::forward(aa) ), - b( fc::forward(bb) ), - c( fc::forward(cc) ) - {} - - template - void visit( V&& v ) { v(a); v(b); v(c); } - template - void visit( V&& v )const { v(a); v(b); v(c); } - - A a; - B b; - C c; - }; - - tuple<> make_tuple(); - - template - tuple make_tuple(A&& a){ return tuple( fc::forward(a) ); } - - template - tuple make_tuple(A&& a, B&& b){ return tuple( fc::forward(a), fc::forward(b) ); } - - template - tuple make_tuple(A&& a, B&& b, C&& c){ return tuple( fc::forward(a), fc::forward(b), fc::forward(c) ); } - - template - tuple make_tuple(A&& a, B&& b, C&& c, D&& d){ - return tuple( fc::forward(a), fc::forward(b), fc::forward(c), fc::forward(d) ); - } - */ } + diff --git a/src/json_rpc_stream_connection.cpp b/src/json_rpc_stream_connection.cpp index d88abb1..2c7e921 100644 --- a/src/json_rpc_stream_connection.cpp +++ b/src/json_rpc_stream_connection.cpp @@ -10,7 +10,7 @@ namespace fc { namespace json { fc::istream& in; fc::ostream& out; rpc_stream_connection& self; - fc::function on_close; + std::function on_close; impl( fc::istream& i, fc::ostream& o, rpc_stream_connection& s ) :in(i),out(o),self(s){ @@ -73,7 +73,7 @@ namespace fc { namespace json { /** * When the connection is closed, call the given method */ - void rpc_stream_connection::on_close( const fc::function& oc ) { + void rpc_stream_connection::on_close( const std::function& oc ) { my->on_close = oc; } diff --git a/src/json_rpc_tcp_server.cpp b/src/json_rpc_tcp_server.cpp index 3c64707..01f85b5 100644 --- a/src/json_rpc_tcp_server.cpp +++ b/src/json_rpc_tcp_server.cpp @@ -7,9 +7,9 @@ namespace fc { namespace json { class rpc_tcp_server::impl { public: - fc::function on_con; - fc::tcp_server tcp_serv; - fc::vector cons; + std::function on_con; + fc::tcp_server tcp_serv; + fc::vector cons; }; rpc_tcp_server::rpc_tcp_server() :my( new impl() ){} @@ -17,7 +17,7 @@ namespace fc { delete my; } - void rpc_tcp_server::on_new_connection( const fc::function& c ) { + void rpc_tcp_server::on_new_connection( const std::function& c ) { my->on_con = c; } diff --git a/src/ssh.cpp b/src/ssh.cpp index c3a9976..eb8f6aa 100644 --- a/src/ssh.cpp +++ b/src/ssh.cpp @@ -437,7 +437,7 @@ namespace fc { namespace ssh { } void client::scp_send( const fc::path& local_path, const fc::path& remote_path, - fc::function progress ) { + std::function progress ) { /** * Tests have shown that if one scp is 'blocked' by a need to read (presumably to * ack recv for the trx window), and then a second transfer begins that the first