4 #include <boost/any.hpp> 5 #include <boost/config.hpp> 10 # define FC_CALL_MEMBER_TEMPLATE_KEYWORD 12 # define FC_CALL_MEMBER_TEMPLATE_KEYWORD template 18 template<
typename T>
struct is_optional :
public std::false_type {};
23 template<
typename T,
typename... Ts>
struct all_optionals<T, Ts...> :
public std::false_type {};
34 template<
typename R,
typename... Parameters>
36 using std::function<R(Parameters...)>::operator();
38 template<
typename... CutList>
44 template<
unsigned RemoveCount,
typename... Types>
46 template<
unsigned RemoveCount,
typename,
typename... Types>
48 template<
typename... Types>
53 template<
unsigned RemoveCount,
typename T,
typename... Types>
56 template<
unsigned RemoveCount,
typename... Types>
58 template<
unsigned RemoveCount,
typename... Types>
61 template<
typename F,
typename... OptionalTypes>
63 return f(OptionalTypes()...);
68 template<
class... Args>
69 std::enable_if_t<
sizeof...(Args) <
sizeof...(Parameters), R> operator()(Args... args) {
71 auto partial_function = [
this, &args...](
auto&&... rest) {
72 return (*
this)(std::forward<decltype(args)>(args)..., std::move(rest)...);
75 pack_cutter_t<
sizeof...(Args), std::decay_t<Parameters>...> dummy;
78 return call_function(std::move(partial_function), dummy);
95 template<
typename R,
typename C,
typename P,
typename... Args>
97 template<
typename R,
typename C,
typename P,
typename... Args>
101 template<
typename Interface,
typename Transform >
102 struct vtable :
public std::enable_shared_from_this<vtable<Interface,Transform>>
105 template<
typename OtherType>
111 template<
typename R,
typename MemberPtr,
typename... Args>
112 void operator()(
const char* name, std::function<R(Args...)>& memb, MemberPtr m )
const {
113 OtherType* src = &_source;
114 memb = [src,m]( Args... args ){
return (src->*m)(args...); };
119 template<
typename Interface,
typename Transform >
132 virtual uint64_t get_handle()
const = 0;
134 virtual api_id_type register_api(
api_connection& conn )
const = 0;
137 template<
typename T >
144 template<
typename Interface,
typename Transform =
identity_member_with_optionals >
149 api():_vtable(
std::make_shared<vtable_type>() ) {}
152 template<
typename T >
154 :_vtable(
std::make_shared<vtable_type>() )
156 _data = std::make_shared<boost::any>(p);
157 T& ptr = boost::any_cast<T&>(*_data);
158 auto& pointed_at = *ptr;
159 typedef typename std::remove_reference<decltype(pointed_at)>::type source_vtable_type;
163 api(
const api& cpy ):_vtable(cpy._vtable),_data(cpy._data) {}
168 virtual uint64_t
get_handle()
const override {
return uint64_t(_data.get()); }
169 virtual api_id_type register_api(
api_connection& conn )
const override;
181 #include <boost/preprocessor/repeat.hpp> 182 #include <boost/preprocessor/repetition/enum_binary_params.hpp> 183 #include <boost/preprocessor/repetition/enum_params.hpp> 184 #include <boost/preprocessor/repetition/enum_trailing_params.hpp> 185 #include <boost/preprocessor/facilities/empty.hpp> 186 #include <boost/preprocessor/seq/for_each.hpp> 187 #include <boost/preprocessor/stringize.hpp> 189 #define FC_API_VTABLE_DEFINE_MEMBER( r, data, elem ) \ 190 decltype(Transform::functor( (data*)nullptr, &data::elem)) elem; 191 #define FC_API_VTABLE_DEFINE_VISIT_OTHER( r, data, elem ) \ 192 { typedef typename Visitor::other_type OtherType; \ 193 v( BOOST_PP_STRINGIZE(elem), elem, &OtherType::elem ); } 194 #define FC_API_VTABLE_DEFINE_VISIT( r, data, elem ) \ 195 v( BOOST_PP_STRINGIZE(elem), elem ); 197 #define FC_API( CLASS, METHODS ) \ 199 template<typename Transform> \ 200 struct vtable<CLASS,Transform> : public std::enable_shared_from_this<vtable<CLASS,Transform>> { \ 201 BOOST_PP_SEQ_FOR_EACH( FC_API_VTABLE_DEFINE_MEMBER, CLASS, METHODS ) \ 202 template<typename Visitor> \ 203 void visit_other( Visitor&& v ){ \ 204 BOOST_PP_SEQ_FOR_EACH( FC_API_VTABLE_DEFINE_VISIT_OTHER, CLASS, METHODS ) \ 206 template<typename Visitor> \ 207 void visit( Visitor&& v ){ \ 208 BOOST_PP_SEQ_FOR_EACH( FC_API_VTABLE_DEFINE_VISIT, CLASS, METHODS ) \
This metafunction determines whether its template argument is an instantiation of fc::optional...
vtable_type * operator->() const
std::shared_ptr< api_base > api_ptr
virtual uint64_t get_handle() const override
bool operator!=(const CBigNum &a, const CBigNum &b)
bool operator==(const CBigNum &a, const CBigNum &b)
provides stack-based nullable value similar to boost::optional
void operator()(const char *name, std::function< R(Args...)> &memb, MemberPtr m) const
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
std::shared_ptr< boost::any > _data
vtable_type & operator*() const
std::shared_ptr< vtable_type > _vtable
vtable< Interface, Transform > vtable_type
vtable_copy_visitor(OtherType &s)
R call_function(F &&f, short_pack< OptionalTypes... >)
This metafunction determines whether all of its template arguments are instantiations of fc::optional...
typename pack_cutter< RemoveCount, Types... >::type pack_cutter_t