Represents a node in a tree used to model a boolean expression for evaluating if the files in a directory match a set of conditions.
More...
#include <tagconditionnode.h>
|
| TagConditionNode () |
| Constructs a node of type empty.
|
|
| TagConditionNode (std::string expression, const std::vector< TagCondition > &conditions) |
| Constructs a new node from the given boolean expression and conditions. Recursively constructs children as needed. Node types are deduced from the expression.
|
|
bool | evaluate (const std::vector< std::pair< std::string, std::string > > &files) const |
| Checks if files in the given vector satisfy the boolean expression modeled by this tree node.
|
|
|
static void | removeEnclosingParentheses (std::string &expression) |
| Removes all outer parentheses that serve no semantic purpose in the given expression.
|
|
static bool | expressionIsValid (std::string expression, int num_conditions) |
| Checks if the given string is a syntactically valid boolean expression.
|
|
|
bool | evaluateOnce (const std::vector< std::pair< std::string, std::string > > &files, std::map< int, bool > &results) const |
| Checks if files in the given vector satisfy the boolean expression modeled by this tree node. This check is skipped if the given results map contains this nodes id.
|
|
bool | evaluateWithoutInversion (const std::vector< std::pair< std::string, std::string > > &files, std::map< int, bool > &results) const |
| Checks if files in the given vector satisfy the boolean expression modeled by this tree node. This check is skipped if the given results map contains this nodes id. Does not invert the result even is invert_ is true.
|
|
bool | containsOperator (const std::string &expression, const std::string &op) const |
| Checks if the given expression contains the given boolean operator. Only checks the top level part of the expression.
|
|
std::vector< std::pair< int, int > > | tokenize (const std::string &expression) const |
| Splits the given expression into tokens. Tokens are either condition ids, boolean operators or a subexpression in parentheses.
|
|
void | removeWhitespaces (std::string &expression) const |
| Removes all whitespaces in the given string.
|
|
bool | wildcardMatch (const std::string &target) const |
| Checks if the given string matches this nodes condition_ string. Uses * as a wildcard.
|
|
std::vector< std::string > | splitString (const std::string &input) const |
| Splits the given string into substrings seperated by the * wildcard.
|
|
|
static bool | operatorOrderIsValid (std::string expression) |
| Checks if the order of operators in the given boolean expression is valid.
|
|
static void | removeSubstring (std::string &string, std::string substring) |
| Removes all occurrences of substring from string.
|
|
|
std::string | expression_ |
| The boolean expression modeled by this tree.
|
|
bool | invert_ = false |
| If true: Invert the evaluation result.
|
|
std::vector< TagConditionNode > | children_ |
| Child nodes of this node.
|
|
Type | type_ |
| Type of this node.
|
|
std::string | condition_ |
| String used to comparisons in leaf nodes.
|
|
std::vector< std::string > | condition_strings_ |
| Used to store substrings of the expression. Split by the * wildcard.
|
|
int | condition_id_ |
| If this is a leaf: Represents the condition in the tree. Used to avoid evaluating conditions multiple times.
|
|
bool | use_regex_ |
| If true: Use regex to compare against the condition string. Else: Use a simple string matcher with * as a wildcard.
|
|
Represents a node in a tree used to model a boolean expression for evaluating if the files in a directory match a set of conditions.
◆ Type
Type of this node.
Enumerator |
---|
and_connector | Node evaluates to true only if all children evaluate to true.
|
or_connector | Node evaluates to true if at least one child evaluates to true.
|
file_matcher | Leaf node. Evaluates to true if a file name matches a pattern.
|
path_matcher | Leaf node. Evaluates to true if a file path matches a pattern.
|
empty | Dummy node. Always evaluates to false.
|
◆ TagConditionNode()
TagConditionNode::TagConditionNode |
( |
std::string | expression, |
|
|
const std::vector< TagCondition > & | conditions ) |
Constructs a new node from the given boolean expression and conditions. Recursively constructs children as needed. Node types are deduced from the expression.
- Parameters
-
expression | Expression used to construct the tree. |
conditions | Conditions which serve as variables in the expression. |
◆ containsOperator()
bool TagConditionNode::containsOperator |
( |
const std::string & | expression, |
|
|
const std::string & | op ) const |
|
private |
Checks if the given expression contains the given boolean operator. Only checks the top level part of the expression.
- Parameters
-
expression | Expression to check. |
op | Operator used for comparison. |
- Returns
- True if expression contains operator.
◆ evaluate()
bool TagConditionNode::evaluate |
( |
const std::vector< std::pair< std::string, std::string > > & | files | ) |
const |
Checks if files in the given vector satisfy the boolean expression modeled by this tree node.
- Parameters
-
files | Contains pairs of path and file names for all files of a mod. |
- Returns
- True if the directory satisfies the expression.
◆ evaluateOnce()
bool TagConditionNode::evaluateOnce |
( |
const std::vector< std::pair< std::string, std::string > > & | files, |
|
|
std::map< int, bool > & | results ) const |
|
private |
Checks if files in the given vector satisfy the boolean expression modeled by this tree node. This check is skipped if the given results map contains this nodes id.
- Parameters
-
files | Contains pairs of path and file names for all files of a mod. |
results | Contains results of previous evaluations. |
- Returns
- True if the directory satisfies the expression.
◆ evaluateWithoutInversion()
bool TagConditionNode::evaluateWithoutInversion |
( |
const std::vector< std::pair< std::string, std::string > > & | files, |
|
|
std::map< int, bool > & | results ) const |
|
private |
Checks if files in the given vector satisfy the boolean expression modeled by this tree node. This check is skipped if the given results map contains this nodes id. Does not invert the result even is invert_ is true.
- Parameters
-
files | Contains pairs of path and file names for all files of a mod. |
results | Contains results of previous evaluations. |
- Returns
- True if the directory satisfies the expression.
◆ expressionIsValid()
bool TagConditionNode::expressionIsValid |
( |
std::string | expression, |
|
|
int | num_conditions ) |
|
static |
Checks if the given string is a syntactically valid boolean expression.
- Parameters
-
exppression | String to validate. |
num_conditions | Number of conditions available in the expression. |
- Returns
- True if the expression is valid.
◆ operatorOrderIsValid()
bool TagConditionNode::operatorOrderIsValid |
( |
std::string | expression | ) |
|
|
staticprivate |
Checks if the order of operators in the given boolean expression is valid.
- Parameters
-
expression | Expression to check. |
- Returns
- True if the order is valid.
◆ removeEnclosingParentheses()
void TagConditionNode::removeEnclosingParentheses |
( |
std::string & | expression | ) |
|
|
static |
Removes all outer parentheses that serve no semantic purpose in the given expression.
- Parameters
-
expression | Expression to be modified. |
◆ removeSubstring()
void TagConditionNode::removeSubstring |
( |
std::string & | string, |
|
|
std::string | substring ) |
|
staticprivate |
Removes all occurrences of substring from string.
- Parameters
-
string | String from which to remove. |
substring | Substring to remove. |
◆ removeWhitespaces()
void TagConditionNode::removeWhitespaces |
( |
std::string & | expression | ) |
const |
|
private |
Removes all whitespaces in the given string.
- Parameters
-
expression | Expression to modify. |
◆ splitString()
std::vector< std::string > TagConditionNode::splitString |
( |
const std::string & | input | ) |
const |
|
private |
Splits the given string into substrings seperated by the * wildcard.
- Parameters
-
- Returns
- All substrings without the * wildcard.
◆ tokenize()
std::vector< std::pair< int, int > > TagConditionNode::tokenize |
( |
const std::string & | expression | ) |
const |
|
private |
Splits the given expression into tokens. Tokens are either condition ids, boolean operators or a subexpression in parentheses.
- Parameters
-
expression | Expression to split. |
- Returns
- Contains pairs of index and length of tokens in the given expression.
◆ wildcardMatch()
bool TagConditionNode::wildcardMatch |
( |
const std::string & | target | ) |
const |
|
private |
Checks if the given string matches this nodes condition_ string. Uses * as a wildcard.
- Parameters
-
target | String to compare to. |
- Returns
- True if both match.
The documentation for this class was generated from the following files: