fixes compile
[platform/upstream/ibus-libpinyin.git] / src / PYSignal.h
1 /* vim:set et ts=4 sts=4:
2  *
3  * ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus
4  *
5  * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20  */
21 #ifndef __PY_SIGNAL_H_
22 #define __PY_SIGNAL_H_
23
24
25 #ifdef HAVE_CONFIG_H
26 #  include <config.h>
27 #endif
28
29 #ifdef __GXX_EXPERIMENTAL_CXX0X__
30
31 #  include <functional>
32
33 namespace PY {
34
35 using namespace std::placeholders;
36
37 // implement signal templates
38 template<typename R  = void,
39          typename T1 = void,
40          typename T2 = void,
41          typename T3 = void>
42 struct signal
43 {
44 };
45
46 template<typename R, typename T1, typename T2, typename T3>
47 struct signal< R(), T1, T2, T3>
48 {
49     typedef std::function<R()> func_type;
50     void connect (func_type f) { m_func = f; }
51     R operator ()() const { m_func (); }
52 private:
53     func_type m_func;
54 };
55
56 template<typename R, typename T1, typename T2, typename T3>
57 struct signal< R(T1), T2, T3>
58 {
59     typedef std::function<R(T1)> func_type;
60     void connect (func_type f) { m_func = f; }
61     R operator ()(T1 a1) const { return m_func (a1); }
62 private:
63     func_type m_func;
64 };
65
66 template<typename R, typename T1, typename T2, typename T3>
67 struct signal< R(T1, T2), T3>
68 {
69     typedef std::function<R(T1, T2)> func_type;
70     void connect (func_type f) { m_func = f; }
71     R operator ()(T1 a1, T2 a2) const { return m_func (a1, a2); }
72 private:
73     func_type m_func;
74 };
75
76 template<typename R, typename T1, typename T2, typename T3>
77 struct signal< R(T1, T2, T3)>
78 {
79     typedef std::function<R(T1, T2, T3)> func_type;
80     void connect (func_type f) {m_func = f; }
81     R operator ()(T1 a1, T2 a2, T3 a3) const { return m_func (a1, a2, a3); }
82 private:
83     func_type m_func;
84 };
85
86 };
87
88 #else // __GXX_EXPERIMENTAL_CXX0X__
89
90 #  include <boost/signals2.hpp>
91 #  include <boost/bind.hpp>
92
93 namespace std {
94     // import boost::bind into std namespace
95     using boost::bind;
96 };
97
98 namespace PY {
99     // use boost::signal2
100     namespace bs2 = boost::signals2;
101     template <typename Signature>
102     struct signal : public bs2::signal_type
103         <Signature, bs2::keywords::mutex_type<bs2::dummy_mutex> >::type { };
104
105 };
106
107 #endif // __GXX_EXPERIMENTAL_CXX0X__
108 #endif // __PY_SIGNAL_H_
109