-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathkcalc_token.h
More file actions
188 lines (169 loc) · 4.02 KB
/
Copy pathkcalc_token.h
File metadata and controls
188 lines (169 loc) · 4.02 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
SPDX-FileCopyrightText: 2023 Gabriel Barrantes <gabriel.barrantes.dev@outlook.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include "kcalc_core_p.h"
#include "kcalc_priority_levels_p.h"
#include "knumber.h"
#include <QDebug>
class KCalcToken
{
public:
KCalcToken();
~KCalcToken();
enum TokenCode {
Knumber,
DecimalPoint,
Plus,
Minus,
InvertSign,
Division,
Slash,
Multiplication,
Dot,
Asterisk,
Percentage,
Permille,
OpeningParenthesis,
ClosingParenthesis,
Square,
Cube,
SquareRoot,
CubicRoot,
Degree,
Gradian,
Radian,
Sin,
SinRad,
SinDeg,
SinGrad,
Cos,
CosRad,
CosDeg,
CosGrad,
Tan,
TanRad,
TanDeg,
TanGrad,
Asin,
AsinRad,
AsinDeg,
AsinGrad,
Acos,
AcosRad,
AcosDeg,
AcosGrad,
Atan,
AtanRad,
AtanDeg,
AtanGrad,
PolarRad,
PolarDeg,
PolarGrad,
ArgRad,
ArgDeg,
ArgGrad,
Sinh,
Cosh,
Tanh,
Asinh,
Acosh,
Atanh,
E,
Pi,
Phi,
I,
Polar,
Re,
Im,
Conj,
PosInfinity,
NegInfinity,
VacuumPermitivity,
VacuumPermeability,
VacuumImpedance,
PlanckSConstant,
PlanckOver2Pi,
Exp,
Exp10,
Power,
PowerRoot,
Factorial,
DoubleFactorial,
Gamma,
Ln,
Log10,
Reciprocal,
Binomial,
Modulo,
IntegerDivision,
And,
Or,
Xor,
OnesComplement,
TwosComplement,
Rsh,
Lsh,
Equal,
Ans,
InvalidToken,
Stub
};
enum TokenType {
KNumberType,
RightUnaryFunctionType,
LeftUnaryFunctionType,
BinaryFunctionType,
OpeningParenthesesType,
ClosingParenthesesType,
NotInitialized
};
KCalcToken(TokenCode tokenCode);
KCalcToken(TokenCode tokenCode, int stringIndex);
KCalcToken(const KNumber &kNumber);
KCalcToken(const KNumber &kNumber, int stringIndex);
bool isKNumber() const;
bool isRightUnaryFunction() const;
bool isLeftUnaryFunction() const;
bool isBinaryFunction() const;
bool isOpeningParentheses() const;
bool isClosingParentheses() const;
TokenCode getTokenCode() const;
TokenType getTokenType() const;
int getPriorityLevel() const;
int getStringIndex() const;
const KNumber getKNumber() const;
KNumber evaluate(const KNumber &kNumber) const;
KNumber evaluate(const KNumber &kNumberLeft, const KNumber &kNumberRight) const;
void invertSignFirstArg();
void invertSignSecondArg();
bool isFirstArgInverted() const;
bool isSecondArgInverted() const;
void updateToken(const KNumber &kNumber);
void updateToken(TokenCode tokenCode);
private:
typedef KNumber (*Unary_Function_Ptr)(const KNumber &);
typedef KNumber (*Binary_Function_Ptr)(const KNumber &, const KNumber &);
KNumber *m_key;
KNumber m_kNumber;
TokenCode m_tokenCode;
TokenType m_tokenType;
Unary_Function_Ptr m_unaryFunctionPtr;
Binary_Function_Ptr m_binaryFunctionPtr;
bool m_isKNumber;
bool m_isRightUnaryFunction;
bool m_isLeftUnaryFunction;
bool m_isBinaryFunction;
bool m_isOpeningParentheses;
bool m_isClosingParentheses;
bool m_invertSignFirstArg;
bool m_invertSignSecondArg;
int m_priorityLevel;
int m_stringIndex;
void setToken(TokenCode tokenCode);
void inline setLeftUnaryToken(Unary_Function_Ptr function, int priorityLevel);
void inline setRightUnaryToken(Unary_Function_Ptr function, int priorityLevel);
void inline setBinaryToken(Binary_Function_Ptr function, int priorityLevel);
void resetToken();
};