1
/* This file is part of Clementine.
2
Copyright 2011, David Sansome <me@davidsansome.com>
4
Clementine is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
9
Clementine is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
21
#include <tr1/functional>
23
#include <QMetaMethod>
26
#include <boost/noncopyable.hpp>
27
#include <boost/scoped_ptr.hpp>
29
#include "core/logging.h"
31
class ClosureArgumentWrapper {
33
virtual ~ClosureArgumentWrapper() {}
35
virtual QGenericArgument arg() const = 0;
39
class ClosureArgument : public ClosureArgumentWrapper {
41
ClosureArgument(const T& data) : data_(data) {}
43
virtual QGenericArgument arg() const {
44
return Q_ARG(T, data_);
51
class Closure : public QObject, boost::noncopyable {
55
Closure(QObject* sender, const char* signal,
56
QObject* receiver, const char* slot,
57
const ClosureArgumentWrapper* val0 = 0,
58
const ClosureArgumentWrapper* val1 = 0,
59
const ClosureArgumentWrapper* val2 = 0);
61
Closure(QObject* sender, const char* signal,
62
std::tr1::function<void()> callback);
69
void Connect(QObject* sender, const char* signal);
72
std::tr1::function<void()> callback_;
74
boost::scoped_ptr<const ClosureArgumentWrapper> val0_;
75
boost::scoped_ptr<const ClosureArgumentWrapper> val1_;
76
boost::scoped_ptr<const ClosureArgumentWrapper> val2_;
79
#define C_ARG(type, data) new ClosureArgument<type>(data)
95
sender, signal, receiver, slot,
99
template <typename T0, typename T1>
108
sender, signal, receiver, slot,
109
C_ARG(T0, val0), C_ARG(T1, val1));
112
template <typename T0, typename T1, typename T2>
122
sender, signal, receiver, slot,
123
C_ARG(T0, val0), C_ARG(T1, val1), C_ARG(T2, val2));