Cosmetics.

This commit is contained in:
Birunthan Mohanathas 2012-02-20 14:49:38 +00:00
parent b0046d2968
commit 0fec35edaa
4 changed files with 28 additions and 28 deletions

View File

@ -756,7 +756,7 @@ double CConfigParser::ReadFormula(LPCTSTR section, LPCTSTR key, double defValue)
if (!result.empty() && result[0] == L'(' && result[result.size() - 1] == L')') if (!result.empty() && result[0] == L'(' && result[result.size() - 1] == L')')
{ {
double resultValue = defValue; double resultValue = defValue;
WCHAR* errMsg = MathParser::CheckParse(result.c_str(), &resultValue); const WCHAR* errMsg = MathParser::CheckedParse(result.c_str(), &resultValue);
if (errMsg != NULL) if (errMsg != NULL)
{ {
std::wstring error = L"ReadFormula: "; std::wstring error = L"ReadFormula: ";
@ -782,7 +782,7 @@ bool CConfigParser::ParseFormula(const std::wstring& result, double* resultValue
// Formulas must be surrounded by parenthesis // Formulas must be surrounded by parenthesis
if (!result.empty() && result[0] == L'(' && result[result.size() - 1] == L')') if (!result.empty() && result[0] == L'(' && result[result.size() - 1] == L')')
{ {
WCHAR* errMsg = MathParser::CheckParse(result.c_str(), resultValue); const WCHAR* errMsg = MathParser::CheckedParse(result.c_str(), resultValue);
if (errMsg != NULL) if (errMsg != NULL)
{ {
std::wstring error = L"ParseFormula: "; std::wstring error = L"ParseFormula: ";

View File

@ -98,7 +98,7 @@ static double neg(double x);
static double frac(double x); static double frac(double x);
static double trunc(double x); static double trunc(double x);
static double sgn(double x); static double sgn(double x);
static WCHAR* round(int paramcnt, double* args, double* result); static const WCHAR* round(int paramcnt, double* args, double* result);
static Function g_Functions[] = static Function g_Functions[] =
{ {
@ -121,7 +121,7 @@ static Function g_Functions[] =
{ L"sgn", &sgn, 4 }, { L"sgn", &sgn, 4 },
{ L"neg", &neg, 4 }, { L"neg", &neg, 4 },
{ L"e", NULL, 1 }, { L"e", NULL, 1 },
{ L"pi", NULL, 2} { L"pi", NULL, 2 }
}; };
static const int FUNC_MAX_LEN = 5; static const int FUNC_MAX_LEN = 5;
@ -180,8 +180,8 @@ struct Parser
Parser() : opTop(0), valTop(-1), obrDist(2) { opStack[0].type = OP_OBR; } Parser() : opTop(0), valTop(-1), obrDist(2) { opStack[0].type = OP_OBR; }
}; };
static WCHAR* CalcToObr(Parser& parser); static const WCHAR* CalcToObr(Parser& parser);
static WCHAR* Calc(Parser& parser); static const WCHAR* Calc(Parser& parser);
struct Lexer struct Lexer
{ {
@ -198,16 +198,16 @@ struct Lexer
static MathTokenType GetNextToken(Lexer& lexer); static MathTokenType GetNextToken(Lexer& lexer);
WCHAR eBrackets [] = L"Unmatched brackets"; const WCHAR* eBrackets = L"Unmatched brackets";
WCHAR eSyntax [] = L"Syntax error"; const WCHAR* eSyntax = L"Syntax error";
WCHAR eInternal [] = L"Internal error"; const WCHAR* eInternal = L"Internal error";
WCHAR eExtraOp [] = L"Extra operation"; const WCHAR* eExtraOp = L"Extra operation";
WCHAR eInfinity [] = L"Division by 0"; const WCHAR* eInfinity = L"Division by 0";
WCHAR eUnknFunc [] = L"\"%s\" is unknown"; const WCHAR* eUnknFunc = L"\"%s\" is unknown";
WCHAR eLogicErr [] = L"Logical expression error"; const WCHAR* eLogicErr = L"Logical expression error";
WCHAR eInvPrmCnt[] = L"Invalid function parameter count"; const WCHAR* eInvPrmCnt = L"Invalid function parameter count";
WCHAR* MathParser::Check(const WCHAR* formula) const WCHAR* MathParser::Check(const WCHAR* formula)
{ {
int brackets = 0; int brackets = 0;
@ -228,9 +228,9 @@ WCHAR* MathParser::Check(const WCHAR* formula)
return (brackets != 0) ? eBrackets : NULL; return (brackets != 0) ? eBrackets : NULL;
} }
WCHAR* MathParser::CheckParse(const WCHAR* formula, double* result) const WCHAR* MathParser::CheckedParse(const WCHAR* formula, double* result)
{ {
WCHAR* error = Check(formula); const WCHAR* error = Check(formula);
if (!error) if (!error)
{ {
error = Parse(formula, NULL, result); error = Parse(formula, NULL, result);
@ -238,7 +238,7 @@ WCHAR* MathParser::CheckParse(const WCHAR* formula, double* result)
return error; return error;
} }
WCHAR* MathParser::Parse(const WCHAR* formula, CMeasureCalc* calc, double* result) const WCHAR* MathParser::Parse(const WCHAR* formula, CMeasureCalc* calc, double* result)
{ {
static WCHAR errorBuffer[128]; static WCHAR errorBuffer[128];
@ -251,7 +251,7 @@ WCHAR* MathParser::Parse(const WCHAR* formula, CMeasureCalc* calc, double* resul
Parser parser; Parser parser;
Lexer lexer(formula); Lexer lexer(formula);
WCHAR* error; const WCHAR* error;
for (;;) for (;;)
{ {
if ((parser.opTop == _countof(parser.opStack) - 2) || if ((parser.opTop == _countof(parser.opStack) - 2) ||
@ -410,7 +410,7 @@ WCHAR* MathParser::Parse(const WCHAR* formula, CMeasureCalc* calc, double* resul
} }
} }
static WCHAR* Calc(Parser& parser) static const WCHAR* Calc(Parser& parser)
{ {
double res; double res;
Operation op = parser.opStack[parser.opTop--]; Operation op = parser.opStack[parser.opTop--];
@ -577,11 +577,11 @@ static WCHAR* Calc(Parser& parser)
return NULL; return NULL;
} }
static WCHAR* CalcToObr(Parser& parser) static const WCHAR* CalcToObr(Parser& parser)
{ {
while (parser.opStack[parser.opTop].type != OP_OBR) while (parser.opStack[parser.opTop].type != OP_OBR)
{ {
WCHAR* error = Calc(parser); const WCHAR* error = Calc(parser);
if (error) return error; if (error) return error;
} }
--parser.opTop; --parser.opTop;
@ -803,7 +803,7 @@ static double neg(double x)
} }
// "Advanced" round function; second argument - sharpness // "Advanced" round function; second argument - sharpness
static WCHAR* round(int paramcnt, double* args, double* result) static const WCHAR* round(int paramcnt, double* args, double* result)
{ {
int sharpness; int sharpness;
if (paramcnt == 1) if (paramcnt == 1)

View File

@ -25,9 +25,9 @@ class CMeasureCalc;
namespace MathParser namespace MathParser
{ {
WCHAR* Check(const WCHAR* formula); const WCHAR* Check(const WCHAR* formula);
WCHAR* CheckParse(const WCHAR* formula, double* result); const WCHAR* CheckedParse(const WCHAR* formula, double* result);
WCHAR* Parse(const WCHAR* formula, CMeasureCalc* calc, double* result); const WCHAR* Parse(const WCHAR* formula, CMeasureCalc* calc, double* result);
bool IsDelimiter(WCHAR ch); bool IsDelimiter(WCHAR ch);
}; };

View File

@ -63,7 +63,7 @@ bool CMeasureCalc::Update()
{ {
if (!CMeasure::PreUpdate()) return false; if (!CMeasure::PreUpdate()) return false;
WCHAR* errMsg = MathParser::Parse(m_Formula.c_str(), this, &m_Value); const WCHAR* errMsg = MathParser::Parse(m_Formula.c_str(), this, &m_Value);
if (errMsg != NULL) if (errMsg != NULL)
{ {
std::wstring error = L"Calc: "; std::wstring error = L"Calc: ";
@ -110,7 +110,7 @@ void CMeasureCalc::ReadConfig(CConfigParser& parser, const WCHAR* section)
FormulaReplace(); FormulaReplace();
} }
WCHAR* errMsg = MathParser::Check(m_Formula.c_str()); const WCHAR* errMsg = MathParser::Check(m_Formula.c_str());
if (errMsg != NULL) if (errMsg != NULL)
{ {
std::wstring error = L"Calc: "; std::wstring error = L"Calc: ";