Imported Upstream version 17.22.1
[platform/upstream/libzypp.git] / zypp / zyppng / base / signals.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \----------------------------------------------------------------------/
9 *
10 * This file contains private API, this might break at any time between releases.
11 * You have been warned!
12 *
13 */
14 #ifndef ZYPP_NG_BASE_SIGNALS_H_INCLUDED
15 #define ZYPP_NG_BASE_SIGNALS_H_INCLUDED
16
17 #include <sigc++/trackable.h>
18 #include <sigc++/signal.h>
19 #include <sigc++/connection.h>
20
21 namespace zyppng {
22
23 using sigc::signal;
24 using sigc::connection;
25 using sigc::trackable;
26
27 template <class R, class... T>
28 class SignalProxy;
29
30 /**
31      * Hides the signals emit function from external code.
32      *
33      * \note based on Glibmms SignalProxy code
34      */
35 template <class R, class... T>
36 class SignalProxy<R(T...)>
37 {
38 public:
39   using SlotType = sigc::slot<R(T...)>;
40   using SignalType = sigc::signal<R(T...)>;
41
42   SignalProxy ( SignalType &sig ) : _sig ( sig ) {}
43
44   /** Connects a signal handler to a signal.
45          *
46          * For instance, connect(sigc::mem_fun(*this, &TheClass::on_something));
47          *
48          * @param slot The signal handler, usually created with sigc::mem_fun() or sigc::ptr_fun().
49          * @return A sigc::connection.
50          */
51   connection connect( const SlotType& slot )
52   {
53     return _sig.connect( slot );
54   }
55
56   /** Connects a signal handler to a signal.
57          * @see connect(const SlotType& slot).
58          */
59   connection connect( SlotType&& slot )
60   {
61     return _sig.connect( std::move( slot ) );
62   }
63
64 private:
65   SignalType &_sig;
66 };
67
68
69 }
70
71 #endif // ZYPP_NG_CORE_SIGNALS_H_INCLUDED