forked from Mudlet/Mudlet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTEvent.h
100 lines (93 loc) · 4.5 KB
/
TEvent.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef MUDLET_TEVENT_H
#define MUDLET_TEVENT_H
/***************************************************************************
* Copyright (C) 2008-2009 by Heiko Koehn - KoehnHeiko@googlemail.com *
* Copyright (C) 2016 by Eric Wallace - eewallace@gmail.com *
* Copyright (C) 2016 by Stephen Lyons - slysven@virginmedia.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. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "pre_guard.h"
#include <QDebug>
#include <QDebugStateSaver>
#include <QList>
#include <QStringBuilder>
#include <QStringList>
#include "post_guard.h"
#define ARGUMENT_TYPE_NUMBER 0
#define ARGUMENT_TYPE_STRING 1
#define ARGUMENT_TYPE_BOOLEAN 2
#define ARGUMENT_TYPE_NIL 3
#define ARGUMENT_TYPE_TABLE 4
#define ARGUMENT_TYPE_FUNCTION 5
class TEvent
{
public:
QStringList mArgumentList;
QList<int> mArgumentTypeList;
};
#ifndef QT_NO_DEBUG_STREAM
// Note "inline" is REQUIRED:
inline QDebug& operator<<(QDebug& debug, const TEvent& event)
{
QDebugStateSaver saver(debug);
const int argCount = event.mArgumentList.count();
const int typeCount = event.mArgumentTypeList.count();
int i = 0;
QString result = QLatin1String("TEvent(");
while (i < argCount && i < typeCount) {
if (Q_UNLIKELY(i >= typeCount)) {
result.append(QLatin1String("[") % QString::number(i) % QLatin1String("{missing}") % event.mArgumentList.at(i) % QLatin1String("]"));
} else {
if (Q_UNLIKELY(i >= argCount)) {
switch (event.mArgumentTypeList.at(i)) {
case ARGUMENT_TYPE_NUMBER:
result.append(QLatin1String("[") % QString::number(i) % QLatin1String("{number}missing]"));
break;
case ARGUMENT_TYPE_BOOLEAN:
result.append(QLatin1String("[") % QString::number(i) % QLatin1String("{bool}missing]"));
break;
case ARGUMENT_TYPE_NIL:
result.append(QLatin1String("[") % QString::number(i) % QLatin1String("{nil}missing]"));
break;
default:
result.append(QLatin1String("[") % QString::number(i) % QLatin1String("{string}missing]"));
}
} else {
switch (event.mArgumentTypeList.at(i)) {
case ARGUMENT_TYPE_NUMBER:
result.append(QLatin1String("[") % QString::number(i) % QLatin1String("{number}") % QString::number(event.mArgumentList.at(i).toDouble()) % QLatin1String("]"));
break;
case ARGUMENT_TYPE_BOOLEAN:
result.append(QLatin1String("[") % QString::number(i) % QLatin1String("{bool}") % (event.mArgumentList.at(i).toInt() ? QLatin1String("true") : QLatin1String("false"))
% QLatin1String("]"));
break;
case ARGUMENT_TYPE_NIL:
result.append(QLatin1String("[") % QString::number(i) % QLatin1String("{nil}nil]"));
break;
default:
result.append(QLatin1String("[") % QString::number(i) % QLatin1String("{string}") % event.mArgumentList.at(i) % QLatin1String("]"));
}
}
++i;
}
}
result.append(QLatin1String(")"));
debug.nospace() << result;
return debug;
}
#endif // QT_NO_DEBUG_STREAM
#endif // MUDLET_TEVENT_H