From 9af6c22f301af636dab4854eff660f200db4a97e Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Fri, 26 Oct 2012 17:13:42 -0400 Subject: [PATCH] expanded support for more args in tuple + rpc --- include/fc/function.hpp | 2 -- include/fc/json_rpc_client.hpp | 25 ++++++++------ include/fc/ptr.hpp | 1 + include/fc/tuple.hpp | 62 ++++++++++++++++++++++++++++++---- include/fc/value.hpp | 4 +-- include/fc/vector.hpp | 2 +- 6 files changed, 73 insertions(+), 23 deletions(-) diff --git a/include/fc/function.hpp b/include/fc/function.hpp index f06033a..fdead59 100644 --- a/include/fc/function.hpp +++ b/include/fc/function.hpp @@ -78,8 +78,6 @@ template class function : public function { public: function(){} -// template -// function( U&& u ) { static_assert( sizeof(U) < 0, "tesT"); *this = fc::forward(u); } function( const function& u ):function(u){} function( function&& u ):function(u){} function( const function& u ):function(u.func){} diff --git a/include/fc/json_rpc_client.hpp b/include/fc/json_rpc_client.hpp index fb59fb9..3db486e 100644 --- a/include/fc/json_rpc_client.hpp +++ b/include/fc/json_rpc_client.hpp @@ -1,24 +1,28 @@ #pragma once #include #include +#include +#include +#include +#include namespace fc { namespace json { namespace detail { struct rpc_member { - // TODO: expand for all method arity and constness.... - template - static fc::function,A1> functor( P, - R (C::*mem_func)(A1), - const rpc_connection& c = rpc_connection(), - const char* name = nullptr - ) { - return [=](A1 a1)->fc::future{ return c.invoke( name, make_tuple(a1) ); }; - } + #define RPC_MEMBER_FUNCTOR(z,n,IS_CONST) \ + template \ + static fc::function BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n,A) > \ + functor( P, R (C::*mem_func)(BOOST_PP_ENUM_PARAMS(n,A)) IS_CONST, \ + const rpc_connection& c = rpc_connection(), 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 }; - struct vtable_visitor { vtable_visitor( rpc_connection& c ):_con(c){} @@ -28,7 +32,6 @@ namespace fc { namespace json { } rpc_connection& _con; }; - }; diff --git a/include/fc/ptr.hpp b/include/fc/ptr.hpp index c4cf4d0..acc410d 100644 --- a/include/fc/ptr.hpp +++ b/include/fc/ptr.hpp @@ -79,6 +79,7 @@ namespace fc { namespace fc { namespace detail { \ template \ struct vtable : public fc::retainable { \ + vtable(){} \ BOOST_PP_SEQ_FOR_EACH( FC_STUB_VTABLE_DEFINE_MEMBER, CLASS, METHODS ) \ template \ void visit( Visitor&& v ) { \ diff --git a/include/fc/tuple.hpp b/include/fc/tuple.hpp index 454aa7d..020a908 100644 --- a/include/fc/tuple.hpp +++ b/include/fc/tuple.hpp @@ -1,5 +1,12 @@ #pragma once #include +#include +#include +#include +#include +#include +#include +#include namespace fc { @@ -21,7 +28,6 @@ namespace fc { * void operator()( const MemberType& m ); * }; * @endcode - */ template struct tuple { tuple(){} @@ -45,14 +51,55 @@ namespace fc { C c; D d; }; + */ - template<> - struct tuple<> { - enum size_enum { size = 0 }; - template - void visit( V&& v)const{}; - }; + #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) ) ) + #define ILIST_PARAMS_COPY(z,n,data) BOOST_PP_CAT(a,n)( t.BOOST_PP_CAT(a,n) ) + #define VISIT_PARAMS(z,n,data) v(BOOST_PP_CAT(a,n)); + #define FORWARD_PARAMS(z,n,data) fc::forward(BOOST_PP_CAT(a,n)) + #define MEM_PARAMS(z,n,data) BOOST_PP_CAT(A,n) BOOST_PP_CAT(a,n); + #define TUPLE(z,n,unused) \ + template \ + struct tuple { \ + enum size_enum { size = n }; \ + template \ + tuple( BOOST_PP_ENUM(n, RREF_PARAMS, unused ) )BOOST_PP_IF(n,:,BOOST_PP_EMPTY())BOOST_PP_ENUM( n, ILIST_PARAMS,unused){} \ + tuple( const tuple& t )BOOST_PP_IF(n,:,BOOST_PP_EMPTY())BOOST_PP_ENUM( n, ILIST_PARAMS_COPY,unused){} \ + tuple( tuple&& t )BOOST_PP_IF(n,:,BOOST_PP_EMPTY())BOOST_PP_ENUM( n, ILIST_PARAMS_COPY,unused){} \ + tuple(){}\ + template\ + void visit( V&& v ) { BOOST_PP_REPEAT(n,VISIT_PARAMS,a) }\ + template\ + void visit( V&& v )const { BOOST_PP_REPEAT(n,VISIT_PARAMS,a) }\ + BOOST_PP_REPEAT(n,MEM_PARAMS,a) \ + }; \ + template \ + tuple make_tuple( BOOST_PP_ENUM( n, RREF_PARAMS, unused) ) { \ + return tuple( BOOST_PP_ENUM( n, FORWARD_PARAMS,unused ) ); \ + } + template struct tuple{}; + BOOST_PP_REPEAT_FROM_TO( 1, 8, TUPLE, unused ) + + #undef FORWARD_PARAMS + #undef RREF_PARAMS + #undef ILIST_PARAMS + #undef ILIST_PARAMS_COPY + #undef VISIT_PARAMS + #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 tuple { enum size_enum { size = 1 }; @@ -127,4 +174,5 @@ namespace fc { 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/include/fc/value.hpp b/include/fc/value.hpp index a3c647e..84ca8f5 100644 --- a/include/fc/value.hpp +++ b/include/fc/value.hpp @@ -3,10 +3,10 @@ #include #include #include +#include namespace fc { - template - struct tuple; + template struct tuple; /** * @brief a dynamic container that can hold diff --git a/include/fc/vector.hpp b/include/fc/vector.hpp index baa700d..7b84a8a 100644 --- a/include/fc/vector.hpp +++ b/include/fc/vector.hpp @@ -182,7 +182,7 @@ namespace fc { }; template - class vector_impl { + struct vector_impl { public: typedef T* iterator; typedef const T* const_iterator;