More concise checking of callback param counts.

This commit is contained in:
John Maguire 2012-06-08 15:13:23 +02:00
parent ae4898655d
commit 80ab12aeff
2 changed files with 7 additions and 64 deletions

View File

@ -20,44 +20,10 @@
#include <glib-object.h> #include <glib-object.h>
#include <boost/config.hpp> #include <boost/function_types/function_arity.hpp>
#include <boost/typeof/typeof.hpp>
#ifdef BOOST_NO_VARIADIC_TEMPLATES
template <typename R>
int GetFunctionParamCount(R (*func)()) {
return 0;
}
template <typename R, typename P0>
int GetFunctionParamCount(R (*func)(P0)) {
return 1;
}
template <typename R, typename P0, typename P1>
int GetFunctionParamCount(R (*func)(P0, P1)) {
return 2;
}
template <typename R, typename P0, typename P1, typename P2>
int GetFunctionParamCount(R (*func)(P0, P1, P2)) {
return 3;
}
template <typename R, typename P0, typename P1, typename P2, typename P3>
int GetFunctionParamCount(R (*func)(P0, P1, P2, P3)) {
return 4;
}
#else // BOOST_NO_VARIADIC_TEMPLATES
template <typename R, typename... Params>
int GetFunctionParamCount(R (*func)(Params...)) {
return sizeof...(Params);
}
#endif // BOOST_NO_VARIADIC_TEMPLATES
// Do not call this directly, use CHECKED_GCONNECT instead.
bool CheckedGConnect( bool CheckedGConnect(
gpointer source, gpointer source,
const char* signal, const char* signal,
@ -65,31 +31,9 @@ bool CheckedGConnect(
gpointer data, gpointer data,
const int callback_param_count); const int callback_param_count);
#ifdef BOOST_NO_VARIADIC_TEMPLATES #define FUNCTION_ARITY(callback) boost::function_types::function_arity<BOOST_TYPEOF(callback)>::value
template <typename R, typename P0, typename P1, typename P2> #define CHECKED_GCONNECT(source, signal, callback, data) \
bool CheckedGConnect( CheckedGConnect(source, signal, G_CALLBACK(callback), data, FUNCTION_ARITY(callback));
gpointer source, const char* signal, R (*callback)(P0, P1, P2), gpointer data) {
return CheckedGConnect(
source, signal, G_CALLBACK(callback), data, GetFunctionParamCount(callback));
}
template <typename R, typename P0, typename P1, typename P2, typename P3>
bool CheckedGConnect(
gpointer source, const char* signal, R (*callback)(P0, P1, P2, P3), gpointer data) {
return CheckedGConnect(
source, signal, G_CALLBACK(callback), data, GetFunctionParamCount(callback));
}
#else
template <typename R, typename... Params>
bool CheckedGConnect(
gpointer source, const char* signal, R (*callback)(Params...), gpointer data) {
return CheckedGConnect(
source, signal, G_CALLBACK(callback), data, GetFunctionParamCount(callback));
}
#endif // BOOST_NO_VARIADIC_TEMPLATES
#endif // SIGNALCHECKER_H #endif // SIGNALCHECKER_H

View File

@ -104,8 +104,7 @@ void MoodbarPipeline::Start() {
"max-width", 1000, NULL); "max-width", 1000, NULL);
// Connect signals // Connect signals
CheckedGConnect( CHECKED_GCONNECT(decodebin, "pad-added", &NewPadCallback, this);
decodebin, "pad-added", &NewPadCallback, this);
gst_bus_set_sync_handler(gst_pipeline_get_bus(GST_PIPELINE(pipeline_)), BusCallbackSync, this); gst_bus_set_sync_handler(gst_pipeline_get_bus(GST_PIPELINE(pipeline_)), BusCallbackSync, this);
// Set appsink callbacks // Set appsink callbacks