forked from KDE/kcalc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kcalc_token.h
178 lines (159 loc) · 3.95 KB
/
kcalc_token.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
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
/*
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,
DECIMAL_POINT,
PLUS,
MINUS,
INVERT_SIGN,
DIVISION,
SLASH,
MULTIPLICATION,
DOT,
ASTERISK,
PERCENTAGE,
PERMILLE,
OPENING_PARENTHESIS,
CLOSING_PARENTHESIS,
SQUARE,
CUBE,
SQUARE_ROOT,
CUBIC_ROOT,
DEGREE,
GRADIAN,
RADIAN,
SIN,
SIN_RAD,
SIN_DEG,
SIN_GRAD,
COS,
COS_RAD,
COS_DEG,
COS_GRAD,
TAN,
TAN_RAD,
TAN_DEG,
TAN_GRAD,
ASIN,
ASIN_RAD,
ASIN_DEG,
ASIN_GRAD,
ACOS,
ACOS_RAD,
ACOS_DEG,
ACOS_GRAD,
ATAN,
ATAN_RAD,
ATAN_DEG,
ATAN_GRAD,
SINH,
COSH,
TANH,
ASINH,
ACOSH,
ATANH,
E,
PI,
PHI,
I,
POS_INFINITY,
NEG_INFINITY,
VACUUM_PERMITIVITY,
VACUUM_PERMEABILITY,
VACUUM_IMPEDANCE,
PLANCK_S_CONSTANT,
PLANCK_OVER_2PI,
EXP,
EXP_10,
POWER,
POWER_ROOT,
FACTORIAL,
DOUBLE_FACTORIAL,
GAMMA,
LN,
LOG_10,
RECIPROCAL,
BINOMIAL,
MODULO,
INTEGER_DIVISION,
AND,
OR,
XOR,
ONE_S_COMPLEMENT,
TWO_S_COMPLEMENT,
RSH,
LSH,
EQUAL,
ANS,
INVALID_TOKEN,
STUB
};
enum TokenType {
KNUMBER_TYPE,
RIGHT_UNARY_FUNCTION_TYPE,
LEFT_UNARY_FUNCTION_TYPE,
BINARY_FUNCTION_TYPE,
OPENING_PARENTHESES_TYPE,
CLOSING_PARENTHESES_TYPE,
NOT_INITIALIZED
};
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 &);
const KNumber *key_;
KNumber kNumber_;
TokenCode token_Code_;
TokenType token_Type_;
Unary_Function_Ptr unary_Function_Ptr_;
Binary_Function_Ptr binary_Function_Ptr_;
bool is_KNumber_;
bool is_Right_Unary_Function_;
bool is_Left_Unary_Function_;
bool is_Binary_Function_;
bool is_Opening_Parentheses_;
bool is_Closing_Parentheses_;
bool invert_Sign_First_Arg_;
bool invert_Sign_Second_Arg_;
int priority_level_;
int string_index_;
void setToken_(TokenCode tokenCode);
void inline set_Left_Unary_Token_(Unary_Function_Ptr function, int priorityLevel);
void inline set_Right_UnaryToken_(Unary_Function_Ptr function, int priorityLevel);
void inline set_Binary_Token_(Binary_Function_Ptr function, int priorityLevel);
void resetToken_();
};