![]() |
|
Objects of this class represent expressions that can be evaluated to produce a boolean value. More...
#include <booleanExpression.h>
Public Types | |
| enum class | BinaryOperator { EqualTo , NotEqualTo , LessThan , LessThanOrEqualTo , GreaterThan , GreaterThanOrEqualTo , And , Or } |
| Operators for combining two subexpressions. More... | |
| enum class | UnaryOperator { Not } |
| Operators applied to a single subexpression. More... | |
| using | BinaryVisitor = TfFunctionRef< void(SdfBooleanExpression const &, BinaryOperator, SdfBooleanExpression const &)> |
| The Visit() method will invoke this callback if the receiver represents a binary operator applied to two subexpressions. | |
| using | UnaryVisitor = TfFunctionRef< void(SdfBooleanExpression const &, UnaryOperator)> |
| The Visit() method will invoke this callback if the receiver represents an operator applied to a single subexpression. | |
| using | VariableVisitor = TfFunctionRef< void(TfToken const &)> |
| The Visit() method will invoke this callback if the receiver represents a variable. | |
| using | ConstantVisitor = TfFunctionRef< void(VtValue const &)> |
| The Visit() method will invoke this callback if the receiver represents a constant. | |
| using | VariableCallback = TfFunctionRef< VtValue(TfToken const &)> |
| Provides the current value for a given variable. | |
| using | NameTransform = TfFunctionRef< TfToken(TfToken const &)> |
| Encapsulates a transformation that may be applied to a variable name. | |
Public Member Functions | |
| SdfBooleanExpression ()=default | |
| Constructs an empty expression. | |
| SDF_API | SdfBooleanExpression (std::string const &text) |
| Constructs an expression by parsing a string representation. | |
| SDF_API bool | IsEmpty () const |
| An expression is empty if it was default constructed or if there was a problem parsing its string representation. | |
| SDF_API std::string | GetText () const |
| Provides a string representation that can be parsed by SdfBooleanExpression(std::string const&). | |
| SDF_API std::string const & | GetParseError () const |
| Return parsing errors as a string if this expression was constructed from a string and parse errors were encountered. | |
| SDF_API std::set< TfToken > | GetVariableNames () const |
| Provides the collection of variable names referenced by the expression. | |
| SDF_API void | Visit (VariableVisitor variable, ConstantVisitor constant, BinaryVisitor binary, UnaryVisitor unary) const |
| Invokes one of the given callbacks based on the type of the expression. | |
| SDF_API bool | Evaluate (VariableCallback const &variableCallback) const |
| Evaluates the expression. | |
| SDF_API SdfBooleanExpression | RenameVariables (NameTransform const &transform) const |
| Applies the provided transform to each variable name and returns the resulting expression. | |
| TF_DECLARE_REF_PTRS (_Node) | |
Static Public Member Functions | |
| static SDF_API SdfBooleanExpression | MakeVariable (TfToken const &variableName) |
| Constructs an expression representing a variable. | |
| static SDF_API SdfBooleanExpression | MakeConstant (VtValue const &value) |
| Constructs an expression wrapping a constant value. | |
| static SDF_API SdfBooleanExpression | MakeBinaryOp (SdfBooleanExpression lhs, BinaryOperator op, SdfBooleanExpression rhs) |
| Constructs an expression that applies the provided operator to the result of the two provided subexpressions. | |
| static SDF_API SdfBooleanExpression | MakeUnaryOp (SdfBooleanExpression expression, UnaryOperator op) |
| Constructs an expression that applies the provided operator to the result of the provided subexpression. | |
| static SDF_API bool | Validate (std::string const &expression, std::string *errorMessage=nullptr) |
| Determines if the provided string can be parsed as an expression. | |
Friends | |
| SDF_API friend std::ostream & | operator<< (std::ostream &, SdfBooleanExpression const &) |
Objects of this class represent expressions that can be evaluated to produce a boolean value.
See Sdf_Page_BooleanExpressions for more details.
Definition at line 29 of file booleanExpression.h.
| using BinaryVisitor = TfFunctionRef<void(SdfBooleanExpression const&, BinaryOperator, SdfBooleanExpression const&)> |
The Visit() method will invoke this callback if the receiver represents a binary operator applied to two subexpressions.
Given the expression width > 10.0, the callback would be invoked with the arguments:
| argument | value |
|---|---|
| lhs | SdfBooleanExpression representing width |
| op | BinaryOperator::GreaterThan |
| rhs | SdfBooleanExpression representing 10.0 |
Definition at line 142 of file booleanExpression.h.
| using ConstantVisitor = TfFunctionRef<void(VtValue const&)> |
The Visit() method will invoke this callback if the receiver represents a constant.
Definition at line 169 of file booleanExpression.h.
| using NameTransform = TfFunctionRef<TfToken(TfToken const&)> |
Encapsulates a transformation that may be applied to a variable name.
Used by RenameVariables().
Definition at line 187 of file booleanExpression.h.
| using UnaryVisitor = TfFunctionRef<void(SdfBooleanExpression const&, UnaryOperator)> |
The Visit() method will invoke this callback if the receiver represents an operator applied to a single subexpression.
Given the expression !(width > 10.0), the callback would be invoked with the arguments:
| argument | value |
|---|---|
| expression | SdfBooleanExpression representing width > 10.0 |
| op | UnaryOp::Not |
Definition at line 156 of file booleanExpression.h.
| using VariableCallback = TfFunctionRef<VtValue (TfToken const&)> |
Provides the current value for a given variable.
Used by Evaluate() when evaluating the expression.
Definition at line 179 of file booleanExpression.h.
| using VariableVisitor = TfFunctionRef<void(TfToken const&)> |
The Visit() method will invoke this callback if the receiver represents a variable.
Definition at line 163 of file booleanExpression.h.
|
strong |
Operators for combining two subexpressions.
Definition at line 70 of file booleanExpression.h.
|
strong |
Operators applied to a single subexpression.
| Enumerator | |
|---|---|
| Not | The |
Definition at line 113 of file booleanExpression.h.
|
default |
Constructs an empty expression.
|
explicit |
Constructs an expression by parsing a string representation.
If an error occurs while parsing the string, the result will be an empty expression. See also GetParseError().
| SDF_API bool Evaluate | ( | VariableCallback const & | variableCallback | ) | const |
Evaluates the expression.
If the expression contains any variables, variableCallback will be invoked to determine their current values.
| SDF_API std::string const & GetParseError | ( | ) | const |
Return parsing errors as a string if this expression was constructed from a string and parse errors were encountered.
| SDF_API std::string GetText | ( | ) | const |
Provides a string representation that can be parsed by SdfBooleanExpression(std::string const&).
If the expression was constructed from a string, the existing formatting will be preserved.
| SDF_API std::set< TfToken > GetVariableNames | ( | ) | const |
Provides the collection of variable names referenced by the expression.
| SDF_API bool IsEmpty | ( | ) | const |
An expression is empty if it was default constructed or if there was a problem parsing its string representation.
|
static |
Constructs an expression that applies the provided operator to the result of the two provided subexpressions.
The expression width > 10.0 would be constructed with the arguments:
| argument | value |
|---|---|
| lhs | SdfBooleanExpression::MakeVariable(TfToken("width")); |
| op | BinaryOperator::GreaterThan |
| rhs | SdfBooleanExpression::MakeConstant(VtValue(10.0)); |
|
static |
Constructs an expression wrapping a constant value.
|
static |
Constructs an expression that applies the provided operator to the result of the provided subexpression.
The expression !(width > 10.0) would be constructed with the arguments:
| argument | value |
|---|---|
| expression | SdfBooleanExpression representing width > 10.0 |
| op | UnaryOp::Not |
|
static |
Constructs an expression representing a variable.
| SDF_API SdfBooleanExpression RenameVariables | ( | NameTransform const & | transform | ) | const |
Applies the provided transform to each variable name and returns the resulting expression.
|
static |
Determines if the provided string can be parsed as an expression.
Returns true if the expression is valid, otherwise returns false. If the string is not a valid expression, errorMessage (if non-null) will be filled with an explanatory error message.
| SDF_API void Visit | ( | VariableVisitor | variable, |
| ConstantVisitor | constant, | ||
| BinaryVisitor | binary, | ||
| UnaryVisitor | unary | ||
| ) | const |
Invokes one of the given callbacks based on the type of the expression.