removed dependency on varidic templates...

eliminate fc::function for now..
This commit is contained in:
Daniel Larimer 2012-11-08 23:06:31 -05:00
parent 39436c7021
commit 914b8b2d3e
12 changed files with 112 additions and 147 deletions

View file

@ -8,7 +8,7 @@ namespace fc {
struct actor_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&& p, R (C::*mem_func)(A1), fc::thread* t = nullptr) {
static std::function<fc::future<R>(A1)> functor( P&& p, R (C::*mem_func)(A1), fc::thread* t = nullptr) {
return [=](A1 a1){ return t->async( [=](){ return (p->*mem_func)(a1); } ); };
}
};

View file

@ -1,7 +1,7 @@
#if 0
#pragma once
#include <fc/utility.hpp>
#include <fc/shared_ptr.hpp>
namespace fc {
template<typename R,typename ... Args>
class function {
@ -108,4 +108,5 @@ class function<R(A1,A2,A3)> : public function<R,A1,A2,A3> {
};
}
#endif

View file

@ -9,21 +9,36 @@
namespace fc { namespace json {
//static std::function<fc::future<R>( BOOST_PP_ENUM_PARAMS(n,A) ) >
namespace detail {
struct rpc_member {
#define RPC_MEMBER_FUNCTOR(z,n,IS_CONST) \
template<typename R, typename C, typename P BOOST_PP_ENUM_TRAILING_PARAMS( n, typename A)> \
static fc::function<fc::future<R> 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<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
#if BOOST_NO_VARIADIC_TEMPLATES
#define RPC_MEMBER_FUNCTOR(z,n,IS_CONST) \
template<typename R, typename C, typename P BOOST_PP_ENUM_TRAILING_PARAMS( n, typename A)> \
static std::function<fc::future<R>( 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<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
#else
template<typename R, typename C, typename P, typename... Args>
static std::function<fc::future<R>(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<R>{
return c->invoke<R>( name, make_tuple(args...) ); };
}
template<typename R, typename C, typename P, typename... Args>
static std::function<fc::future<R>(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<R>{
return c->invoke<R>( name, make_tuple(args...) ); };
}
#endif
};
struct vtable_visitor {

View file

@ -40,16 +40,13 @@ namespace fc { namespace json {
};
template<typename R, typename... Args>
template<typename R, typename ArgsTuple, typename Signature>
struct rpc_server_method_impl : public rpc_server_method {
//static_assert( fc::is_tuple<Args>::type::value, "params should be a tuple" );
rpc_server_method_impl( const fc::function<R,Args...>& f ):func(f){}
rpc_server_method_impl( const std::function<Signature>& f ):func(f){}
virtual value call( const value& v ) {
// slog( "cast %s", typeid(Args).name() );
return value( call_fused( func, fc::value_cast<fc::tuple<Args...> >( v ) ) );
//return value( func( fc::value_cast<Args>( v )) );
return value( call_fused(func, fc::value_cast<ArgsTuple>( v ) ) );
}
fc::function<R,Args...> func;
std::function<Signature> func;
};
template<typename InterfaceType>
@ -57,8 +54,12 @@ namespace fc { namespace json {
public:
add_method_visitor( const fc::ptr<InterfaceType>& p, fc::json::rpc_connection& c ):_ptr(p),_con(c){}
template<typename R, typename... Args>
void operator()( const char* name, fc::function<R,Args...>& meth);
template<typename R>
void operator()( const char* name, std::function<R()>& meth);
template<typename R, typename A1>
void operator()( const char* name, std::function<R(A1)>& meth);
template<typename R, typename A1, typename A2>
void operator()( const char* name, std::function<R(A1,A2)>& meth);
const fc::ptr<InterfaceType>& _ptr;
fc::json::rpc_connection& _con;
@ -92,12 +93,6 @@ namespace fc { namespace json {
return rtn;
}
template<typename R, typename Args >
void add_method( const fc::string& name, const fc::function<R,Args>& a ) {
static_assert( is_tuple<Args>::type::value, "is tuple" );
this->add_method( name, rpc_server_method::ptr(new detail::rpc_server_method_impl<R,Args>(a) ) );
}
template<typename InterfaceType>
void add_interface( const fc::ptr<InterfaceType>& it ) {
it->template visit<InterfaceType>( detail::add_method_visitor<InterfaceType>( it, *this ) );
@ -125,10 +120,19 @@ namespace fc { namespace json {
namespace detail {
template<typename InterfaceType>
template<typename R, typename... Args>
void add_method_visitor<InterfaceType>::operator()( const char* name, fc::function<R,Args...>& meth) {
_con.add_method( name, rpc_server_method::ptr(
new rpc_server_method_impl<R,Args...>(meth) ) );
template<typename R, typename A1>
void add_method_visitor<InterfaceType>::operator()( const char* name, std::function<R(A1)>& meth) {
_con.add_method( name, rpc_server_method::ptr( new rpc_server_method_impl<R,tuple<A1>,R(A1) >(meth) ) );
}
template<typename InterfaceType>
template<typename R, typename A1, typename A2>
void add_method_visitor<InterfaceType>::operator()( const char* name, std::function<R(A1,A2)>& meth) {
_con.add_method( name, rpc_server_method::ptr( new rpc_server_method_impl<R,tuple<A1,A2>,R(A1,A2) >(meth) ) );
}
template<typename InterfaceType>
template<typename R>
void add_method_visitor<InterfaceType>::operator()( const char* name, std::function<R()>& meth) {
_con.add_method( name, rpc_server_method::ptr( new rpc_server_method_impl<R,tuple<>,R() >(meth) ) );
}
} // namespace detail

View file

@ -24,7 +24,7 @@ namespace fc {
/**
* When the connection is closed, call the given method
*/
void on_close( const fc::function<void>& );
void on_close( const std::function<void()>& );
protected:
~rpc_stream_connection();

View file

@ -30,7 +30,7 @@ namespace fc {
});
}
void on_new_connection( const fc::function<void,rpc_connection&>& c );
void on_new_connection( const std::function<void(rpc_connection&)>& c );
void listen( uint16_t port );

View file

@ -1,15 +1,37 @@
#pragma once
#include <fc/function.hpp>
//#include <fc/function.hpp>
#include <fc/future.hpp>
#include <functional>
#include <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
#include <boost/preprocessor/facilities/empty.hpp>
namespace fc {
namespace detail {
struct identity_member {
template<typename R, typename C, typename P, typename... Args>
static fc::function<R,Args...> functor( P&& p, R (C::*mem_func)(Args...) ) {
return fc::function<R,Args...>([=](Args... args){ return (p->*mem_func)(args...); });
}
#if BOOST_NO_VARIADIC_TEMPLATES
#define RPC_MEMBER_FUNCTOR(z,n,IS_CONST) \
template<typename R, typename C, typename P BOOST_PP_ENUM_TRAILING_PARAMS( n, typename A)> \
static std::function<R( BOOST_PP_ENUM_PARAMS(n,A) ) > \
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<typename R, typename C, typename P, typename... Args>
static std::function<R(Args...)> functor( P&& p, R (C::*mem_func)(Args...) ) {
return std::function<R(Args...)>([=](Args... args){ return (p->*mem_func)(args...); });
}
template<typename R, typename C, typename P, typename... Args>
static std::function<R(Args...)> functor( P&& p, R (C::*mem_func)(Args...)const ) {
return std::function<R(Args...)>([=](Args... args){ return (p->*mem_func)(args...); });
}
#endif
};
template< typename Interface, typename Transform = detail::identity_member >

View file

@ -1,6 +1,6 @@
#pragma once
#include <fc/ssh/process.hpp>
#include <fc/function.hpp>
#include <functional>
#include <fc/filesystem.hpp>
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<bool,size_t,size_t> progress = [](size_t,size_t){return true;} );
std::function<bool(size_t,size_t)> progress = [](size_t,size_t){return true;} );
/**

View file

@ -52,6 +52,21 @@ namespace fc {
D d;
};
*/
template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(9, typename A, void)> struct 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 T>
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(AA,n)>( 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<BOOST_PP_ENUM_PARAMS( n, typename AA)> \
struct is_tuple<fc::tuple<BOOST_PP_ENUM_PARAMS(n,AA)> > { \
typedef fc::true_type type; \
};
template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(9, typename A, void)> 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<typename V>
void visit( V&& v)const{};
};
inline tuple<> make_tuple(){ return tuple<>(); }
template<typename T>
struct is_tuple {
typedef fc::false_type type;
};
template<typename... T>
struct is_tuple<fc::tuple<T...> > {
typedef fc::true_type type;
};
/*
template<typename A>
struct tuple<A,void> {
enum size_enum { size = 1 };
template<typename AA>
tuple( AA&& aa ):a( fc::forward<AA>(aa) ){}
tuple( const tuple& t ):a(t.a){}
tuple( tuple&& t ):a(t.a){}
tuple(){}
template<typename V>
void visit( V&& v ) { v(a); }
template<typename V>
void visit( V&& v )const { v(a); }
A a;
};
template<typename A, typename B>
struct tuple<A,B> {
enum size_enum { size = 2 };
template<typename AA, typename BB>
tuple( AA&& aa, BB&& bb )
:a( fc::forward<AA>(aa) ),
b( fc::forward<BB>(bb) ){}
tuple(){}
template<typename V>
void visit( V&& v ) { v(a); v(b); }
template<typename V>
void visit( V&& v )const { v(a); v(b); }
A a;
B b;
};
template<typename A, typename B, typename C>
struct tuple<A, B, C > {
enum size_enum { size = 3 };
tuple(){}
template<typename AA, typename BB, typename CC>
tuple( AA&& aa, BB&& bb, CC&& cc )
:a( fc::forward<AA>(aa) ),
b( fc::forward<BB>(bb) ),
c( fc::forward<CC>(cc) )
{}
template<typename V>
void visit( V&& v ) { v(a); v(b); v(c); }
template<typename V>
void visit( V&& v )const { v(a); v(b); v(c); }
A a;
B b;
C c;
};
tuple<> make_tuple();
template<typename A>
tuple<A> make_tuple(A&& a){ return tuple<A>( fc::forward<A>(a) ); }
template<typename A,typename B>
tuple<A,B> make_tuple(A&& a, B&& b){ return tuple<A,B>( fc::forward<A>(a), fc::forward<B>(b) ); }
template<typename A,typename B, typename C>
tuple<A,B,C> make_tuple(A&& a, B&& b, C&& c){ return tuple<A,B,C>( fc::forward<A>(a), fc::forward<B>(b), fc::forward<C>(c) ); }
template<typename A,typename B, typename C,typename D>
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) );
}
*/
}

View file

@ -10,7 +10,7 @@ namespace fc { namespace json {
fc::istream& in;
fc::ostream& out;
rpc_stream_connection& self;
fc::function<void> on_close;
std::function<void()> 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<void>& oc ) {
void rpc_stream_connection::on_close( const std::function<void()>& oc ) {
my->on_close = oc;
}

View file

@ -7,9 +7,9 @@ namespace fc {
namespace json {
class rpc_tcp_server::impl {
public:
fc::function<void,rpc_connection&> on_con;
fc::tcp_server tcp_serv;
fc::vector<rpc_tcp_connection::ptr> cons;
std::function<void(rpc_connection&)> on_con;
fc::tcp_server tcp_serv;
fc::vector<rpc_tcp_connection::ptr> 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<void,rpc_connection&>& c ) {
void rpc_tcp_server::on_new_connection( const std::function<void(rpc_connection&)>& c ) {
my->on_con = c;
}

View file

@ -437,7 +437,7 @@ namespace fc { namespace ssh {
}
void client::scp_send( const fc::path& local_path, const fc::path& remote_path,
fc::function<bool,size_t,size_t> progress ) {
std::function<bool(size_t,size_t)> 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