7#ifndef PXR_USD_SDF_PREDICATE_EXPRESSION_H
8#define PXR_USD_SDF_PREDICATE_EXPRESSION_H
11#include "pxr/usd/sdf/api.h"
13#include "pxr/base/vt/value.h"
21PXR_NAMESPACE_OPEN_SCOPE
77 return { std::string(), val };
79 static FnArg Keyword(std::string
const &name,
VtValue const &val) {
85 template <
class HashState>
86 friend void TfHashAppend(HashState &h,
FnArg const &arg) {
87 h.Append(arg.argName, arg.value);
90 friend bool operator==(
FnArg const &l,
FnArg const &r) {
91 return std::tie(l.argName, l.value) == std::tie(r.argName, r.value);
93 friend bool operator!=(
FnArg const &l,
FnArg const &r) {
98 swap(l.argName, r.argName);
99 swap(l.value, r.value);
115 std::string funcName;
116 std::vector<FnArg> args;
118 template <
class HashState>
119 friend void TfHashAppend(HashState &h,
FnCall const &c) {
120 h.Append(c.kind, c.funcName, c.args);
123 friend bool operator==(FnCall
const &l, FnCall
const &r) {
124 return std::tie(l.kind, l.funcName, l.args) ==
125 std::tie(r.kind, r.funcName, r.args);
127 friend bool operator!=(FnCall
const &l, FnCall
const &r) {
130 friend void swap(FnCall &l, FnCall &r) {
131 auto lt = std::tie(l.kind, l.funcName, l.args);
132 auto rt = std::tie(r.kind, r.funcName, r.args);
151 std::string
const &context = {});
162 enum Op { Call, Not, ImpliedAnd, And, Or };
222 TfFunctionRef<
void (std::vector<std::pair<Op, int>>
const &)> logic,
237 explicit operator bool()
const {
250 return std::move(_parseError);
254 template <
class HashState>
256 h.Append(expr._ops, expr._calls, expr._parseError);
262 return std::tie(l._ops, l._calls, l._parseError) ==
263 std::tie(r._ops, r._calls, r._parseError);
273 friend std::ostream &
283 std::vector<Op> _ops;
287 std::vector<FnCall> _calls;
291 std::string _parseError;
294PXR_NAMESPACE_CLOSE_SCOPE
Represents a logical expression syntax tree consisting of predicate function calls joined by the logi...
SdfPredicateExpression()=default
Construct the empty expression whose bool-operator returns false.
SdfPredicateExpression & operator=(SdfPredicateExpression &&)=default
Move assign from another expression.
SdfPredicateExpression & operator=(SdfPredicateExpression const &)=default
Copy assign from another expression.
SDF_API std::string GetText() const
Return a text representation of this expression that parses to the same expression.
Op
Enumerant describing a subexpression operation.
SDF_API void Walk(TfFunctionRef< void(Op, int)> logic, TfFunctionRef< void(FnCall const &)> call) const
Walk this expression's syntax tree in depth-first order, calling call with the current function call ...
static SDF_API SdfPredicateExpression MakeOp(Op op, SdfPredicateExpression &&left, SdfPredicateExpression &&right)
Produce a new expression by combining left and right with the operator op.
static SDF_API SdfPredicateExpression MakeNot(SdfPredicateExpression &&right)
Produce a new expression by prepending the 'not' operator onto right.
SdfPredicateExpression(SdfPredicateExpression &&)=default
Move construct from another expression.
bool IsEmpty() const
Return true if this is the empty expression; i.e.
static SDF_API SdfPredicateExpression MakeCall(FnCall &&call)
Produce a new expression containing just a the function call call.
std::string GetParseError() &&
Return parsing errors as a string if this function was constructed from a string and parse errors wer...
SdfPredicateExpression(SdfPredicateExpression const &)=default
Copy construct from another expression.
std::string const & GetParseError() const &
Return parsing errors as a string if this function was constructed from a string and parse errors wer...
SDF_API void WalkWithOpStack(TfFunctionRef< void(std::vector< std::pair< Op, int > > const &)> logic, TfFunctionRef< void(FnCall const &)> call) const
Equivalent to Walk(), except that the logic function is called with a const reference to the current ...
SDF_API SdfPredicateExpression(std::string const &expr, std::string const &context={})
Construct an expression by parsing expr.
This class provides a non-owning reference to a type-erased callable object with a specified signatur...
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Represents a function argument name and value.
Represents a function call in an expression with calling style, function name, and arguments.
@ BareCall
no-arg call like 'active'
@ ParenCall
paren/comma & pos/kw args like 'foo(23, bar=baz)'
@ ColonCall
colon-separated pos args, like 'isa:Imageable'