1 /* vim:set et ts=4 sts=4:
3 * ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus
5 * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
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)
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.
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.
21 #ifndef __PY_SIGNAL_H_
22 #define __PY_SIGNAL_H_
29 #ifdef __GXX_EXPERIMENTAL_CXX0X__
31 # include <functional>
35 using namespace std::placeholders;
37 // implement signal templates
38 template<typename R = void,
46 template<typename R, typename T1, typename T2, typename T3>
47 struct signal< R(), T1, T2, T3>
49 typedef std::function<R()> func_type;
50 void connect (func_type f) { m_func = f; }
51 R operator ()() const { m_func (); }
56 template<typename R, typename T1, typename T2, typename T3>
57 struct signal< R(T1), T2, T3>
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); }
66 template<typename R, typename T1, typename T2, typename T3>
67 struct signal< R(T1, T2), T3>
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); }
76 template<typename R, typename T1, typename T2, typename T3>
77 struct signal< R(T1, T2, T3)>
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); }
88 #else // __GXX_EXPERIMENTAL_CXX0X__
90 # include <boost/signals2.hpp>
91 # include <boost/bind.hpp>
94 // import boost::bind into std namespace
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 { };
107 #endif // __GXX_EXPERIMENTAL_CXX0X__
108 #endif // __PY_SIGNAL_H_