Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Public simgrid::xbt:signal<F> class
[simgrid.git] / include / xbt / signal.hpp
1 /* Copyright (c) 2014-2015. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_XBT_SIGNAL_HPP
7 #define SIMGRID_XBT_SIGNAL_HPP
8
9 #ifdef SIMGRID_HAVE_LIBSIG
10 #include <sigc++/sigc++.h>
11
12 namespace simgrid {
13 namespace xbt {
14   // Wraps sigc++ signals with the interface of boost::signals2:
15   template<class T> class signal;
16   template<class R, class... P>
17   class signal<R(P...)> {
18   private:
19     sigc::signal<R, P...> sig_;
20   public:
21     template<class U> XBT_ALWAYS_INLINE
22     void connect(U&& slot)
23     {
24       sig_.connect(std::forward<U>(slot));
25     }
26     template<class Res, class... Args> XBT_ALWAYS_INLINE
27     void connect(Res(*slot)(Args...))
28     {
29       sig_.connect(sigc::ptr_fun(slot));
30     }
31     template<class... Args> XBT_ALWAYS_INLINE
32     R operator()(Args&&... args) const
33     {
34       return sig_.emit(std::forward<Args>(args)...);
35     }
36   };
37 }
38 }
39
40 #else
41
42 #include <boost/signals2.hpp>
43 namespace simgrid {
44 namespace xbt {
45   template<class T>
46   using signal = ::boost::signals2::signal<T>;
47 }
48 }
49
50 #endif
51
52 #endif