Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kebab-case some smpi options
[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 #include "simgrid_config.h"
10 #if SIMGRID_HAVE_LIBSIG
11 #include <sigc++/sigc++.h>
12 #else
13 #include <boost/signals2.hpp>
14 #endif
15
16 namespace simgrid {
17 namespace xbt {
18
19 #if SIMGRID_HAVE_LIBSIG
20
21   // Wraps sigc++ signals with the interface of boost::signals2:
22   template<class T> class signal;
23   template<class R, class... P>
24   class signal<R(P...)> {
25   private:
26     sigc::signal<R, P...> sig_;
27   public:
28     template<class U> XBT_ALWAYS_INLINE
29     void connect(U&& slot)
30     {
31       sig_.connect(std::forward<U>(slot));
32     }
33     template<class Res, class... Args> XBT_ALWAYS_INLINE
34     void connect(Res(*slot)(Args...))
35     {
36       sig_.connect(sigc::ptr_fun(slot));
37     }
38     template<class... Args> XBT_ALWAYS_INLINE
39     R operator()(Args&&... args) const
40     {
41       return sig_.emit(std::forward<Args>(args)...);
42     }
43     void disconnect_all_slots()
44     {
45       sig_.clear();
46     }
47   };
48
49 #else
50
51   template<class T>
52   using signal = ::boost::signals2::signal<T>;
53
54 #endif
55
56 }
57 }
58
59 #endif