Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
LogicExpression.hpp
Go to the documentation of this file.
1#ifndef IV_SRC_LOGIC_LOGICEXPRESSION_HPP_
2#define IV_SRC_LOGIC_LOGICEXPRESSION_HPP_
3
6#include "third_party/exprtk.hpp"
7
8#include <optional>
9
10namespace iv::logics
11{
12
14{
15public:
16 LogicExpression() = default;
17 LogicExpression(const std::string &expression,
18 const std::map<std::string, std::weak_ptr<iv::channels::AbstractChannel>> &variables);
19 LogicExpression(const LogicExpression &other);
20 LogicExpression(LogicExpression &&other) noexcept;
21 ~LogicExpression() = default;
22
24 LogicExpression &operator=(LogicExpression &&other) noexcept;
25
26 bool operator==(const LogicExpression &) const;
27
28 bool load(const iv::file::xml::node &nodeLogicExpression);
29 bool save(iv::file::xml::node &nodeLogicExpression) const;
30
31 static bool getErrorAndVariables(const std::string &expr, std::string &errorMessage,
32 std::set<std::string> &variables);
33 bool compile(std::string &errorMessage);
34 [[nodiscard]] std::optional<iv::types::channelValue> evaluate();
35
36 [[nodiscard]] std::string getStrExpression() const;
37 [[nodiscard]] std::map<std::string, std::weak_ptr<iv::channels::AbstractChannel>> getVariables() const;
38
39 bool setVariableChannel(const std::string &variableName,
40 const std::weak_ptr<iv::channels::AbstractChannel> &channel);
41
42private:
43 std::string strExpression;
44 std::map<std::string, std::weak_ptr<iv::channels::AbstractChannel>> m_variables;
45
46 typedef exprtk::symbol_table<iv::types::channelValue> symbol_table_t;
47 typedef exprtk::expression<iv::types::channelValue> expression_t;
48 typedef exprtk::parser<iv::types::channelValue> parser_t;
49
52
53 struct Keys
54 {
55 static constexpr std::string_view expression {"Expression"};
56 static constexpr std::string_view variableName {"VariableName"};
57 static constexpr std::string_view variableChannelId {"VariableChannelId"};
58 };
59
60 struct Sections
61 {
62 static constexpr std::string_view variables {"Variables"};
63 static constexpr std::string_view variable {"Variable"};
64 };
65
67 {
68 static constexpr std::string string {};
69 };
70};
71
72}// namespace iv::logics
73
74#endif//IV_SRC_LOGIC_LOGICEXPRESSION_HPP_
Definition xmlFile.hpp:15
Definition LogicExpression.hpp:14
std::string strExpression
Definition LogicExpression.hpp:43
bool operator==(const LogicExpression &) const
Definition LogicExpression.cpp:120
expression_t expression
Definition LogicExpression.hpp:50
bool compile(std::string &errorMessage)
Definition LogicExpression.cpp:130
LogicExpression & operator=(const LogicExpression &other)
Definition LogicExpression.cpp:98
std::string getStrExpression() const
Definition LogicExpression.cpp:205
std::map< std::string, std::weak_ptr< iv::channels::AbstractChannel > > m_variables
Definition LogicExpression.hpp:44
exprtk::expression< iv::types::channelValue > expression_t
Definition LogicExpression.hpp:47
static bool getErrorAndVariables(const std::string &expr, std::string &errorMessage, std::set< std::string > &variables)
Definition LogicExpression.cpp:182
exprtk::parser< iv::types::channelValue > parser_t
Definition LogicExpression.hpp:48
bool setVariableChannel(const std::string &variableName, const std::weak_ptr< iv::channels::AbstractChannel > &channel)
Definition LogicExpression.cpp:216
bool save(iv::file::xml::node &nodeLogicExpression) const
Definition LogicExpression.cpp:66
std::optional< iv::types::channelValue > evaluate()
Definition LogicExpression.cpp:164
bool load(const iv::file::xml::node &nodeLogicExpression)
Definition LogicExpression.cpp:33
symbol_table_t symbolTable
Definition LogicExpression.hpp:51
exprtk::symbol_table< iv::types::channelValue > symbol_table_t
Definition LogicExpression.hpp:46
std::map< std::string, std::weak_ptr< iv::channels::AbstractChannel > > getVariables() const
Definition LogicExpression.cpp:211
Definition LogicExpression.cpp:6
Definition LogicExpression.hpp:67
Definition LogicExpression.hpp:54
static constexpr std::string_view variableChannelId
Definition LogicExpression.hpp:57
static constexpr std::string_view variableName
Definition LogicExpression.hpp:56
static constexpr std::string_view expression
Definition LogicExpression.hpp:55
Definition LogicExpression.hpp:61
static constexpr std::string_view variables
Definition LogicExpression.hpp:62
static constexpr std::string_view variable
Definition LogicExpression.hpp:63