diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2025-11-17 18:34:02 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-17 18:34:02 +0000 |
| commit | c2670e9ab90bd657e87a1da2c5322e9007dce01f (patch) | |
| tree | cd033fe3a9b87b1b0d457df043ecc50929ad3c8d /src/helpers/math | |
| parent | 95ee08b3403b90e2930d46425cada1d280f3524e (diff) | |
windowrules: rewrite completely (#12269)
Reworks the window rule syntax completely
---------
Co-authored-by: Mihai Fufezan <mihai@fufexan.net>
Diffstat (limited to 'src/helpers/math')
| -rw-r--r-- | src/helpers/math/Expression.cpp | 22 | ||||
| -rw-r--r-- | src/helpers/math/Expression.hpp | 28 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/helpers/math/Expression.cpp b/src/helpers/math/Expression.cpp new file mode 100644 index 00000000..fb28628d --- /dev/null +++ b/src/helpers/math/Expression.cpp @@ -0,0 +1,22 @@ +#include "Expression.hpp" +#include "muParser.h" +#include "../../debug/Log.hpp" + +using namespace Math; + +CExpression::CExpression() : m_parser(makeUnique<mu::Parser>()) { + ; +} + +void CExpression::addVariable(const std::string& name, double val) { + m_parser->DefineConst(name, val); +} + +std::optional<double> CExpression::compute(const std::string& expr) { + try { + m_parser->SetExpr(expr); + return m_parser->Eval(); + } catch (mu::Parser::exception_type& e) { Debug::log(ERR, "CExpression::compute: mu threw: {}", e.GetMsg()); } + + return std::nullopt; +} diff --git a/src/helpers/math/Expression.hpp b/src/helpers/math/Expression.hpp new file mode 100644 index 00000000..1780e3ee --- /dev/null +++ b/src/helpers/math/Expression.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include "../memory/Memory.hpp" +#include <string> +#include <optional> + +namespace mu { + class Parser; +}; + +namespace Math { + class CExpression { + public: + CExpression(); + ~CExpression() = default; + + CExpression(const CExpression&) = delete; + CExpression(CExpression&) = delete; + CExpression(CExpression&&) = delete; + + void addVariable(const std::string& name, double val); + + std::optional<double> compute(const std::string& expr); + + private: + UP<mu::Parser> m_parser; + }; +};
\ No newline at end of file |
