Replace custom types with standard ones (#212)

Replace custom types with standard ones
This commit is contained in:
Michał Janiszewski
2019-03-26 22:30:46 +01:00
committed by Daniel Belcher
parent ef3f5e9cbb
commit 7a48f66807
32 changed files with 478 additions and 396 deletions

View File

@@ -56,7 +56,7 @@ bool CalcInput::TryToggleSign(bool isIntegerMode, wstring_view maxNumStr)
return true;
}
bool CalcInput::TryAddDigit(unsigned int value, uint32_t radix, bool isIntegerMode, wstring_view maxNumStr, long wordBitWidth, int maxDigits)
bool CalcInput::TryAddDigit(unsigned int value, uint32_t radix, bool isIntegerMode, wstring_view maxNumStr, int32_t wordBitWidth, int maxDigits)
{
// Convert from an integer into a character
// This includes both normal digits and alpha 'digits' for radixes > 10

View File

@@ -5,24 +5,24 @@
#include "Header Files/CalcEngine.h"
#include "Header Files/CalcUtils.h"
bool IsOpInRange(WPARAM op, uint32_t x, uint32_t y)
bool IsOpInRange(OpCode op, uint32_t x, uint32_t y)
{
return ((op >= x) && (op <= y));
}
bool IsBinOpCode(WPARAM opCode)
bool IsBinOpCode(OpCode opCode)
{
return IsOpInRange(opCode, IDC_AND, IDC_PWR);
}
// WARNING: IDC_SIGN is a special unary op but still this doesn't catch this. Caller has to be aware
// of it and catch it themselves or not needing this
bool IsUnaryOpCode(WPARAM opCode)
bool IsUnaryOpCode(OpCode opCode)
{
return IsOpInRange(opCode, IDC_UNARYFIRST, IDC_UNARYLAST);
}
bool IsDigitOpCode(WPARAM opCode)
bool IsDigitOpCode(OpCode opCode)
{
return IsOpInRange(opCode, IDC_0, IDC_F);
}
@@ -32,7 +32,7 @@ bool IsDigitOpCode(WPARAM opCode)
// so we abstract this as a separate routine. Note: There is another side to this. Some commands are not
// gui mode setting to begin with, but once it is discovered it is invalid and we want to behave as though it
// was never inout, we need to revert the state changes made as a result of this test
bool IsGuiSettingOpCode(WPARAM opCode)
bool IsGuiSettingOpCode(OpCode opCode)
{
if (IsOpInRange(opCode, IDM_HEX, IDM_BIN) ||
IsOpInRange(opCode, IDM_QWORD, IDM_BYTE) ||

View File

@@ -13,7 +13,7 @@ using namespace std;
using namespace CalcEngine;
namespace {
void IFT(HRESULT hr)
void IFT(ResultCode hr)
{
if (FAILED(hr))
{

View File

@@ -28,10 +28,10 @@ namespace CalcEngine
PNUMBER Number::ToPNUMBER() const
{
PNUMBER ret = _createnum(static_cast<ULONG>(this->Mantissa().size()) + 1);
PNUMBER ret = _createnum(static_cast<uint32_t>(this->Mantissa().size()) + 1);
ret->sign = this->Sign();
ret->exp = this->Exp();
ret->cdigit = static_cast<long>(this->Mantissa().size());
ret->cdigit = static_cast<int32_t>(this->Mantissa().size());
MANTTYPE *ptrRet = ret->mant;
for (auto const& digit : this->Mantissa())

View File

@@ -31,7 +31,7 @@ namespace CalcEngine
Rational::Rational(int32_t i)
{
PRAT pr = longtorat(static_cast<long>(i));
PRAT pr = i32torat(static_cast<int32_t>(i));
m_p = Number{ pr->pp };
m_q = Number{ pr->pq };
@@ -41,7 +41,7 @@ namespace CalcEngine
Rational::Rational(uint32_t ui)
{
PRAT pr = Ulongtorat(static_cast<unsigned long>(ui));
PRAT pr = Ui32torat(static_cast<uint32_t>(ui));
m_p = Number{ pr->pp };
m_q = Number{ pr->pq };
@@ -100,7 +100,7 @@ namespace CalcEngine
addrat(&lhsRat, rhsRat, RATIONAL_PRECISION);
destroyrat(rhsRat);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(lhsRat);
destroyrat(rhsRat);
@@ -123,7 +123,7 @@ namespace CalcEngine
subrat(&lhsRat, rhsRat, RATIONAL_PRECISION);
destroyrat(rhsRat);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(lhsRat);
destroyrat(rhsRat);
@@ -146,7 +146,7 @@ namespace CalcEngine
mulrat(&lhsRat, rhsRat, RATIONAL_PRECISION);
destroyrat(rhsRat);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(lhsRat);
destroyrat(rhsRat);
@@ -169,7 +169,7 @@ namespace CalcEngine
divrat(&lhsRat, rhsRat, RATIONAL_PRECISION);
destroyrat(rhsRat);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(lhsRat);
destroyrat(rhsRat);
@@ -192,7 +192,7 @@ namespace CalcEngine
modrat(&lhsRat, rhsRat);
destroyrat(rhsRat);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(lhsRat);
destroyrat(rhsRat);
@@ -215,7 +215,7 @@ namespace CalcEngine
lshrat(&lhsRat, rhsRat, RATIONAL_BASE, RATIONAL_PRECISION);
destroyrat(rhsRat);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(lhsRat);
destroyrat(rhsRat);
@@ -238,7 +238,7 @@ namespace CalcEngine
rshrat(&lhsRat, rhsRat, RATIONAL_BASE, RATIONAL_PRECISION);
destroyrat(rhsRat);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(lhsRat);
destroyrat(rhsRat);
@@ -261,7 +261,7 @@ namespace CalcEngine
andrat(&lhsRat, rhsRat, RATIONAL_BASE, RATIONAL_PRECISION);
destroyrat(rhsRat);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(lhsRat);
destroyrat(rhsRat);
@@ -283,7 +283,7 @@ namespace CalcEngine
orrat(&lhsRat, rhsRat, RATIONAL_BASE, RATIONAL_PRECISION);
destroyrat(rhsRat);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(lhsRat);
destroyrat(rhsRat);
@@ -305,7 +305,7 @@ namespace CalcEngine
xorrat(&lhsRat, rhsRat, RATIONAL_BASE, RATIONAL_PRECISION);
destroyrat(rhsRat);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(lhsRat);
destroyrat(rhsRat);
@@ -388,7 +388,7 @@ namespace CalcEngine
{
result = rat_equ(lhsRat, rhsRat, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(lhsRat);
destroyrat(rhsRat);
@@ -416,7 +416,7 @@ namespace CalcEngine
{
result = rat_lt(lhsRat, rhsRat, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(lhsRat);
destroyrat(rhsRat);
@@ -453,7 +453,7 @@ namespace CalcEngine
{
result = RatToString(rat, fmt, radix, precision);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(rat);
throw(error);
@@ -470,9 +470,9 @@ namespace CalcEngine
uint64_t result;
try
{
result = rattoUlonglong(rat, RATIONAL_BASE, RATIONAL_PRECISION);
result = rattoUi64(rat, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(rat);
throw(error);

View File

@@ -14,7 +14,7 @@ Rational RationalMath::Frac(Rational const& rat)
{
fracrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(prat);
throw(error);
@@ -33,7 +33,7 @@ Rational RationalMath::Integer(Rational const& rat)
{
intrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(prat);
throw(error);
@@ -55,7 +55,7 @@ Rational RationalMath::Pow(Rational const& base, Rational const& pow)
powrat(&baseRat, powRat, RATIONAL_BASE, RATIONAL_PRECISION);
destroyrat(powRat);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(baseRat);
destroyrat(powRat);
@@ -81,7 +81,7 @@ Rational RationalMath::Fact(Rational const& rat)
{
factrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(prat);
throw(error);
@@ -101,7 +101,7 @@ Rational RationalMath::Exp(Rational const& rat)
{
exprat(&prat, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(prat);
throw(error);
@@ -121,7 +121,7 @@ Rational RationalMath::Log(Rational const& rat)
{
lograt(&prat, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(prat);
throw(error);
@@ -156,7 +156,7 @@ Rational RationalMath::Sin(Rational const& rat, ANGLE_TYPE angletype)
{
sinanglerat(&prat, angletype, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(prat);
throw(error);
@@ -176,7 +176,7 @@ Rational RationalMath::Cos(Rational const& rat, ANGLE_TYPE angletype)
{
cosanglerat(&prat, angletype, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(prat);
throw(error);
@@ -196,7 +196,7 @@ Rational RationalMath::Tan(Rational const& rat, ANGLE_TYPE angletype)
{
tananglerat(&prat, angletype, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(prat);
throw(error);
@@ -216,7 +216,7 @@ Rational RationalMath::ASin(Rational const& rat, ANGLE_TYPE angletype)
{
asinanglerat(&prat, angletype, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(prat);
throw(error);
@@ -236,7 +236,7 @@ Rational RationalMath::ACos(Rational const& rat, ANGLE_TYPE angletype)
{
acosanglerat(&prat, angletype, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(prat);
throw(error);
@@ -256,7 +256,7 @@ Rational RationalMath::ATan(Rational const& rat, ANGLE_TYPE angletype)
{
atananglerat(&prat, angletype, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(prat);
throw(error);
@@ -276,7 +276,7 @@ Rational RationalMath::Sinh(Rational const& rat)
{
sinhrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(prat);
throw(error);
@@ -296,7 +296,7 @@ Rational RationalMath::Cosh(Rational const& rat)
{
coshrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(prat);
throw(error);
@@ -316,7 +316,7 @@ Rational RationalMath::Tanh(Rational const& rat)
{
tanhrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(prat);
throw(error);
@@ -336,7 +336,7 @@ Rational RationalMath::ASinh(Rational const& rat)
{
asinhrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(prat);
throw(error);
@@ -356,7 +356,7 @@ Rational RationalMath::ACosh(Rational const& rat)
{
acoshrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(prat);
throw(error);
@@ -376,7 +376,7 @@ Rational RationalMath::ATanh(Rational const& rat)
{
atanhrat(&prat, RATIONAL_PRECISION);
}
catch (DWORD error)
catch (uint32_t error)
{
destroyrat(prat);
throw(error);

View File

@@ -15,7 +15,7 @@ using namespace CalcEngine;
static constexpr int DEFAULT_MAX_DIGITS = 32;
static constexpr int DEFAULT_PRECISION = 32;
static constexpr long DEFAULT_RADIX = 10;
static constexpr int32_t DEFAULT_RADIX = 10;
static constexpr wchar_t DEFAULT_DEC_SEPARATOR = L'.';
static constexpr wchar_t DEFAULT_GRP_SEPARATOR = L',';

View File

@@ -31,9 +31,9 @@ namespace {
//
// returns a virtual number for precedence for the operator. We expect binary operator only, otherwise the lowest number
// 0 is returned. Higher the number, higher the precedence of the operator.
INT NPrecedenceOfOp(int nopCode)
int NPrecedenceOfOp(int nopCode)
{
static BYTE rgbPrec[] = { 0,0, IDC_OR,0, IDC_XOR,0, IDC_AND,1,
static uint8_t rgbPrec[] = { 0,0, IDC_OR,0, IDC_XOR,0, IDC_AND,1,
IDC_ADD,2, IDC_SUB,2, IDC_RSHF,3, IDC_LSHF,3,
IDC_MOD,3, IDC_DIV,3, IDC_MUL,3, IDC_PWR,4, IDC_ROOT, 4 };
unsigned int iPrec;
@@ -56,7 +56,7 @@ namespace {
//
// When it is discovered by the state machine that at this point the input is not valid (eg. "1+)"), we want to proceed as though this input never
// occurred and may be some feedback to user like Beep. The rest of input can then continue by just ignoring this command.
void CCalcEngine::HandleErrorCommand(WPARAM idc)
void CCalcEngine::HandleErrorCommand(OpCode idc)
{
if (!IsGuiSettingOpCode(idc))
{
@@ -83,7 +83,7 @@ void CCalcEngine::ClearTemporaryValues()
m_bError = false;
}
void CCalcEngine::ProcessCommand(WPARAM wParam)
void CCalcEngine::ProcessCommand(OpCode wParam)
{
if (wParam == IDC_SET_RESULT)
{
@@ -94,9 +94,9 @@ void CCalcEngine::ProcessCommand(WPARAM wParam)
ProcessCommandWorker(wParam);
}
void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
void CCalcEngine::ProcessCommandWorker(OpCode wParam)
{
INT nx, ni;
int nx, ni;
// Save the last command. Some commands are not saved in this manor, these
// commands are:
@@ -107,7 +107,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
if (!IsGuiSettingOpCode(wParam))
{
m_nLastCom = m_nTempCom;
m_nTempCom = (INT)wParam;
m_nTempCom = (int)wParam;
}
if (m_bError)
@@ -185,10 +185,10 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
// Change the operation if last input was operation.
if (IsBinOpCode(m_nLastCom))
{
INT nPrev;
int nPrev;
bool fPrecInvToHigher = false; // Is Precedence Inversion from lower to higher precedence happening ??
m_nOpCode = (INT)wParam;
m_nOpCode = (int)wParam;
// Check to see if by changing this binop, a Precedence inversion is happening.
// Eg. 1 * 2 + and + is getting changed to ^. The previous precedence rules would have already computed
@@ -285,7 +285,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
DisplayAnnounceBinaryOperator();
m_lastVal = m_currentVal;
m_nOpCode = (INT)wParam;
m_nOpCode = (int)wParam;
m_HistoryCollector.AddBinOpToHistory(m_nOpCode);
m_bNoPrevEqu = m_bChangeOp = true;
return;
@@ -313,7 +313,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
m_HistoryCollector.AddOpndToHistory(m_numberString, m_currentVal);
}
m_HistoryCollector.AddUnaryOpToHistory((INT)wParam, m_bInv, m_angletype);
m_HistoryCollector.AddUnaryOpToHistory((int)wParam, m_bInv, m_angletype);
}
if ((wParam == IDC_SIN) || (wParam == IDC_COS) || (wParam == IDC_TAN) || (wParam == IDC_SINH) || (wParam == IDC_COSH) || (wParam == IDC_TANH))
@@ -326,7 +326,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
}
}
m_currentVal = SciCalcFunctions(m_currentVal, (DWORD)wParam);
m_currentVal = SciCalcFunctions(m_currentVal, (uint32_t)wParam);
if (m_bError)
return;
@@ -366,7 +366,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
CheckAndAddLastBinOpToHistory();
if (TryToggleBit(m_currentVal, (DWORD)wParam - IDC_BINEDITSTART))
if (TryToggleBit(m_currentVal, (uint32_t)wParam - IDC_BINEDITSTART))
{
DisplayNum();
}
@@ -442,7 +442,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
m_nTempCom = m_nLastCom; // Put back this last saved command to the prev state so ) can be handled properly
ProcessCommand(IDC_CLOSEP);
m_nLastCom = m_nTempCom; // Actually this is IDC_CLOSEP
m_nTempCom = (INT)wParam; // put back in the state where last op seen was IDC_CLOSEP, and current op is IDC_EQU
m_nTempCom = (int)wParam; // put back in the state where last op seen was IDC_CLOSEP, and current op is IDC_EQU
}
if (!m_bNoPrevEqu)
@@ -1060,7 +1060,7 @@ wstring CCalcEngine::GetStringForDisplay(Rational const& rat, uint32_t radix)
result = tempRat.ToString(radix, m_nFE, m_precision);
}
catch (DWORD)
catch (uint32_t)
{
}
}

View File

@@ -39,7 +39,7 @@ typedef struct {
Rational value;
int32_t precision;
uint32_t radix;
INT nFE;
int nFE;
NUM_WIDTH numwidth;
bool fIntMath;
bool bRecord;

View File

@@ -24,7 +24,7 @@ using namespace CalcEngine;
using namespace CalcEngine::RationalMath;
/* Routines for more complex mathematical functions/error checking. */
CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& rat, DWORD op)
CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& rat, uint32_t op)
{
Rational result{};
try
@@ -205,7 +205,7 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r
}
} // end switch( op )
}
catch (DWORD nErrCode)
catch (uint32_t nErrCode)
{
DisplayError(nErrCode);
result = rat;
@@ -215,9 +215,9 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r
}
/* Routine to display error messages and set m_bError flag. Errors are */
/* called with DisplayError (n), where n is a DWORD between 0 and 5. */
/* called with DisplayError (n), where n is a uint32_t between 0 and 5. */
void CCalcEngine::DisplayError(DWORD nError)
void CCalcEngine::DisplayError(uint32_t nError)
{
wstring errorString{ GetString(IDS_ERRORS_FIRST + SCODE_CODE(nError)) };

View File

@@ -133,7 +133,7 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
break;
}
}
catch (DWORD dwErrCode)
catch (uint32_t dwErrCode)
{
DisplayError(dwErrCode);

View File

@@ -51,10 +51,10 @@ void CCalcEngine::SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwid
DisplayNum();
}
LONG CCalcEngine::DwWordBitWidthFromeNumWidth(NUM_WIDTH /*numwidth*/)
int32_t CCalcEngine::DwWordBitWidthFromeNumWidth(NUM_WIDTH /*numwidth*/)
{
static constexpr int nBitMax[] = { 64, 32, 16, 8 };
LONG wmax = nBitMax[0];
int32_t wmax = nBitMax[0];
if (m_numwidth >= 0 && (size_t)m_numwidth < size(nBitMax))
{
@@ -77,9 +77,9 @@ uint32_t CCalcEngine::NRadixFromRadixType(RADIX_TYPE radixtype)
}
// Toggles a given bit into the number representation. returns true if it changed it actually.
bool CCalcEngine::TryToggleBit(CalcEngine::Rational& rat, DWORD wbitno)
bool CCalcEngine::TryToggleBit(CalcEngine::Rational& rat, uint32_t wbitno)
{
DWORD wmax = DwWordBitWidthFromeNumWidth(m_numwidth);
uint32_t wmax = DwWordBitWidthFromeNumWidth(m_numwidth);
if (wbitno >= wmax)
{
return false; // ignore error cant happen