10#include "../ConnectedComponent.hpp"
12namespace wmtk::components::image_simulation::expression_parser {
29 virtual bool eval(
const CellTag& tags)
const = 0;
75 virtual std::set<std::string> tag_names_involved()
const = 0;
78using ExpressionPtr = std::unique_ptr<Expression>;
86 explicit TagExpr(int64_t tag,
const std::string& name)
91 bool eval(
const CellTag& tags)
const override {
return tags.count(m_tag) != 0; }
92 std::string
to_string()
const override {
return "\"" + m_name +
"\""; }
94 std::set<std::string> tag_names_involved()
const override {
return {m_name}; }
109 bool eval(
const CellTag& tags)
const override {
return tags.empty(); }
110 std::string
to_string()
const override {
return "\"_\""; }
112 std::set<std::string> tag_names_involved()
const override {
return {}; }
121 explicit NotExpr(ExpressionPtr expr)
122 : m_expr(std::move(expr))
125 bool eval(
const CellTag& tags)
const override {
return !m_expr->eval(tags); }
126 std::string
to_string()
const override {
return "!(" + m_expr->to_string() +
")"; }
130 bool contains_or()
const override {
return m_expr->contains_or(); }
132 std::set<std::string> tag_names_involved()
const override
134 return m_expr->tag_names_involved();
138 ExpressionPtr m_expr;
147 AndExpr(ExpressionPtr left, ExpressionPtr right)
148 : m_left(std::move(left))
149 , m_right(std::move(right))
152 bool eval(
const CellTag& tags)
const override
154 return m_left->eval(tags) && m_right->eval(tags);
158 return "(" + m_left->to_string() +
" & " + m_right->to_string() +
")";
161 bool contains_not()
const override {
return m_left->contains_not() || m_right->contains_not(); }
163 bool contains_or()
const override {
return m_left->contains_or() || m_right->contains_or(); }
166 CellTag tags = m_left->tags_involved();
167 CellTag right_tags = m_right->tags_involved();
168 tags.insert(right_tags.begin(), right_tags.end());
172 std::set<std::string> tag_names_involved()
const override
174 auto names = m_left->tag_names_involved();
175 auto right_names = m_right->tag_names_involved();
176 names.insert(right_names.begin(), right_names.end());
181 ExpressionPtr m_left;
182 ExpressionPtr m_right;
191 OrExpr(ExpressionPtr left, ExpressionPtr right)
192 : m_left(std::move(left))
193 , m_right(std::move(right))
196 bool eval(
const CellTag& tags)
const override
198 return m_left->eval(tags) || m_right->eval(tags);
203 return "(" + m_left->to_string() +
" | " + m_right->to_string() +
")";
206 bool contains_not()
const override {
return m_left->contains_not() || m_right->contains_not(); }
207 bool contains_and()
const override {
return m_left->contains_and() || m_right->contains_and(); }
211 CellTag tags = m_left->tags_involved();
212 CellTag right_tags = m_right->tags_involved();
213 tags.insert(right_tags.begin(), right_tags.end());
216 std::set<std::string> tag_names_involved()
const override
218 auto names = m_left->tag_names_involved();
219 auto right_names = m_right->tag_names_involved();
220 names.insert(right_names.begin(), right_names.end());
225 ExpressionPtr m_left;
226 ExpressionPtr m_right;
Definition Expression.hpp:145
bool contains_or() const override
Checks if the expression contains a logical OR operation.
Definition Expression.hpp:163
std::string to_string() const override
Converts the expression to its string representation. Mainly for debugging purposes.
Definition Expression.hpp:156
CellTag tags_involved() const override
Returns the set of tags involved in this expression.
Definition Expression.hpp:164
bool contains_not() const override
Checks if the expression contains a logical NOT operation.
Definition Expression.hpp:161
bool eval(const CellTag &tags) const override
Evaluates the expression against a given set of tags.
Definition Expression.hpp:152
bool contains_and() const override
Checks if the expression contains a logical AND operation.
Definition Expression.hpp:162
Definition Expression.hpp:105
std::string to_string() const override
Converts the expression to its string representation. Mainly for debugging purposes.
Definition Expression.hpp:110
bool eval(const CellTag &tags) const override
Evaluates the expression against a given set of tags.
Definition Expression.hpp:109
CellTag tags_involved() const override
Returns the set of tags involved in this expression.
Definition Expression.hpp:111
Base class for boolean expression tree nodes used to evaluate cell tags.
Definition Expression.hpp:18
virtual bool contains_or() const
Checks if the expression contains a logical OR operation.
Definition Expression.hpp:52
virtual bool eval(const CellTag &tags) const =0
Evaluates the expression against a given set of tags.
virtual CellTag tags_involved() const =0
Returns the set of tags involved in this expression.
virtual bool contains_and() const
Checks if the expression contains a logical AND operation.
Definition Expression.hpp:47
bool contains_only_and() const
Checks if the expression contains only logical AND operations or none.
Definition Expression.hpp:57
bool contains_only_not() const
Checks if the expression contains only logical NOT operations or none.
Definition Expression.hpp:65
bool contains_only_or() const
Checks if the expression contains only logical OR operations or none.
Definition Expression.hpp:61
virtual std::string to_string() const =0
Converts the expression to its string representation. Mainly for debugging purposes.
virtual bool contains_not() const
Checks if the expression contains a logical NOT operation.
Definition Expression.hpp:42
Definition Expression.hpp:119
bool contains_or() const override
Checks if the expression contains a logical OR operation.
Definition Expression.hpp:130
bool eval(const CellTag &tags) const override
Evaluates the expression against a given set of tags.
Definition Expression.hpp:125
bool contains_not() const override
Checks if the expression contains a logical NOT operation.
Definition Expression.hpp:128
std::string to_string() const override
Converts the expression to its string representation. Mainly for debugging purposes.
Definition Expression.hpp:126
bool contains_and() const override
Checks if the expression contains a logical AND operation.
Definition Expression.hpp:129
CellTag tags_involved() const override
Returns the set of tags involved in this expression.
Definition Expression.hpp:131
Definition Expression.hpp:189
bool eval(const CellTag &tags) const override
Evaluates the expression against a given set of tags.
Definition Expression.hpp:196
bool contains_and() const override
Checks if the expression contains a logical AND operation.
Definition Expression.hpp:207
bool contains_not() const override
Checks if the expression contains a logical NOT operation.
Definition Expression.hpp:206
std::string to_string() const override
Converts the expression to its string representation. Mainly for debugging purposes.
Definition Expression.hpp:201
CellTag tags_involved() const override
Returns the set of tags involved in this expression.
Definition Expression.hpp:209
bool contains_or() const override
Checks if the expression contains a logical OR operation.
Definition Expression.hpp:208
Definition Expression.hpp:84
std::string to_string() const override
Converts the expression to its string representation. Mainly for debugging purposes.
Definition Expression.hpp:92
CellTag tags_involved() const override
Returns the set of tags involved in this expression.
Definition Expression.hpp:93
bool eval(const CellTag &tags) const override
Evaluates the expression against a given set of tags.
Definition Expression.hpp:91