HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SdfBooleanExpression Class Reference

#include <booleanExpression.h>

Public Types

enum  BinaryOperator {
  BinaryOperator::EqualTo, BinaryOperator::NotEqualTo, BinaryOperator::LessThan, BinaryOperator::LessThanOrEqualTo,
  BinaryOperator::GreaterThan, BinaryOperator::GreaterThanOrEqualTo, BinaryOperator::And, BinaryOperator::Or
}
 
enum  UnaryOperator { UnaryOperator::Not }
 
using BinaryVisitor = TfFunctionRef< void(SdfBooleanExpression const &, BinaryOperator, SdfBooleanExpression const &)>
 
using UnaryVisitor = TfFunctionRef< void(SdfBooleanExpression const &, UnaryOperator)>
 
using VariableVisitor = TfFunctionRef< void(TfToken const &)>
 
using ConstantVisitor = TfFunctionRef< void(VtValue const &)>
 
using VariableCallback = TfFunctionRef< VtValue(TfToken const &)>
 
using NameTransform = TfFunctionRef< TfToken(TfToken const &)>
 

Public Member Functions

 SdfBooleanExpression ()=default
 Constructs an empty expression. More...
 
SDF_API SdfBooleanExpression (std::string const &text)
 
SDF_API bool IsEmpty () const
 
SDF_API std::string GetText () const
 
SDF_API std::string const & GetParseError () const
 
SDF_API std::set< TfTokenGetVariableNames () const
 Provides the collection of variable names referenced by the expression. More...
 
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. More...
 
SDF_API bool Evaluate (VariableCallback const &variableCallback) const
 
SDF_API SdfBooleanExpression RenameVariables (NameTransform const &transform) const
 
 TF_DECLARE_REF_PTRS (_Node)
 

Static Public Member Functions

static SDF_API SdfBooleanExpression MakeVariable (TfToken const &variableName)
 
static SDF_API SdfBooleanExpression MakeConstant (VtValue const &value)
 
static SDF_API SdfBooleanExpression MakeBinaryOp (SdfBooleanExpression lhs, BinaryOperator op, SdfBooleanExpression rhs)
 
static SDF_API SdfBooleanExpression MakeUnaryOp (SdfBooleanExpression expression, UnaryOperator op)
 
static SDF_API bool Validate (std::string const &expression, std::string *errorMessage=nullptr)
 

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

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:

argumentvalue
lhs SdfBooleanExpression representing width
op BinaryOperator::GreaterThan
rhs SdfBooleanExpression representing 10.0
See Also
MakeBinaryOp()

Definition at line 144 of file booleanExpression.h.

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

See Also
MakeConstant()

Definition at line 169 of file booleanExpression.h.

Encapsulates a transformation that may be applied to a variable name. Used by RenameVariables().

Definition at line 187 of file booleanExpression.h.

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
expressionSdfBooleanExpression representing width > 10.0
op UnaryOp::Not
See Also
MakeUnaryOp()

Definition at line 157 of file booleanExpression.h.

Provides the current value for a given variable. Used by Evaluate() when evaluating the expression.

Definition at line 179 of file booleanExpression.h.

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

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.

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::SdfBooleanExpression ( )
default

Constructs an empty expression.

SDF_API SdfBooleanExpression::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

SDF_API bool SdfBooleanExpression::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& SdfBooleanExpression::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 SdfBooleanExpression::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> SdfBooleanExpression::GetVariableNames ( ) const

Provides the collection of variable names referenced by the expression.

SDF_API bool SdfBooleanExpression::IsEmpty ( ) const

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

static SDF_API SdfBooleanExpression 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:

argumentvalue
lhs SdfBooleanExpression::MakeVariable(TfToken("width"));
op BinaryOperator::GreaterThan
rhs SdfBooleanExpression::MakeConstant(VtValue(10.0));
See Also
BinaryVisitor
static SDF_API SdfBooleanExpression SdfBooleanExpression::MakeConstant ( VtValue const &  value)
static

Constructs an expression wrapping a constant value.

See Also
ConstantVisitor
static SDF_API SdfBooleanExpression 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
expressionSdfBooleanExpression representing width > 10.0
op UnaryOp::Not
See Also
UnaryVisitor
static SDF_API SdfBooleanExpression SdfBooleanExpression::MakeVariable ( TfToken const &  variableName)
static

Constructs an expression representing a variable.

See Also
VariableVisitor
SDF_API SdfBooleanExpression SdfBooleanExpression::RenameVariables ( NameTransform const &  transform) const

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

SdfBooleanExpression::TF_DECLARE_REF_PTRS ( _Node  )
static SDF_API bool SdfBooleanExpression::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.

SDF_API void SdfBooleanExpression::Visit ( VariableVisitor  variable,
ConstantVisitor  constant,
BinaryVisitor  binary,
UnaryVisitor  unary 
) const

Invokes one of the given callbacks based on the type of the expression.

Friends And Related Function Documentation

SDF_API friend std::ostream& operator<< ( std::ostream &  ,
SdfBooleanExpression const &   
)
friend

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