From: Gabriel Corona Date: Mon, 23 Nov 2015 15:18:27 +0000 (+0100) Subject: [surf] Wrap the sigc++ API to provide the same API as boost::signals2 X-Git-Tag: v3_13~1570 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/0946e187d72b37589478b0b6ee0d1f193df7f14d?hp=6b198112a3d1f0d80b88f715b5de7517bfeeabaa [surf] Wrap the sigc++ API to provide the same API as boost::signals2 --- diff --git a/src/bindings/java/surf_swig.cpp b/src/bindings/java/surf_swig.cpp index ac6c7c019b..bacbfa702b 100644 --- a/src/bindings/java/surf_swig.cpp +++ b/src/bindings/java/surf_swig.cpp @@ -4,6 +4,12 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +// Avoid ambiguity between boost and std placeholders +// (the std placeholders are imported through boost::signals2): +#ifndef BOOST_BIND_NO_PLACEHOLDERS + #define BOOST_BIND_NO_PLACEHOLDERS +#endif + #include #include diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index 0ec897faa1..de1665d759 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -11,6 +11,8 @@ #include #include #include +#include + #include #include #include "surf/trace_mgr.h" @@ -23,15 +25,47 @@ #ifdef LIBSIGC #include -#define surf_callback(arg1, ...) sigc::signal -#define surf_callback_connect(callback, fun_ptr) callback.connect(sigc::ptr_fun(fun_ptr)) -#define surf_callback_emit(callback, ...) callback.emit(__VA_ARGS__) +namespace simgrid { +namespace surf { + // Wraps sigc++ signals with the interface of boost::signals2: + template class signal; + template + class signal { + private: + sigc::signal sig_; + public: + template XBT_ALWAYS_INLINE + void connect(T&& slot) + { + sig_.connect(std::forward(slot)); + } + template XBT_ALWAYS_INLINE + void connect(Res(*slot)(Args...)) + { + sig_.connect(sigc::ptr_fun(slot)); + } + template + R operator()(Args&&... args) const + { + return sig_.emit(std::forward(args)...); + } + }; +} +} #else #include -#define surf_callback(arg1, ...) boost::signals2::signal +namespace simgrid { +namespace surf { + template + using signal = ::boost::signals2::signal; +} +} +#endif + +// Deprecated: +#define surf_callback(arg1, ...) ::simgrid::surf::signal #define surf_callback_connect(callback, fun_ptr) callback.connect(fun_ptr) #define surf_callback_emit(callback, ...) callback(__VA_ARGS__) -#endif #ifdef _MSC_VER #pragma warning( disable : 4251)