OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
GenericCaller.h File Reference

Header providing templated functions to automate the process of calling a C++ member function (specifically the function call operator) from a facility that accepts a C function pointer and an opaque "userdata" pointer. More...

#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/if.hpp>
#include <boost/preprocessor/enum.hpp>
#include <boost/preprocessor/enum_params.hpp>
#include <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/facilities/empty.hpp>
#include <boost/function_types/function_arity.hpp>
#include <boost/function_types/result_type.hpp>
#include <boost/function_types/parameter_types.hpp>
#include <boost/type_traits/is_void.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/type_traits/is_function.hpp>
#include <boost/type_traits/remove_cv.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/remove_pointer.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/next_prior.hpp>
#include <boost/static_assert.hpp>

Go to the source code of this file.

Classes

struct  osvr::util::functor_trampolines::this_last_t
 Tag type indicating the last parameter of the function contains the "this" pointer. More...
 
struct  osvr::util::functor_trampolines::this_first_t
 Tag type indicating the first parameter of the function contains the "this" pointer. More...
 
struct  osvr::util::functor_trampolines::detail::param_at< F, C >
 Convenience metafunction to simplify computing the type of a particular argument to a function F. More...
 
struct  osvr::util::functor_trampolines::detail::Caller< ThisLocation, Arity, Return >
 Template that will be specialized to contain callers for functors with the "this" pointer as a void * argument. More...
 
struct  osvr::util::functor_trampolines::detail::ComputeGenericCaller< FunctionPtr, FunctionObjectType, ThisLocation >
 Internal metafunction to compute which caller you need based on the pointer types and this location. More...
 
struct  osvr::util::functor_trampolines::GenericCaller< FunctionPtr, FunctionObjectType, ThisLocation >
 Struct containing a single static function member named "call" that serves as a converter from a function call with an opaque userdata pointer to a functor call using the userdata pointer as "this". More...
 

Namespaces

 osvr
 <
 
 osvr::util
 The Util library: Functionality not necessarily coupled to any particular core library, serving more as a common base layer behind all systems.
 

Macros

#define OSVR_UTIL_CALLER_MAX_ARITY   3
 
#define OSVR_PARAM_STEM   p
 what do we call our pass-through parameters
 
#define OSVR_MAKE_PARAMLIST(Z, N, unused)   typename param_at<FPtr, N>::type BOOST_PP_CAT(OSVR_PARAM_STEM, N)
 Macro for use with BOOST_PP_ENUM to generate pass-through argument list.
 
#define OSVR_RETURNTYPE(R)
 Expands to the result type computation if R==1, void if R==0. More...
 
#define OSVR_RETURNSTATEMENT(R)   BOOST_PP_IF(R, return, BOOST_PP_EMPTY())
 Expands to "return" if R==1, nothing if R==0. More...
 
#define OSVR_MAKE_CALLERS(Z, ARITY, RETURNS)
 Generates specializations of CallerThisLast and CallerThisFirst for the given values of ARITY and RETURNS (matching the template parameters). More...
 

Functions

template<typename FunctionPtr , typename FunctionObjectType , typename ThisLocation >
FunctionPtr osvr::util::functor_trampolines::getCaller ()
 Get a generic functor caller: a pointer to a function that will call an object of your specific function object type, expecting the function object address passed as a void * as a parameter. More...
 
template<typename FunctionPtr , typename FunctionObjectType , typename ThisLocation >
FunctionPtr osvr::util::functor_trampolines::getCaller (ThisLocation const &)
 Get a generic functor caller. Specify the location of "this" through the argument: results in automatic type deduction for ThisLocation. More...
 
template<typename FunctionPtr , typename FunctionObjectType , typename ThisLocation >
FunctionPtr osvr::util::functor_trampolines::getCaller (FunctionObjectType const *, ThisLocation const &)
 Get a generic functor caller. Pass a pointer to a function object and specify the location of "this" through the argument: results in automatic type deduction for FunctionObjectType and ThisLocation. More...
 

Variables

BOOST_CONSTEXPR_OR_CONST
this_last_t 
this_last = {}
 Pass as an argument to a getCaller() overload to indicate the last parameter of the function contains the "this" pointer. More...
 
BOOST_CONSTEXPR_OR_CONST
this_first_t 
this_first = {}
 Pass as an argument to a getCaller() overload to indicate the first parameter of the function contains the "this" pointer. More...
 

Detailed Description

Header providing templated functions to automate the process of calling a C++ member function (specifically the function call operator) from a facility that accepts a C function pointer and an opaque "userdata" pointer.

Date
2014
Author
Sensics, Inc. http://sensics.com/osvr

Definition in file GenericCaller.h.

Macro Definition Documentation

#define OSVR_RETURNTYPE (   R)
Value:
BOOST_PP_IF(R, typename boost::function_types::result_type<FPtr>::type, \
void)

Expands to the result type computation if R==1, void if R==0.

Parameters
Rvalue of RETURNS

Definition at line 131 of file GenericCaller.h.

#define OSVR_RETURNSTATEMENT (   R)    BOOST_PP_IF(R, return, BOOST_PP_EMPTY())

Expands to "return" if R==1, nothing if R==0.

Parameters
Rvalue of RETURNS

Definition at line 138 of file GenericCaller.h.

#define OSVR_MAKE_CALLERS (   Z,
  ARITY,
  RETURNS 
)
Value:
template <> struct Caller<this_last_t, ARITY, RETURNS> { \
template <typename FPtr, typename F> struct Specialized { \
static OSVR_RETURNTYPE(RETURNS) \
call(BOOST_PP_ENUM(ARITY, OSVR_MAKE_PARAMLIST, ~) \
BOOST_PP_COMMA_IF(ARITY) void *functor) { \
F *o = static_cast<F *>(functor); \
OSVR_RETURNSTATEMENT(RETURNS) (*o)( \
BOOST_PP_ENUM_PARAMS(ARITY, OSVR_PARAM_STEM)); \
} \
}; \
}; \
template <> struct Caller<this_first_t, ARITY, RETURNS> { \
template <typename FPtr, typename F> \
static OSVR_RETURNTYPE(RETURNS) \
call(void *functor BOOST_PP_COMMA_IF(ARITY) \
BOOST_PP_ENUM(ARITY, OSVR_MAKE_PARAMLIST, ~)) { \
F *o = static_cast<F *>(functor); \
OSVR_RETURNSTATEMENT(RETURNS) (*o)( \
BOOST_PP_ENUM_PARAMS(ARITY, OSVR_PARAM_STEM)); \
} \
};
#define OSVR_MAKE_PARAMLIST(Z, N, unused)
Macro for use with BOOST_PP_ENUM to generate pass-through argument list.
#define OSVR_RETURNSTATEMENT(R)
Expands to "return" if R==1, nothing if R==0.
#define OSVR_PARAM_STEM
what do we call our pass-through parameters
#define OSVR_RETURNTYPE(R)
Expands to the result type computation if R==1, void if R==0.

Generates specializations of CallerThisLast and CallerThisFirst for the given values of ARITY and RETURNS (matching the template parameters).

Intended for use with BOOST_PP_REPEAT, passing a value (0 or 1) for RETURNS in the third, "data" parameter.

Definition at line 145 of file GenericCaller.h.

Variable Documentation

BOOST_CONSTEXPR_OR_CONST this_last_t this_last = {}

Pass as an argument to a getCaller() overload to indicate the last parameter of the function contains the "this" pointer.

()

Definition at line 86 of file GenericCaller.h.

BOOST_CONSTEXPR_OR_CONST this_first_t this_first = {}

Pass as an argument to a getCaller() overload to indicate the first parameter of the function contains the "this" pointer.

()

Definition at line 90 of file GenericCaller.h.