-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
kcalc_core.h
68 lines (52 loc) · 1.63 KB
/
kcalc_core.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
/*
SPDX-FileCopyrightText: 2001-2013 Evan Teran <[email protected]>
SPDX-FileCopyrightText: 1996-2000 Bernd Johannes Wuebben <[email protected]>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include "kcalc_stats.h"
#include "kcalc_token.h"
#include "knumber.h"
#include <QQueue>
class CalcEngine
{
public:
CalcEngine();
enum ResultCode {
SUCCESS,
EMPTY_INPUT,
MATH_ERROR,
MISSING_LEFT_UNARY_ARG,
MISSING_RIGHT_UNARY_ARG,
MISSING_RIGHT_BINARY_ARG,
INCOMPLETE_INPUT,
SYNTAX_ERROR
};
ResultCode calculate(const QQueue<KCalcToken> tokenBuffer, int &errorIndex); // returs 0 on success
KNumber getResult();
KNumber lastOutput(bool &error) const;
public:
void StatClearAll();
void StatCount(const KNumber &input);
void StatDataNew(const KNumber &input);
void StatDataDel();
void StatMean(const KNumber &input);
void StatMedian(const KNumber &input);
void StatStdDeviation(const KNumber &input);
void StatStdSample(const KNumber &input);
void StatSum(const KNumber &input);
void StatSumSquares(const KNumber &input);
public:
void Reset();
private:
KStats stats;
QList<KCalcToken> token_stack_;
const KCalcToken multiplication_Token_ = KCalcToken(KCalcToken::TokenCode::MULTIPLICATION);
int reduce_Stack_(bool toParentheses = true);
int insert_Binary_Function_Token_In_Stack_(const KCalcToken &token);
int insert_KNumber_Token_In_Stack_(const KCalcToken &token);
int insert_percentage_Token_In_Stack_();
void printStacks_();
bool error_;
KNumber buffer_result_;
};