24#ifndef PXR_USD_SDF_PREDICATE_EXPRESSION_H
25#define PXR_USD_SDF_PREDICATE_EXPRESSION_H
28#include "pxr/usd/sdf/api.h"
30#include "pxr/base/vt/value.h"
38PXR_NAMESPACE_OPEN_SCOPE
94 return { std::string(), val };
96 static FnArg Keyword(std::string
const &name,
VtValue const &val) {
102 template <
class HashState>
103 friend void TfHashAppend(HashState &h,
FnArg const &arg) {
104 h.Append(arg.argName, arg.value);
107 friend bool operator==(
FnArg const &l,
FnArg const &r) {
108 return std::tie(l.argName, l.value) == std::tie(r.argName, r.value);
110 friend bool operator!=(
FnArg const &l,
FnArg const &r) {
115 swap(l.argName, r.argName);
116 swap(l.value, r.value);
132 std::string funcName;
133 std::vector<FnArg> args;
135 template <
class HashState>
136 friend void TfHashAppend(HashState &h,
FnCall const &c) {
137 h.Append(c.kind, c.funcName, c.args);
140 friend bool operator==(FnCall
const &l, FnCall
const &r) {
141 return std::tie(l.kind, l.funcName, l.args) ==
142 std::tie(r.kind, r.funcName, r.args);
144 friend bool operator!=(FnCall
const &l, FnCall
const &r) {
147 friend void swap(FnCall &l, FnCall &r) {
148 auto lt = std::tie(l.kind, l.funcName, l.args);
149 auto rt = std::tie(r.kind, r.funcName, r.args);
168 std::string
const &context = {});
179 enum Op { Call, Not, ImpliedAnd, And, Or };
239 TfFunctionRef<
void (std::vector<std::pair<Op, int>>
const &)> logic,
254 explicit operator bool()
const {
271 template <
class HashState>
273 h.Append(expr._ops, expr._calls, expr._parseError);
279 return std::tie(l._ops, l._calls, l._parseError) ==
280 std::tie(r._ops, r._calls, r._parseError);
290 friend std::ostream &
300 std::vector<Op> _ops;
304 std::vector<FnCall> _calls;
308 std::string _parseError;
311PXR_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.
std::string GetParseError() const &&
Return parsing errors as a string if this function was constructed from a string and parse errors wer...
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.
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'