Fix the project code style, as it is not consistent. (#236)
Fixes #202 This PR fixes code style for the project files. The Problem Different files in the project use different code style. That is not consistent and leads to harder maintenance of the project. Description of the changes: Have investigated and determined the most used code style across the given codebase Have configured IDE and applied code style to all project files. Have crafted clang-formatter config. see https://clang.llvm.org/docs/ClangFormat.html https://clang.llvm.org/docs/ClangFormatStyleOptions.html Some cases were fixed manually How changes were validated: manual/ad-hoc testing, automated testing All tests pass as before because these are only code style changes. Additional Please review, and let me know if I have any mistake in the code style. In case of any mistake, I will change the configuration and re-apply it to the project.
This commit is contained in:
committed by
Daniel Belcher
parent
c77f1de84c
commit
2826d37056
@@ -17,34 +17,33 @@
|
||||
|
||||
// The following are the valid id's which can be passed to CCalcEngine::ProcessCommand
|
||||
|
||||
#define IDM_HEX 313
|
||||
#define IDM_DEC 314
|
||||
#define IDM_OCT 315
|
||||
#define IDM_BIN 316
|
||||
#define IDM_QWORD 317
|
||||
#define IDM_DWORD 318
|
||||
#define IDM_WORD 319
|
||||
#define IDM_BYTE 320
|
||||
#define IDM_DEG 321
|
||||
#define IDM_RAD 322
|
||||
#define IDM_GRAD 323
|
||||
#define IDM_DEGREES 324
|
||||
#define IDM_HEX 313
|
||||
#define IDM_DEC 314
|
||||
#define IDM_OCT 315
|
||||
#define IDM_BIN 316
|
||||
#define IDM_QWORD 317
|
||||
#define IDM_DWORD 318
|
||||
#define IDM_WORD 319
|
||||
#define IDM_BYTE 320
|
||||
#define IDM_DEG 321
|
||||
#define IDM_RAD 322
|
||||
#define IDM_GRAD 323
|
||||
#define IDM_DEGREES 324
|
||||
|
||||
#define IDC_HEX IDM_HEX
|
||||
#define IDC_DEC IDM_DEC
|
||||
#define IDC_OCT IDM_OCT
|
||||
#define IDC_BIN IDM_BIN
|
||||
#define IDC_HEX IDM_HEX
|
||||
#define IDC_DEC IDM_DEC
|
||||
#define IDC_OCT IDM_OCT
|
||||
#define IDC_BIN IDM_BIN
|
||||
|
||||
#define IDC_DEG IDM_DEG
|
||||
#define IDC_RAD IDM_RAD
|
||||
#define IDC_GRAD IDM_GRAD
|
||||
#define IDC_DEGREES IDM_DEGREES
|
||||
|
||||
#define IDC_QWORD IDM_QWORD
|
||||
#define IDC_DWORD IDM_DWORD
|
||||
#define IDC_WORD IDM_WORD
|
||||
#define IDC_BYTE IDM_BYTE
|
||||
#define IDC_DEG IDM_DEG
|
||||
#define IDC_RAD IDM_RAD
|
||||
#define IDC_GRAD IDM_GRAD
|
||||
#define IDC_DEGREES IDM_DEGREES
|
||||
|
||||
#define IDC_QWORD IDM_QWORD
|
||||
#define IDC_DWORD IDM_DWORD
|
||||
#define IDC_WORD IDM_WORD
|
||||
#define IDC_BYTE IDM_BYTE
|
||||
|
||||
// Key IDs:
|
||||
// These id's must be consecutive from IDC_FIRSTCONTROL to IDC_LASTCONTROL.
|
||||
@@ -55,162 +54,158 @@
|
||||
// Find the string id for that control from the rc file
|
||||
// Now define the control's id as IDC_FRISTCONTROL+stringID(IDC_ST_AVE)
|
||||
#define IDC_FIRSTCONTROL IDC_SIGN
|
||||
#define IDC_SIGN 80
|
||||
#define IDC_CLEAR 81
|
||||
#define IDC_CENTR 82
|
||||
#define IDC_BACK 83
|
||||
#define IDC_SIGN 80
|
||||
#define IDC_CLEAR 81
|
||||
#define IDC_CENTR 82
|
||||
#define IDC_BACK 83
|
||||
|
||||
#define IDC_PNT 84
|
||||
#define IDC_PNT 84
|
||||
|
||||
// Hole 85
|
||||
|
||||
#define IDC_AND 86 // Binary operators must be between IDC_AND and IDC_PWR
|
||||
#define IDC_OR 87
|
||||
#define IDC_XOR 88
|
||||
#define IDC_LSHF 89
|
||||
#define IDC_RSHF 90
|
||||
#define IDC_DIV 91
|
||||
#define IDC_MUL 92
|
||||
#define IDC_ADD 93
|
||||
#define IDC_SUB 94
|
||||
#define IDC_MOD 95
|
||||
#define IDC_ROOT 96
|
||||
#define IDC_PWR 97
|
||||
#define IDC_AND 86 // Binary operators must be between IDC_AND and IDC_PWR
|
||||
#define IDC_OR 87
|
||||
#define IDC_XOR 88
|
||||
#define IDC_LSHF 89
|
||||
#define IDC_RSHF 90
|
||||
#define IDC_DIV 91
|
||||
#define IDC_MUL 92
|
||||
#define IDC_ADD 93
|
||||
#define IDC_SUB 94
|
||||
#define IDC_MOD 95
|
||||
#define IDC_ROOT 96
|
||||
#define IDC_PWR 97
|
||||
|
||||
#define IDC_UNARYFIRST IDC_CHOP
|
||||
#define IDC_CHOP 98 // Unary operators must be between IDC_CHOP and IDC_EQU
|
||||
#define IDC_ROL 99
|
||||
#define IDC_ROR 100
|
||||
#define IDC_COM 101
|
||||
#define IDC_SIN 102
|
||||
#define IDC_COS 103
|
||||
#define IDC_TAN 104
|
||||
|
||||
#define IDC_UNARYFIRST IDC_CHOP
|
||||
#define IDC_CHOP 98 // Unary operators must be between IDC_CHOP and IDC_EQU
|
||||
#define IDC_ROL 99
|
||||
#define IDC_ROR 100
|
||||
#define IDC_COM 101
|
||||
#define IDC_SIN 102
|
||||
#define IDC_COS 103
|
||||
#define IDC_TAN 104
|
||||
#define IDC_SINH 105
|
||||
#define IDC_COSH 106
|
||||
#define IDC_TANH 107
|
||||
|
||||
#define IDC_SINH 105
|
||||
#define IDC_COSH 106
|
||||
#define IDC_TANH 107
|
||||
|
||||
#define IDC_LN 108
|
||||
#define IDC_LOG 109
|
||||
#define IDC_SQRT 110
|
||||
#define IDC_SQR 111
|
||||
#define IDC_CUB 112
|
||||
#define IDC_FAC 113
|
||||
#define IDC_REC 114
|
||||
#define IDC_DMS 115
|
||||
#define IDC_CUBEROOT 116 // x ^ 1/3
|
||||
#define IDC_POW10 117 // 10 ^ x
|
||||
#define IDC_PERCENT 118
|
||||
#define IDC_LN 108
|
||||
#define IDC_LOG 109
|
||||
#define IDC_SQRT 110
|
||||
#define IDC_SQR 111
|
||||
#define IDC_CUB 112
|
||||
#define IDC_FAC 113
|
||||
#define IDC_REC 114
|
||||
#define IDC_DMS 115
|
||||
#define IDC_CUBEROOT 116 // x ^ 1/3
|
||||
#define IDC_POW10 117 // 10 ^ x
|
||||
#define IDC_PERCENT 118
|
||||
#define IDC_UNARYLAST IDC_PERCENT
|
||||
|
||||
#define IDC_FE 119
|
||||
#define IDC_PI 120
|
||||
#define IDC_EQU 121
|
||||
#define IDC_FE 119
|
||||
#define IDC_PI 120
|
||||
#define IDC_EQU 121
|
||||
|
||||
#define IDC_MCLEAR 122
|
||||
#define IDC_RECALL 123
|
||||
#define IDC_STORE 124
|
||||
#define IDC_MPLUS 125
|
||||
#define IDC_MMINUS 126
|
||||
#define IDC_MCLEAR 122
|
||||
#define IDC_RECALL 123
|
||||
#define IDC_STORE 124
|
||||
#define IDC_MPLUS 125
|
||||
#define IDC_MMINUS 126
|
||||
|
||||
#define IDC_EXP 127
|
||||
#define IDC_EXP 127
|
||||
|
||||
#define IDC_OPENP 128
|
||||
#define IDC_CLOSEP 129
|
||||
|
||||
#define IDC_OPENP 128
|
||||
#define IDC_CLOSEP 129
|
||||
|
||||
#define IDC_0 130 // The controls for 0 through F must be consecutive and in order
|
||||
#define IDC_1 131
|
||||
#define IDC_2 132
|
||||
#define IDC_3 133
|
||||
#define IDC_4 134
|
||||
#define IDC_5 135
|
||||
#define IDC_6 136
|
||||
#define IDC_7 137
|
||||
#define IDC_8 138
|
||||
#define IDC_9 139
|
||||
#define IDC_A 140
|
||||
#define IDC_B 141
|
||||
#define IDC_C 142
|
||||
#define IDC_D 143
|
||||
#define IDC_E 144
|
||||
#define IDC_F 145 // this is last control ID which must match the string table
|
||||
#define IDC_INV 146
|
||||
#define IDC_SET_RESULT 147
|
||||
#define IDC_0 130 // The controls for 0 through F must be consecutive and in order
|
||||
#define IDC_1 131
|
||||
#define IDC_2 132
|
||||
#define IDC_3 133
|
||||
#define IDC_4 134
|
||||
#define IDC_5 135
|
||||
#define IDC_6 136
|
||||
#define IDC_7 137
|
||||
#define IDC_8 138
|
||||
#define IDC_9 139
|
||||
#define IDC_A 140
|
||||
#define IDC_B 141
|
||||
#define IDC_C 142
|
||||
#define IDC_D 143
|
||||
#define IDC_E 144
|
||||
#define IDC_F 145 // this is last control ID which must match the string table
|
||||
#define IDC_INV 146
|
||||
#define IDC_SET_RESULT 147
|
||||
|
||||
#define IDC_LASTCONTROL IDC_SET_RESULT
|
||||
|
||||
#define IDC_BINEDITSTART 700
|
||||
#define IDC_BINPOS0 700
|
||||
#define IDC_BINPOS1 701
|
||||
#define IDC_BINPOS2 702
|
||||
#define IDC_BINPOS3 703
|
||||
#define IDC_BINPOS4 704
|
||||
#define IDC_BINPOS5 705
|
||||
#define IDC_BINPOS6 706
|
||||
#define IDC_BINPOS7 707
|
||||
#define IDC_BINPOS8 708
|
||||
#define IDC_BINPOS9 709
|
||||
#define IDC_BINPOS10 710
|
||||
#define IDC_BINPOS11 711
|
||||
#define IDC_BINPOS12 712
|
||||
#define IDC_BINPOS13 713
|
||||
#define IDC_BINPOS14 714
|
||||
#define IDC_BINPOS15 715
|
||||
#define IDC_BINPOS16 716
|
||||
#define IDC_BINPOS17 717
|
||||
#define IDC_BINPOS18 718
|
||||
#define IDC_BINPOS19 719
|
||||
#define IDC_BINPOS20 720
|
||||
#define IDC_BINPOS21 721
|
||||
#define IDC_BINPOS22 722
|
||||
#define IDC_BINPOS23 723
|
||||
#define IDC_BINPOS24 724
|
||||
#define IDC_BINPOS25 725
|
||||
#define IDC_BINPOS26 726
|
||||
#define IDC_BINPOS27 727
|
||||
#define IDC_BINPOS28 728
|
||||
#define IDC_BINPOS29 729
|
||||
#define IDC_BINPOS30 730
|
||||
#define IDC_BINPOS31 731
|
||||
#define IDC_BINPOS32 732
|
||||
#define IDC_BINPOS33 733
|
||||
#define IDC_BINPOS34 734
|
||||
#define IDC_BINPOS35 735
|
||||
#define IDC_BINPOS36 736
|
||||
#define IDC_BINPOS37 737
|
||||
#define IDC_BINPOS38 738
|
||||
#define IDC_BINPOS39 739
|
||||
#define IDC_BINPOS40 740
|
||||
#define IDC_BINPOS41 741
|
||||
#define IDC_BINPOS42 742
|
||||
#define IDC_BINPOS43 743
|
||||
#define IDC_BINPOS44 744
|
||||
#define IDC_BINPOS45 745
|
||||
#define IDC_BINPOS46 746
|
||||
#define IDC_BINPOS47 747
|
||||
#define IDC_BINPOS48 748
|
||||
#define IDC_BINPOS49 749
|
||||
#define IDC_BINPOS50 750
|
||||
#define IDC_BINPOS51 751
|
||||
#define IDC_BINPOS52 752
|
||||
#define IDC_BINPOS53 753
|
||||
#define IDC_BINPOS54 754
|
||||
#define IDC_BINPOS55 755
|
||||
#define IDC_BINPOS56 756
|
||||
#define IDC_BINPOS57 757
|
||||
#define IDC_BINPOS58 758
|
||||
#define IDC_BINPOS59 759
|
||||
#define IDC_BINPOS60 760
|
||||
#define IDC_BINPOS61 761
|
||||
#define IDC_BINPOS62 762
|
||||
#define IDC_BINPOS63 763
|
||||
#define IDC_BINEDITEND 763
|
||||
|
||||
#define IDC_BINEDITSTART 700
|
||||
#define IDC_BINPOS0 700
|
||||
#define IDC_BINPOS1 701
|
||||
#define IDC_BINPOS2 702
|
||||
#define IDC_BINPOS3 703
|
||||
#define IDC_BINPOS4 704
|
||||
#define IDC_BINPOS5 705
|
||||
#define IDC_BINPOS6 706
|
||||
#define IDC_BINPOS7 707
|
||||
#define IDC_BINPOS8 708
|
||||
#define IDC_BINPOS9 709
|
||||
#define IDC_BINPOS10 710
|
||||
#define IDC_BINPOS11 711
|
||||
#define IDC_BINPOS12 712
|
||||
#define IDC_BINPOS13 713
|
||||
#define IDC_BINPOS14 714
|
||||
#define IDC_BINPOS15 715
|
||||
#define IDC_BINPOS16 716
|
||||
#define IDC_BINPOS17 717
|
||||
#define IDC_BINPOS18 718
|
||||
#define IDC_BINPOS19 719
|
||||
#define IDC_BINPOS20 720
|
||||
#define IDC_BINPOS21 721
|
||||
#define IDC_BINPOS22 722
|
||||
#define IDC_BINPOS23 723
|
||||
#define IDC_BINPOS24 724
|
||||
#define IDC_BINPOS25 725
|
||||
#define IDC_BINPOS26 726
|
||||
#define IDC_BINPOS27 727
|
||||
#define IDC_BINPOS28 728
|
||||
#define IDC_BINPOS29 729
|
||||
#define IDC_BINPOS30 730
|
||||
#define IDC_BINPOS31 731
|
||||
#define IDC_BINPOS32 732
|
||||
#define IDC_BINPOS33 733
|
||||
#define IDC_BINPOS34 734
|
||||
#define IDC_BINPOS35 735
|
||||
#define IDC_BINPOS36 736
|
||||
#define IDC_BINPOS37 737
|
||||
#define IDC_BINPOS38 738
|
||||
#define IDC_BINPOS39 739
|
||||
#define IDC_BINPOS40 740
|
||||
#define IDC_BINPOS41 741
|
||||
#define IDC_BINPOS42 742
|
||||
#define IDC_BINPOS43 743
|
||||
#define IDC_BINPOS44 744
|
||||
#define IDC_BINPOS45 745
|
||||
#define IDC_BINPOS46 746
|
||||
#define IDC_BINPOS47 747
|
||||
#define IDC_BINPOS48 748
|
||||
#define IDC_BINPOS49 749
|
||||
#define IDC_BINPOS50 750
|
||||
#define IDC_BINPOS51 751
|
||||
#define IDC_BINPOS52 752
|
||||
#define IDC_BINPOS53 753
|
||||
#define IDC_BINPOS54 754
|
||||
#define IDC_BINPOS55 755
|
||||
#define IDC_BINPOS56 756
|
||||
#define IDC_BINPOS57 757
|
||||
#define IDC_BINPOS58 758
|
||||
#define IDC_BINPOS59 759
|
||||
#define IDC_BINPOS60 760
|
||||
#define IDC_BINPOS61 761
|
||||
#define IDC_BINPOS62 762
|
||||
#define IDC_BINPOS63 763
|
||||
#define IDC_BINEDITEND 763
|
||||
|
||||
// The strings in the following range IDS_ENGINESTR_FIRST ... IDS_ENGINESTR_MAX are strings allocated in the
|
||||
// resource for the purpose internal to Engine and cant be used by the clients
|
||||
#define IDS_ENGINESTR_FIRST 0
|
||||
#define IDS_ENGINESTR_MAX 200
|
||||
|
||||
#define IDS_ENGINESTR_FIRST 0
|
||||
#define IDS_ENGINESTR_MAX 200
|
||||
|
@@ -20,7 +20,7 @@
|
||||
#include "../CalculatorVector.h"
|
||||
#include "../ExpressionCommand.h"
|
||||
#include "RadixType.h"
|
||||
#include "History.h" // for History Collector
|
||||
#include "History.h" // for History Collector
|
||||
#include "CalcInput.h"
|
||||
#include "CalcUtils.h"
|
||||
#include "ICalcDisplay.h"
|
||||
@@ -31,11 +31,12 @@
|
||||
// The real exports follows later
|
||||
|
||||
// This is expected to be in same order as IDM_QWORD, IDM_DWORD etc.
|
||||
enum eNUM_WIDTH {
|
||||
QWORD_WIDTH, // Number width of 64 bits mode (default)
|
||||
DWORD_WIDTH, // Number width of 32 bits mode
|
||||
WORD_WIDTH, // Number width of 16 bits mode
|
||||
BYTE_WIDTH // Number width of 16 bits mode
|
||||
enum eNUM_WIDTH
|
||||
{
|
||||
QWORD_WIDTH, // Number width of 64 bits mode (default)
|
||||
DWORD_WIDTH, // Number width of 32 bits mode
|
||||
WORD_WIDTH, // Number width of 16 bits mode
|
||||
BYTE_WIDTH // Number width of 16 bits mode
|
||||
};
|
||||
typedef enum eNUM_WIDTH NUM_WIDTH;
|
||||
static constexpr size_t NUM_WIDTH_LENGTH = 4;
|
||||
@@ -50,58 +51,80 @@ namespace CalculatorEngineTests
|
||||
class CalcEngineTests;
|
||||
}
|
||||
|
||||
class CCalcEngine {
|
||||
class CCalcEngine
|
||||
{
|
||||
public:
|
||||
CCalcEngine(bool fPrecedence, bool fIntegerMode, CalculationManager::IResourceProvider* const pResourceProvider, __in_opt ICalcDisplay *pCalcDisplay, __in_opt std::shared_ptr<IHistoryDisplay> pHistoryDisplay);
|
||||
CCalcEngine(bool fPrecedence, bool fIntegerMode, CalculationManager::IResourceProvider* const pResourceProvider, __in_opt ICalcDisplay* pCalcDisplay,
|
||||
__in_opt std::shared_ptr<IHistoryDisplay> pHistoryDisplay);
|
||||
void ProcessCommand(OpCode wID);
|
||||
void DisplayError (uint32_t nError);
|
||||
void DisplayError(uint32_t nError);
|
||||
std::unique_ptr<CalcEngine::Rational> PersistedMemObject();
|
||||
void PersistedMemObject(CalcEngine::Rational const& memObject);
|
||||
bool FInErrorState() { return m_bError; }
|
||||
bool FInRecordingState() { return m_bRecord; }
|
||||
bool FInErrorState()
|
||||
{
|
||||
return m_bError;
|
||||
}
|
||||
bool FInRecordingState()
|
||||
{
|
||||
return m_bRecord;
|
||||
}
|
||||
void SettingsChanged();
|
||||
bool IsCurrentTooBigForTrig();
|
||||
int GetCurrentRadix();
|
||||
std::wstring GetCurrentResultForRadix(uint32_t radix, int32_t precision);
|
||||
void ChangePrecision(int32_t precision) { m_precision = precision; ChangeConstants(m_radix, precision); }
|
||||
void ChangePrecision(int32_t precision)
|
||||
{
|
||||
m_precision = precision;
|
||||
ChangeConstants(m_radix, precision);
|
||||
}
|
||||
std::wstring GroupDigitsPerRadix(std::wstring_view numberString, uint32_t radix);
|
||||
std::wstring GetStringForDisplay(CalcEngine::Rational const& rat, uint32_t radix);
|
||||
void UpdateMaxIntDigits();
|
||||
wchar_t DecimalSeparator() const;
|
||||
|
||||
// Static methods for the instance
|
||||
static void InitialOneTimeOnlySetup(CalculationManager::IResourceProvider& resourceProvider); // Once per load time to call to initialize all shared global variables
|
||||
static void
|
||||
InitialOneTimeOnlySetup(CalculationManager::IResourceProvider& resourceProvider); // Once per load time to call to initialize all shared global variables
|
||||
// returns the ptr to string representing the operator. Mostly same as the button, but few special cases for x^y etc.
|
||||
static std::wstring_view GetString(int ids) { return s_engineStrings[std::to_wstring(ids)]; }
|
||||
static std::wstring_view GetString(std::wstring ids) { return s_engineStrings[ids]; }
|
||||
static std::wstring_view OpCodeToString(int nOpCode) { return GetString(IdStrFromCmdId(nOpCode)); }
|
||||
static std::wstring_view GetString(int ids)
|
||||
{
|
||||
return s_engineStrings[std::to_wstring(ids)];
|
||||
}
|
||||
static std::wstring_view GetString(std::wstring ids)
|
||||
{
|
||||
return s_engineStrings[ids];
|
||||
}
|
||||
static std::wstring_view OpCodeToString(int nOpCode)
|
||||
{
|
||||
return GetString(IdStrFromCmdId(nOpCode));
|
||||
}
|
||||
static std::wstring_view OpCodeToUnaryString(int nOpCode, bool fInv, ANGLE_TYPE angletype);
|
||||
|
||||
private:
|
||||
bool m_fPrecedence;
|
||||
bool m_fIntegerMode; /* This is true if engine is explicitly called to be in integer mode. All bases are restricted to be in integers only */
|
||||
ICalcDisplay *m_pCalcDisplay;
|
||||
ICalcDisplay* m_pCalcDisplay;
|
||||
CalculationManager::IResourceProvider* const m_resourceProvider;
|
||||
int m_nOpCode; /* ID value of operation. */
|
||||
int m_nOpCode; /* ID value of operation. */
|
||||
int m_nPrevOpCode; // opcode which computed the number in m_currentVal. 0 if it is already bracketed or plain number or
|
||||
// if it hasn't yet been computed
|
||||
bool m_bChangeOp; /* Flag for changing operation. */
|
||||
bool m_bRecord; // Global mode: recording or displaying
|
||||
bool m_bSetCalcState; // Flag for setting the engine result state
|
||||
bool m_bChangeOp; /* Flag for changing operation. */
|
||||
bool m_bRecord; // Global mode: recording or displaying
|
||||
bool m_bSetCalcState; // Flag for setting the engine result state
|
||||
CalcEngine::CalcInput m_input; // Global calc input object for decimal strings
|
||||
eNUMOBJ_FMT m_nFE; /* Scientific notation conversion flag. */
|
||||
eNUMOBJ_FMT m_nFE; /* Scientific notation conversion flag. */
|
||||
CalcEngine::Rational m_maxTrigonometricNum;
|
||||
std::unique_ptr<CalcEngine::Rational> m_memoryValue; // Current memory value.
|
||||
|
||||
CalcEngine::Rational m_holdVal; // For holding the second operand in repetitive calculations ( pressing "=" continuously)
|
||||
|
||||
CalcEngine::Rational m_currentVal; // Currently displayed number used everywhere.
|
||||
CalcEngine::Rational m_lastVal; // Number before operation (left operand).
|
||||
std::array<CalcEngine::Rational, MAXPRECDEPTH> m_parenVals; // Holding array for parenthesis values.
|
||||
CalcEngine::Rational m_currentVal; // Currently displayed number used everywhere.
|
||||
CalcEngine::Rational m_lastVal; // Number before operation (left operand).
|
||||
std::array<CalcEngine::Rational, MAXPRECDEPTH> m_parenVals; // Holding array for parenthesis values.
|
||||
std::array<CalcEngine::Rational, MAXPRECDEPTH> m_precedenceVals; // Holding array for precedence values.
|
||||
bool m_bError; // Error flag.
|
||||
bool m_bInv; // Inverse on/off flag.
|
||||
bool m_bNoPrevEqu; /* Flag for previous equals. */
|
||||
bool m_bError; // Error flag.
|
||||
bool m_bInv; // Inverse on/off flag.
|
||||
bool m_bNoPrevEqu; /* Flag for previous equals. */
|
||||
|
||||
uint32_t m_radix;
|
||||
int32_t m_precision;
|
||||
@@ -110,20 +133,20 @@ private:
|
||||
|
||||
std::wstring m_numberString;
|
||||
|
||||
int m_nTempCom; /* Holding place for the last command. */
|
||||
int m_openParenCount; // Number of open parentheses.
|
||||
std::array<int, MAXPRECDEPTH> m_nOp; /* Holding array for parenthesis operations. */
|
||||
std::array<int, MAXPRECDEPTH> m_nPrecOp; /* Holding array for precedence operations. */
|
||||
size_t m_precedenceOpCount; /* Current number of precedence ops in holding. */
|
||||
int m_nLastCom; // Last command entered.
|
||||
ANGLE_TYPE m_angletype; // Current Angle type when in dec mode. one of deg, rad or grad
|
||||
NUM_WIDTH m_numwidth; // one of qword, dword, word or byte mode.
|
||||
int32_t m_dwWordBitWidth; // # of bits in currently selected word size
|
||||
int m_nTempCom; /* Holding place for the last command. */
|
||||
int m_openParenCount; // Number of open parentheses.
|
||||
std::array<int, MAXPRECDEPTH> m_nOp; /* Holding array for parenthesis operations. */
|
||||
std::array<int, MAXPRECDEPTH> m_nPrecOp; /* Holding array for precedence operations. */
|
||||
size_t m_precedenceOpCount; /* Current number of precedence ops in holding. */
|
||||
int m_nLastCom; // Last command entered.
|
||||
ANGLE_TYPE m_angletype; // Current Angle type when in dec mode. one of deg, rad or grad
|
||||
NUM_WIDTH m_numwidth; // one of qword, dword, word or byte mode.
|
||||
int32_t m_dwWordBitWidth; // # of bits in currently selected word size
|
||||
|
||||
CHistoryCollector m_HistoryCollector; // Accumulator of each line of history as various commands are processed
|
||||
|
||||
std::array<CalcEngine::Rational, NUM_WIDTH_LENGTH> m_chopNumbers; // word size enforcement
|
||||
std::array<std::wstring, NUM_WIDTH_LENGTH> m_maxDecimalValueStrings; // maximum values represented by a given word width based off m_chopNumbers
|
||||
std::array<CalcEngine::Rational, NUM_WIDTH_LENGTH> m_chopNumbers; // word size enforcement
|
||||
std::array<std::wstring, NUM_WIDTH_LENGTH> m_maxDecimalValueStrings; // maximum values represented by a given word width based off m_chopNumbers
|
||||
static std::unordered_map<std::wstring, std::wstring> s_engineStrings; // the string table shared across all instances
|
||||
wchar_t m_decimalSeparator;
|
||||
wchar_t m_groupSeparator;
|
||||
@@ -143,7 +166,7 @@ private:
|
||||
CalcEngine::Rational DoOperation(int operation, CalcEngine::Rational const& lhs, CalcEngine::Rational const& rhs);
|
||||
void SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwidth);
|
||||
int32_t DwWordBitWidthFromeNumWidth(NUM_WIDTH numwidth);
|
||||
uint32_t NRadixFromRadixType( RADIX_TYPE radixtype);
|
||||
uint32_t NRadixFromRadixType(RADIX_TYPE radixtype);
|
||||
|
||||
bool TryToggleBit(CalcEngine::Rational& rat, uint32_t wbitno);
|
||||
void CheckAndAddLastBinOpToHistory(bool addToHistory = true);
|
||||
@@ -151,7 +174,10 @@ private:
|
||||
void InitChopNumbers();
|
||||
|
||||
static void LoadEngineStrings(CalculationManager::IResourceProvider& resourceProvider);
|
||||
static int IdStrFromCmdId(int id) { return id - IDC_FIRSTCONTROL + IDS_ENGINESTR_FIRST; }
|
||||
static int IdStrFromCmdId(int id)
|
||||
{
|
||||
return id - IDC_FIRSTCONTROL + IDS_ENGINESTR_FIRST;
|
||||
}
|
||||
|
||||
static std::vector<uint32_t> DigitGroupingStringToGroupingVector(std::wstring_view groupingString);
|
||||
std::wstring GroupDigits(std::wstring_view delimiter, std::vector<uint32_t> const& grouping, std::wstring_view displayString, bool isNumNegative = false);
|
||||
|
@@ -13,16 +13,24 @@ namespace CalcEngine
|
||||
class CalcNumSec
|
||||
{
|
||||
public:
|
||||
CalcNumSec() :
|
||||
value(),
|
||||
m_isNegative(false)
|
||||
{}
|
||||
CalcNumSec() : value(), m_isNegative(false)
|
||||
{
|
||||
}
|
||||
|
||||
void Clear();
|
||||
bool IsEmpty() { return value.empty(); }
|
||||
bool IsEmpty()
|
||||
{
|
||||
return value.empty();
|
||||
}
|
||||
|
||||
bool IsNegative() { return m_isNegative; }
|
||||
void IsNegative(bool isNegative) { m_isNegative = isNegative; }
|
||||
bool IsNegative()
|
||||
{
|
||||
return m_isNegative;
|
||||
}
|
||||
void IsNegative(bool isNegative)
|
||||
{
|
||||
m_isNegative = isNegative;
|
||||
}
|
||||
|
||||
std::wstring value;
|
||||
|
||||
@@ -34,16 +42,12 @@ namespace CalcEngine
|
||||
{
|
||||
public:
|
||||
CalcInput() : CalcInput(L'.')
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
CalcInput(wchar_t decSymbol) :
|
||||
m_hasExponent(false),
|
||||
m_hasDecimal(false),
|
||||
m_decPtIndex(0),
|
||||
m_decSymbol(decSymbol),
|
||||
m_base(),
|
||||
m_exponent()
|
||||
{}
|
||||
CalcInput(wchar_t decSymbol) : m_hasExponent(false), m_hasDecimal(false), m_decPtIndex(0), m_decSymbol(decSymbol), m_base(), m_exponent()
|
||||
{
|
||||
}
|
||||
|
||||
void Clear();
|
||||
bool TryToggleSign(bool isIntegerMode, std::wstring_view maxNumStr);
|
||||
|
@@ -171,126 +171,123 @@ inline constexpr auto SIDS_ERR_INPUT_OVERFLOW = L"119";
|
||||
inline constexpr auto SIDS_ERR_OUTPUT_OVERFLOW = L"120";
|
||||
|
||||
// Include the resource key ID from above into this vector to load it into memory for the engine to use
|
||||
inline constexpr std::array<std::wstring_view, 120> g_sids =
|
||||
{
|
||||
SIDS_PLUS_MINUS,
|
||||
SIDS_C,
|
||||
SIDS_CE,
|
||||
SIDS_BACKSPACE,
|
||||
SIDS_DECIMAL_SEPARATOR,
|
||||
SIDS_EMPTY_STRING,
|
||||
SIDS_AND,
|
||||
SIDS_OR,
|
||||
SIDS_XOR,
|
||||
SIDS_LSH,
|
||||
SIDS_RSH,
|
||||
SIDS_DIVIDE,
|
||||
SIDS_MULTIPLY,
|
||||
SIDS_PLUS,
|
||||
SIDS_MINUS,
|
||||
SIDS_MOD,
|
||||
SIDS_YROOT,
|
||||
SIDS_POW_HAT,
|
||||
SIDS_INT,
|
||||
SIDS_ROL,
|
||||
SIDS_ROR,
|
||||
SIDS_NOT,
|
||||
SIDS_SIN,
|
||||
SIDS_COS,
|
||||
SIDS_TAN,
|
||||
SIDS_SINH,
|
||||
SIDS_COSH,
|
||||
SIDS_TANH,
|
||||
SIDS_LN,
|
||||
SIDS_LOG,
|
||||
SIDS_SQRT,
|
||||
SIDS_XPOW2,
|
||||
SIDS_XPOW3,
|
||||
SIDS_NFACTORIAL,
|
||||
SIDS_RECIPROCAL,
|
||||
SIDS_DMS,
|
||||
SIDS_CUBEROOT,
|
||||
SIDS_POWTEN,
|
||||
SIDS_PERCENT,
|
||||
SIDS_SCIENTIFIC_NOTATION,
|
||||
SIDS_PI,
|
||||
SIDS_EQUAL,
|
||||
SIDS_MC,
|
||||
SIDS_MR,
|
||||
SIDS_MS,
|
||||
SIDS_MPLUS,
|
||||
SIDS_MMINUS,
|
||||
SIDS_EXP,
|
||||
SIDS_OPEN_PAREN,
|
||||
SIDS_CLOSE_PAREN,
|
||||
SIDS_0,
|
||||
SIDS_1,
|
||||
SIDS_2,
|
||||
SIDS_3,
|
||||
SIDS_4,
|
||||
SIDS_5,
|
||||
SIDS_6,
|
||||
SIDS_7,
|
||||
SIDS_8,
|
||||
SIDS_9,
|
||||
SIDS_A,
|
||||
SIDS_B,
|
||||
SIDS_C,
|
||||
SIDS_D,
|
||||
SIDS_E,
|
||||
SIDS_F,
|
||||
SIDS_FRAC,
|
||||
SIDS_SIND,
|
||||
SIDS_COSD,
|
||||
SIDS_TAND,
|
||||
SIDS_ASIND,
|
||||
SIDS_ACOSD,
|
||||
SIDS_ATAND,
|
||||
SIDS_SINR,
|
||||
SIDS_COSR,
|
||||
SIDS_TANR,
|
||||
SIDS_ASINR,
|
||||
SIDS_ACOSR,
|
||||
SIDS_ATANR,
|
||||
SIDS_SING,
|
||||
SIDS_COSG,
|
||||
SIDS_TANG,
|
||||
SIDS_ASING,
|
||||
SIDS_ACOSG,
|
||||
SIDS_ATANG,
|
||||
SIDS_ASINH,
|
||||
SIDS_ACOSH,
|
||||
SIDS_ATANH,
|
||||
SIDS_POWE,
|
||||
SIDS_POWTEN2,
|
||||
SIDS_SQRT2,
|
||||
SIDS_SQR,
|
||||
SIDS_CUBE,
|
||||
SIDS_CUBERT,
|
||||
SIDS_FACT,
|
||||
SIDS_RECIPROC,
|
||||
SIDS_DEGREES,
|
||||
SIDS_NEGATE,
|
||||
SIDS_RSH,
|
||||
SIDS_DIVIDEBYZERO,
|
||||
SIDS_DOMAIN,
|
||||
SIDS_UNDEFINED,
|
||||
SIDS_POS_INFINITY,
|
||||
SIDS_NEG_INFINITY,
|
||||
SIDS_ABORTED,
|
||||
SIDS_NOMEM,
|
||||
SIDS_TOOMANY,
|
||||
SIDS_OVERFLOW,
|
||||
SIDS_NORESULT,
|
||||
SIDS_INSUFFICIENT_DATA,
|
||||
SIDS_ERR_UNK_CH,
|
||||
SIDS_ERR_UNK_FN,
|
||||
SIDS_ERR_UNEX_NUM,
|
||||
SIDS_ERR_UNEX_CH,
|
||||
SIDS_ERR_UNEX_SZ,
|
||||
SIDS_ERR_MISMATCH_CLOSE,
|
||||
SIDS_ERR_UNEX_END,
|
||||
SIDS_ERR_SG_INV_ERROR,
|
||||
SIDS_ERR_INPUT_OVERFLOW,
|
||||
SIDS_ERR_OUTPUT_OVERFLOW
|
||||
};
|
||||
inline constexpr std::array<std::wstring_view, 120> g_sids = { SIDS_PLUS_MINUS,
|
||||
SIDS_C,
|
||||
SIDS_CE,
|
||||
SIDS_BACKSPACE,
|
||||
SIDS_DECIMAL_SEPARATOR,
|
||||
SIDS_EMPTY_STRING,
|
||||
SIDS_AND,
|
||||
SIDS_OR,
|
||||
SIDS_XOR,
|
||||
SIDS_LSH,
|
||||
SIDS_RSH,
|
||||
SIDS_DIVIDE,
|
||||
SIDS_MULTIPLY,
|
||||
SIDS_PLUS,
|
||||
SIDS_MINUS,
|
||||
SIDS_MOD,
|
||||
SIDS_YROOT,
|
||||
SIDS_POW_HAT,
|
||||
SIDS_INT,
|
||||
SIDS_ROL,
|
||||
SIDS_ROR,
|
||||
SIDS_NOT,
|
||||
SIDS_SIN,
|
||||
SIDS_COS,
|
||||
SIDS_TAN,
|
||||
SIDS_SINH,
|
||||
SIDS_COSH,
|
||||
SIDS_TANH,
|
||||
SIDS_LN,
|
||||
SIDS_LOG,
|
||||
SIDS_SQRT,
|
||||
SIDS_XPOW2,
|
||||
SIDS_XPOW3,
|
||||
SIDS_NFACTORIAL,
|
||||
SIDS_RECIPROCAL,
|
||||
SIDS_DMS,
|
||||
SIDS_CUBEROOT,
|
||||
SIDS_POWTEN,
|
||||
SIDS_PERCENT,
|
||||
SIDS_SCIENTIFIC_NOTATION,
|
||||
SIDS_PI,
|
||||
SIDS_EQUAL,
|
||||
SIDS_MC,
|
||||
SIDS_MR,
|
||||
SIDS_MS,
|
||||
SIDS_MPLUS,
|
||||
SIDS_MMINUS,
|
||||
SIDS_EXP,
|
||||
SIDS_OPEN_PAREN,
|
||||
SIDS_CLOSE_PAREN,
|
||||
SIDS_0,
|
||||
SIDS_1,
|
||||
SIDS_2,
|
||||
SIDS_3,
|
||||
SIDS_4,
|
||||
SIDS_5,
|
||||
SIDS_6,
|
||||
SIDS_7,
|
||||
SIDS_8,
|
||||
SIDS_9,
|
||||
SIDS_A,
|
||||
SIDS_B,
|
||||
SIDS_C,
|
||||
SIDS_D,
|
||||
SIDS_E,
|
||||
SIDS_F,
|
||||
SIDS_FRAC,
|
||||
SIDS_SIND,
|
||||
SIDS_COSD,
|
||||
SIDS_TAND,
|
||||
SIDS_ASIND,
|
||||
SIDS_ACOSD,
|
||||
SIDS_ATAND,
|
||||
SIDS_SINR,
|
||||
SIDS_COSR,
|
||||
SIDS_TANR,
|
||||
SIDS_ASINR,
|
||||
SIDS_ACOSR,
|
||||
SIDS_ATANR,
|
||||
SIDS_SING,
|
||||
SIDS_COSG,
|
||||
SIDS_TANG,
|
||||
SIDS_ASING,
|
||||
SIDS_ACOSG,
|
||||
SIDS_ATANG,
|
||||
SIDS_ASINH,
|
||||
SIDS_ACOSH,
|
||||
SIDS_ATANH,
|
||||
SIDS_POWE,
|
||||
SIDS_POWTEN2,
|
||||
SIDS_SQRT2,
|
||||
SIDS_SQR,
|
||||
SIDS_CUBE,
|
||||
SIDS_CUBERT,
|
||||
SIDS_FACT,
|
||||
SIDS_RECIPROC,
|
||||
SIDS_DEGREES,
|
||||
SIDS_NEGATE,
|
||||
SIDS_RSH,
|
||||
SIDS_DIVIDEBYZERO,
|
||||
SIDS_DOMAIN,
|
||||
SIDS_UNDEFINED,
|
||||
SIDS_POS_INFINITY,
|
||||
SIDS_NEG_INFINITY,
|
||||
SIDS_ABORTED,
|
||||
SIDS_NOMEM,
|
||||
SIDS_TOOMANY,
|
||||
SIDS_OVERFLOW,
|
||||
SIDS_NORESULT,
|
||||
SIDS_INSUFFICIENT_DATA,
|
||||
SIDS_ERR_UNK_CH,
|
||||
SIDS_ERR_UNK_FN,
|
||||
SIDS_ERR_UNEX_NUM,
|
||||
SIDS_ERR_UNEX_CH,
|
||||
SIDS_ERR_UNEX_SZ,
|
||||
SIDS_ERR_MISMATCH_CLOSE,
|
||||
SIDS_ERR_UNEX_END,
|
||||
SIDS_ERR_SG_INV_ERROR,
|
||||
SIDS_ERR_INPUT_OVERFLOW,
|
||||
SIDS_ERR_OUTPUT_OVERFLOW };
|
||||
|
@@ -14,9 +14,10 @@ static constexpr size_t MAXPRECDEPTH = 25;
|
||||
// Helper class really a internal class to CCalcEngine, to accumulate each history line of text by collecting the
|
||||
// operands, operator, unary operator etc. Since it is a separate entity, it can be unit tested on its own but does
|
||||
// rely on CCalcEngine calling it in appropriate order.
|
||||
class CHistoryCollector {
|
||||
class CHistoryCollector
|
||||
{
|
||||
public:
|
||||
CHistoryCollector(ICalcDisplay *pCalcDisplay, std::shared_ptr<IHistoryDisplay> pHistoryDisplay, wchar_t decimalSymbol); // Can throw errors
|
||||
CHistoryCollector(ICalcDisplay* pCalcDisplay, std::shared_ptr<IHistoryDisplay> pHistoryDisplay, wchar_t decimalSymbol); // Can throw errors
|
||||
~CHistoryCollector();
|
||||
void AddOpndToHistory(std::wstring_view numStr, CalcEngine::Rational const& rat, bool fRepetition = false);
|
||||
void RemoveLastOpndFromHistory();
|
||||
@@ -31,24 +32,25 @@ public:
|
||||
bool FOpndAddedToHistory();
|
||||
void CompleteHistoryLine(std::wstring_view numStr);
|
||||
void ClearHistoryLine(std::wstring_view errStr);
|
||||
int AddCommand(_In_ const std::shared_ptr<IExpressionCommand> & spCommand);
|
||||
int AddCommand(_In_ const std::shared_ptr<IExpressionCommand>& spCommand);
|
||||
void UpdateHistoryExpression(uint32_t radix, int32_t precision);
|
||||
void SetDecimalSymbol(wchar_t decimalSymbol);
|
||||
|
||||
private:
|
||||
std::shared_ptr<IHistoryDisplay> m_pHistoryDisplay;
|
||||
ICalcDisplay *m_pCalcDisplay;
|
||||
ICalcDisplay* m_pCalcDisplay;
|
||||
|
||||
int m_iCurLineHistStart; // index of the beginning of the current equation
|
||||
// a sort of state, set to the index before 2 after 2 in the expression 2 + 3 say. Useful for auto correct portion of history and for
|
||||
// attaching the unary op around the last operand
|
||||
int m_lastOpStartIndex; // index of the beginning of the last operand added to the history
|
||||
int m_lastOpStartIndex; // index of the beginning of the last operand added to the history
|
||||
int m_lastBinOpStartIndex; // index of the beginning of the last binary operator added to the history
|
||||
std::array<int, MAXPRECDEPTH> m_operandIndices; // Stack of index of opnd's beginning for each '('. A parallel array to m_hnoParNum, but abstracted independently of that
|
||||
std::array<int, MAXPRECDEPTH>
|
||||
m_operandIndices; // Stack of index of opnd's beginning for each '('. A parallel array to m_hnoParNum, but abstracted independently of that
|
||||
int m_curOperandIndex; // Stack index for the above stack
|
||||
bool m_bLastOpndBrace; // iff the last opnd in history is already braced so we can avoid putting another one for unary operator
|
||||
bool m_bLastOpndBrace; // iff the last opnd in history is already braced so we can avoid putting another one for unary operator
|
||||
wchar_t m_decimalSymbol;
|
||||
std::shared_ptr<CalculatorVector <std::pair<std::wstring, int>>> m_spTokens;
|
||||
std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> m_spTokens;
|
||||
std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> m_spCommands;
|
||||
|
||||
private:
|
||||
|
@@ -7,11 +7,13 @@
|
||||
#include "../ExpressionCommandInterface.h"
|
||||
|
||||
// Callback interface to be implemented by the clients of CCalcEngine
|
||||
class ICalcDisplay {
|
||||
class ICalcDisplay
|
||||
{
|
||||
public:
|
||||
virtual void SetPrimaryDisplay(const std::wstring& pszText, bool isError) = 0;
|
||||
virtual void SetIsInError(bool isInError) = 0;
|
||||
virtual void SetExpressionDisplay(_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const &tokens, _Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const &commands) = 0;
|
||||
virtual void SetExpressionDisplay(_Inout_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& tokens,
|
||||
_Inout_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& commands) = 0;
|
||||
virtual void SetParenthesisNumber(_In_ unsigned int count) = 0;
|
||||
virtual void OnNoRightParenAdded() = 0;
|
||||
virtual void MaxDigitsReached() = 0; // not an error but still need to inform UI layer.
|
||||
|
@@ -4,8 +4,11 @@
|
||||
#pragma once
|
||||
|
||||
// Callback interface to be implemented by the clients of CCalcEngine if they require equation history
|
||||
class IHistoryDisplay {
|
||||
class IHistoryDisplay
|
||||
{
|
||||
public:
|
||||
virtual ~IHistoryDisplay() {};
|
||||
virtual unsigned int AddToHistory(_In_ std::shared_ptr<CalculatorVector <std::pair<std::wstring, int>>> const &tokens, _In_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const &commands, _In_ std::wstring_view result) = 0;
|
||||
virtual ~IHistoryDisplay(){};
|
||||
virtual unsigned int AddToHistory(_In_ std::shared_ptr<CalculatorVector<std::pair<std::wstring, int>>> const& tokens,
|
||||
_In_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& commands,
|
||||
_In_ std::wstring_view result) = 0;
|
||||
};
|
||||
|
@@ -4,7 +4,8 @@
|
||||
#pragma once
|
||||
|
||||
// This is expected to be in same order as IDM_HEX, IDM_DEC, IDM_OCT, IDM_BIN
|
||||
enum eRADIX_TYPE {
|
||||
enum eRADIX_TYPE
|
||||
{
|
||||
HEX_RADIX,
|
||||
DEC_RADIX,
|
||||
OCT_RADIX,
|
||||
|
Reference in New Issue
Block a user