/
variable.h
68 lines (50 loc) · 1.36 KB
/
variable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright (C) 2016 Dmitry Morozov <dmorozov@outlook.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#ifndef VARIABLE_H
#define VARIABLE_H
#include <QVariant>
class Variable;
typedef QList<Variable> VariableList;
#include <QDebug>
class Callback;
class Variable : public QVariant
{
public:
using QVariant::QVariant;
template<typename T>
static Variable fromValue(const T &value)
{
Variable var;
var.setValue(value);
return var;
}
static Variable fromCodedValue(int type, quint16 uint1, quint16 uint2, quint16 uint3, quint16 uint4);
int addCallback(Callback *callback);
inline void setConstant();
template<typename T>
void setValue(const T &value);
Variable &operator=(const Variable &other);
private:
bool m_constant = false;
QVector<Callback *> m_pendingConnections;
};
template<typename T>
inline void Variable::setValue(const T &value)
{
if (m_constant) {
qWarning("%s: attempt to change a constant variable", Q_FUNC_INFO);
return;
}
QVariant::setValue(value);
}
inline void Variable::setConstant()
{
m_constant = true;
}
#endif // VARIABLE_H