Limo
A simple mod manager
Loading...
Searching...
No Matches
TagConditionNode Class Reference

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>

Public Types

enum class  Type {
  and_connector , or_connector , file_matcher , path_matcher ,
  empty
}
 Type of this node. More...
 

Public Member Functions

 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 Public Member Functions

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.
 

Private Member Functions

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 Private Member Functions

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.
 

Private Attributes

std::string expression_
 The boolean expression modeled by this tree.
 
bool invert_ = false
 If true: Invert the evaluation result.
 
std::vector< TagConditionNodechildren_
 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.
 

Detailed Description

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.

Member Enumeration Documentation

◆ Type

enum class TagConditionNode::Type
strong

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.

Constructor & Destructor Documentation

◆ 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
expressionExpression used to construct the tree.
conditionsConditions which serve as variables in the expression.

Member Function Documentation

◆ 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
expressionExpression to check.
opOperator 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
filesContains 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
filesContains pairs of path and file names for all files of a mod.
resultsContains 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
filesContains pairs of path and file names for all files of a mod.
resultsContains 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
exppressionString to validate.
num_conditionsNumber 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
expressionExpression 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
expressionExpression to be modified.

◆ removeSubstring()

void TagConditionNode::removeSubstring ( std::string & string,
std::string substring )
staticprivate

Removes all occurrences of substring from string.

Parameters
stringString from which to remove.
substringSubstring to remove.

◆ removeWhitespaces()

void TagConditionNode::removeWhitespaces ( std::string & expression) const
private

Removes all whitespaces in the given string.

Parameters
expressionExpression 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
inputString to split.
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
expressionExpression 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
targetString to compare to.
Returns
True if both match.

The documentation for this class was generated from the following files: