mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Move MathParser to Common
This commit is contained in:
parent
3cebbc6b53
commit
be3efa7531
@ -22,6 +22,7 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="ControlTemplate.cpp" />
|
||||
<ClCompile Include="Dialog.cpp" />
|
||||
<ClCompile Include="MathParser.cpp" />
|
||||
<ClCompile Include="MenuTemplate.cpp" />
|
||||
<ClCompile Include="PathUtil.cpp" />
|
||||
<ClCompile Include="Platform.cpp" />
|
||||
@ -30,6 +31,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ControlTemplate.h" />
|
||||
<ClInclude Include="Dialog.h" />
|
||||
<ClInclude Include="MathParser.h" />
|
||||
<ClInclude Include="MenuTemplate.h" />
|
||||
<ClInclude Include="PathUtil.h" />
|
||||
<ClInclude Include="Platform.h" />
|
||||
|
@ -7,6 +7,7 @@
|
||||
<ClCompile Include="Platform.cpp" />
|
||||
<ClCompile Include="StringUtil.cpp" />
|
||||
<ClCompile Include="ControlTemplate.cpp" />
|
||||
<ClCompile Include="MathParser.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Dialog.h" />
|
||||
@ -16,5 +17,6 @@
|
||||
<ClInclude Include="RawString.h" />
|
||||
<ClInclude Include="StringUtil.h" />
|
||||
<ClInclude Include="ControlTemplate.h" />
|
||||
<ClInclude Include="MathParser.h" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -18,8 +18,8 @@
|
||||
|
||||
// Heavily based on ccalc 0.5.1 by Walery Studennikov <hqsoftware@mail.ru>
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "MeasureCalc.h"
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include "MathParser.h"
|
||||
|
||||
static const double M_E = 2.7182818284590452354;
|
||||
@ -242,12 +242,13 @@ const WCHAR* MathParser::CheckedParse(const WCHAR* formula, double* result)
|
||||
const WCHAR* error = Check(formula);
|
||||
if (!error)
|
||||
{
|
||||
error = Parse(formula, nullptr, result);
|
||||
error = Parse(formula, result);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
const WCHAR* MathParser::Parse(const WCHAR* formula, MeasureCalc* calc, double* result)
|
||||
const WCHAR* MathParser::Parse(
|
||||
const WCHAR* formula, double* result, GetValueFunc getValue, void* getValueContext)
|
||||
{
|
||||
static WCHAR errorBuffer[128];
|
||||
|
||||
@ -400,7 +401,7 @@ const WCHAR* MathParser::Parse(const WCHAR* formula, MeasureCalc* calc, double*
|
||||
else
|
||||
{
|
||||
double dblval;
|
||||
if (calc && calc->GetMeasureValue(lexer.name, lexer.nameLen, &dblval))
|
||||
if (getValue && getValue(lexer.name, lexer.nameLen, &dblval, getValueContext))
|
||||
{
|
||||
parser.numStack[++parser.valTop] = dblval;
|
||||
break;
|
@ -18,16 +18,20 @@
|
||||
|
||||
// Heavily based on ccalc 0.5.1 by Walery Studennikov <hqsoftware@mail.ru>
|
||||
|
||||
#ifndef __MATHPARSER_H__
|
||||
#define __MATHPARSER_H__
|
||||
#ifndef RM_COMMON_MATHPARSER_H_
|
||||
#define RM_COMMON_MATHPARSER_H_
|
||||
|
||||
class MeasureCalc;
|
||||
#include <Windows.h>
|
||||
|
||||
namespace MathParser
|
||||
{
|
||||
typedef bool (*GetValueFunc)(const WCHAR* str, int len, double* value, void* context);
|
||||
|
||||
const WCHAR* Check(const WCHAR* formula);
|
||||
const WCHAR* CheckedParse(const WCHAR* formula, double* result);
|
||||
const WCHAR* Parse(const WCHAR* formula, MeasureCalc* calc, double* result);
|
||||
const WCHAR* Parse(
|
||||
const WCHAR* formula, double* result,
|
||||
GetValueFunc getValue = nullptr, void* getValueContext = nullptr);
|
||||
|
||||
bool IsDelimiter(WCHAR ch);
|
||||
};
|
@ -17,9 +17,9 @@
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "../Common/MathParser.h"
|
||||
#include "../Common/PathUtil.h"
|
||||
#include "ConfigParser.h"
|
||||
#include "MathParser.h"
|
||||
#include "Litestep.h"
|
||||
#include "Rainmeter.h"
|
||||
#include "System.h"
|
||||
|
@ -102,9 +102,6 @@
|
||||
<ClCompile Include="Logger.cpp">
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MathParser.cpp">
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Measure.cpp">
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
@ -316,7 +313,6 @@
|
||||
<ClInclude Include="Litestep.h" />
|
||||
<ClInclude Include="DialogManage.h" />
|
||||
<ClInclude Include="Logger.h" />
|
||||
<ClInclude Include="MathParser.h" />
|
||||
<ClInclude Include="Measure.h" />
|
||||
<ClInclude Include="MeasureCalc.h" />
|
||||
<ClInclude Include="MeasureCPU.h" />
|
||||
|
@ -321,9 +321,6 @@
|
||||
<ClCompile Include="Export.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MathParser.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Mouse.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@ -596,9 +593,6 @@
|
||||
<ClInclude Include="Export.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MathParser.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="lua\lua\luaconf.h">
|
||||
<Filter>Lua\Lua</Filter>
|
||||
</ClInclude>
|
||||
|
@ -17,9 +17,9 @@
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "../Common/MathParser.h"
|
||||
#include "MeasureCalc.h"
|
||||
#include "Rainmeter.h"
|
||||
#include "MathParser.h"
|
||||
|
||||
bool MeasureCalc::c_RandSeeded = false;
|
||||
|
||||
@ -56,7 +56,7 @@ MeasureCalc::~MeasureCalc()
|
||||
*/
|
||||
void MeasureCalc::UpdateValue()
|
||||
{
|
||||
const WCHAR* errMsg = MathParser::Parse(m_Formula.c_str(), this, &m_Value);
|
||||
const WCHAR* errMsg = MathParser::Parse(m_Formula.c_str(), &m_Value, GetMeasureValue, this);
|
||||
if (errMsg != nullptr)
|
||||
{
|
||||
if (!m_ParseError)
|
||||
@ -145,9 +145,10 @@ void MeasureCalc::FormulaReplace()
|
||||
while (pos != std::wstring::npos);
|
||||
}
|
||||
|
||||
bool MeasureCalc::GetMeasureValue(const WCHAR* str, int len, double* value)
|
||||
bool MeasureCalc::GetMeasureValue(const WCHAR* str, int len, double* value, void* context)
|
||||
{
|
||||
const std::vector<Measure*>& measures = m_MeterWindow->GetMeasures();
|
||||
auto calc = (MeasureCalc*)context;
|
||||
const std::vector<Measure*>& measures = calc->m_MeterWindow->GetMeasures();
|
||||
|
||||
std::vector<Measure*>::const_iterator iter = measures.begin();
|
||||
for ( ; iter != measures.end(); ++iter)
|
||||
@ -162,12 +163,12 @@ bool MeasureCalc::GetMeasureValue(const WCHAR* str, int len, double* value)
|
||||
|
||||
if (_wcsnicmp(str, L"counter", len) == 0)
|
||||
{
|
||||
*value = m_MeterWindow->GetUpdateCounter();
|
||||
*value = calc->m_MeterWindow->GetUpdateCounter();
|
||||
return true;
|
||||
}
|
||||
else if (_wcsnicmp(str, L"random", len) == 0)
|
||||
{
|
||||
*value = GetRandom();
|
||||
*value = calc->GetRandom();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -29,13 +29,13 @@ public:
|
||||
|
||||
virtual UINT GetTypeID() { return TypeID<MeasureCalc>(); }
|
||||
|
||||
bool GetMeasureValue(const WCHAR* str, int len, double* value);
|
||||
|
||||
protected:
|
||||
virtual void ReadOptions(ConfigParser& parser, const WCHAR* section);
|
||||
virtual void UpdateValue();
|
||||
|
||||
private:
|
||||
static bool GetMeasureValue(const WCHAR* str, int len, double* value, void* context);
|
||||
|
||||
void FormulaReplace();
|
||||
int GetRandom();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user