lbrycrd/src/qt/callback.h
practicalswift 64fb0ac016 Declare single-argument (non-converting) constructors "explicit"
In order to avoid unintended implicit conversions.
2017-08-16 16:33:25 +02:00

30 lines
544 B
C++

#ifndef BITCOIN_QT_CALLBACK_H
#define BITCOIN_QT_CALLBACK_H
#include <QObject>
class Callback : public QObject
{
Q_OBJECT
public Q_SLOTS:
virtual void call() = 0;
};
template <typename F>
class FunctionCallback : public Callback
{
F f;
public:
explicit FunctionCallback(F f_) : f(std::move(f_)) {}
~FunctionCallback() override {}
void call() override { f(this); }
};
template <typename F>
FunctionCallback<F>* makeCallback(F f)
{
return new FunctionCallback<F>(std::move(f));
}
#endif // BITCOIN_QT_CALLBACK_H