expanded support for more args in tuple + rpc
This commit is contained in:
parent
4f146b93f1
commit
9af6c22f30
6 changed files with 73 additions and 23 deletions
|
|
@ -78,8 +78,6 @@ template<typename R,typename A1>
|
|||
class function<R(A1)> : public function<R,A1> {
|
||||
public:
|
||||
function(){}
|
||||
// template<typename U>
|
||||
// function( U&& u ) { static_assert( sizeof(U) < 0, "tesT"); *this = fc::forward<U>(u); }
|
||||
function( const function<R,A1>& u ):function<R,A1>(u){}
|
||||
function( function<R,A1>&& u ):function<R,A1>(u){}
|
||||
function( const function& u ):function<R,A1>(u.func){}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,28 @@
|
|||
#pragma once
|
||||
#include <fc/actor.hpp>
|
||||
#include <fc/json_rpc_connection.hpp>
|
||||
#include <boost/preprocessor/repeat.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/facilities/empty.hpp>
|
||||
|
||||
|
||||
namespace fc { namespace json {
|
||||
|
||||
namespace detail {
|
||||
struct rpc_member {
|
||||
// TODO: expand for all method arity and constness....
|
||||
template<typename R, typename C, typename A1, typename P>
|
||||
static fc::function<fc::future<R>,A1> functor( P,
|
||||
R (C::*mem_func)(A1),
|
||||
const rpc_connection& c = rpc_connection(),
|
||||
const char* name = nullptr
|
||||
) {
|
||||
return [=](A1 a1)->fc::future<R>{ return c.invoke<R>( name, make_tuple(a1) ); };
|
||||
}
|
||||
#define RPC_MEMBER_FUNCTOR(z,n,IS_CONST) \
|
||||
template<typename R, typename C, typename P BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS( n, typename A)> \
|
||||
static fc::function<fc::future<R> 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<R>{ return c.invoke<R>( 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;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ namespace fc {
|
|||
namespace fc { namespace detail { \
|
||||
template<typename Transform> \
|
||||
struct vtable<test,Transform> : public fc::retainable { \
|
||||
vtable(){} \
|
||||
BOOST_PP_SEQ_FOR_EACH( FC_STUB_VTABLE_DEFINE_MEMBER, CLASS, METHODS ) \
|
||||
template<typename T, typename Visitor> \
|
||||
void visit( Visitor&& v ) { \
|
||||
|
|
|
|||
|
|
@ -1,5 +1,12 @@
|
|||
#pragma once
|
||||
#include <fc/utility.hpp>
|
||||
#include <boost/preprocessor/repeat.hpp>
|
||||
#include <boost/preprocessor/repeat_from_to.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum.hpp>
|
||||
#include <boost/preprocessor/facilities/empty.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
|
||||
|
||||
namespace fc {
|
||||
|
||||
|
|
@ -21,7 +28,6 @@ namespace fc {
|
|||
* void operator()( const MemberType& m );
|
||||
* };
|
||||
* @endcode
|
||||
*/
|
||||
template<typename A=void, typename B=void,typename C=void, typename D=void>
|
||||
struct tuple {
|
||||
tuple(){}
|
||||
|
|
@ -45,14 +51,55 @@ namespace fc {
|
|||
C c;
|
||||
D d;
|
||||
};
|
||||
*/
|
||||
|
||||
template<>
|
||||
struct tuple<> {
|
||||
enum size_enum { size = 0 };
|
||||
template<typename V>
|
||||
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(AA,n)>( 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(AA,n)>(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<BOOST_PP_ENUM_PARAMS( n, typename A)> \
|
||||
struct tuple<BOOST_PP_ENUM_PARAMS(n,A)> { \
|
||||
enum size_enum { size = n }; \
|
||||
template<BOOST_PP_ENUM_PARAMS( n, typename AA)> \
|
||||
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<typename V>\
|
||||
void visit( V&& v ) { BOOST_PP_REPEAT(n,VISIT_PARAMS,a) }\
|
||||
template<typename V>\
|
||||
void visit( V&& v )const { BOOST_PP_REPEAT(n,VISIT_PARAMS,a) }\
|
||||
BOOST_PP_REPEAT(n,MEM_PARAMS,a) \
|
||||
}; \
|
||||
template<BOOST_PP_ENUM_PARAMS( n, typename AA)> \
|
||||
tuple<BOOST_PP_ENUM_PARAMS(n,AA)> make_tuple( BOOST_PP_ENUM( n, RREF_PARAMS, unused) ) { \
|
||||
return tuple<BOOST_PP_ENUM_PARAMS(n,AA)>( BOOST_PP_ENUM( n, FORWARD_PARAMS,unused ) ); \
|
||||
}
|
||||
template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(9, typename A, void)> 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<typename V>
|
||||
void visit( V&& v)const{};
|
||||
};
|
||||
|
||||
inline tuple<> make_tuple(){ return tuple<>(); }
|
||||
|
||||
/*
|
||||
template<typename A>
|
||||
struct tuple<A,void> {
|
||||
enum size_enum { size = 1 };
|
||||
|
|
@ -127,4 +174,5 @@ namespace fc {
|
|||
tuple<A,B,C> make_tuple(A&& a, B&& b, C&& c, D&& d){
|
||||
return tuple<A,B,C,D>( fc::forward<A>(a), fc::forward<B>(b), fc::forward<C>(c), fc::forward<D>(d) );
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
#include <fc/string.hpp>
|
||||
#include <fc/vector.hpp>
|
||||
#include <fc/aligned.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
|
||||
namespace fc {
|
||||
template<typename A, typename B, typename C, typename D>
|
||||
struct tuple;
|
||||
template<BOOST_PP_ENUM_PARAMS(9, typename A)> struct tuple;
|
||||
|
||||
/**
|
||||
* @brief a dynamic container that can hold
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ namespace fc {
|
|||
};
|
||||
|
||||
template<typename T>
|
||||
class vector_impl<T,fc::true_type> {
|
||||
struct vector_impl<T,fc::true_type> {
|
||||
public:
|
||||
typedef T* iterator;
|
||||
typedef const T* const_iterator;
|
||||
|
|
|
|||
Loading…
Reference in a new issue