Loading...
Searching...
No Matches
SdfBooleanExpression Class Reference

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< TfTokenGetVariableNames () 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 &)
 

Detailed Description

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.

Member Typedef Documentation

◆ BinaryVisitor

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
See also
MakeBinaryOp()

Definition at line 142 of file booleanExpression.h.

◆ ConstantVisitor

using ConstantVisitor = TfFunctionRef<void(VtValue const&)>

The Visit() method will invoke this callback if the receiver represents a constant.

See also
MakeConstant()

Definition at line 169 of file booleanExpression.h.

◆ NameTransform

Encapsulates a transformation that may be applied to a variable name.

Used by RenameVariables().

Definition at line 187 of file booleanExpression.h.

◆ UnaryVisitor

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
See also
MakeUnaryOp()

Definition at line 156 of file booleanExpression.h.

◆ VariableCallback

Provides the current value for a given variable.

Used by Evaluate() when evaluating the expression.

Definition at line 179 of file booleanExpression.h.

◆ VariableVisitor

using VariableVisitor = TfFunctionRef<void(TfToken const&)>

The Visit() method will invoke this callback if the receiver represents a variable.

See also
MakeVariable()

Definition at line 163 of file booleanExpression.h.

Member Enumeration Documentation

◆ BinaryOperator

enum class BinaryOperator
strong

Operators for combining two subexpressions.

See also
MakeBinaryOp
Enumerator
EqualTo 

The == operator.

NotEqualTo 

The != operator.

LessThan 

The < operator.

LessThanOrEqualTo 

The <= operator.

GreaterThan 

The > operator.

GreaterThanOrEqualTo 

The >= operator.

And 

The && operator.

Or 

The || operator.

Definition at line 70 of file booleanExpression.h.

◆ UnaryOperator

enum class UnaryOperator
strong

Operators applied to a single subexpression.

See also
MakeUnaryOp
Enumerator
Not 

The ! operator.

Definition at line 113 of file booleanExpression.h.

Constructor & Destructor Documentation

◆ SdfBooleanExpression() [1/2]

SdfBooleanExpression ( )
default

Constructs an empty expression.

◆ SdfBooleanExpression() [2/2]

SDF_API SdfBooleanExpression ( std::string const &  text)
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().

Member Function Documentation

◆ Evaluate()

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.

◆ GetParseError()

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.

◆ GetText()

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.

◆ GetVariableNames()

SDF_API std::set< TfToken > GetVariableNames ( ) const

Provides the collection of variable names referenced by the expression.

◆ IsEmpty()

SDF_API bool IsEmpty ( ) const

An expression is empty if it was default constructed or if there was a problem parsing its string representation.

◆ MakeBinaryOp()

static SDF_API SdfBooleanExpression MakeBinaryOp ( SdfBooleanExpression  lhs,
BinaryOperator  op,
SdfBooleanExpression  rhs 
)
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));
See also
BinaryVisitor

◆ MakeConstant()

static SDF_API SdfBooleanExpression MakeConstant ( VtValue const &  value)
static

Constructs an expression wrapping a constant value.

See also
ConstantVisitor

◆ MakeUnaryOp()

static SDF_API SdfBooleanExpression MakeUnaryOp ( SdfBooleanExpression  expression,
UnaryOperator  op 
)
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
See also
UnaryVisitor

◆ MakeVariable()

static SDF_API SdfBooleanExpression MakeVariable ( TfToken const &  variableName)
static

Constructs an expression representing a variable.

See also
VariableVisitor

◆ RenameVariables()

SDF_API SdfBooleanExpression RenameVariables ( NameTransform const &  transform) const

Applies the provided transform to each variable name and returns the resulting expression.

◆ Validate()

static SDF_API bool Validate ( std::string const &  expression,
std::string *  errorMessage = nullptr 
)
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.

◆ Visit()

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.


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