24#ifndef PXR_USD_SDF_PATH_EXPRESSION_H
25#define PXR_USD_SDF_PATH_EXPRESSION_H
28#include "pxr/usd/sdf/api.h"
29#include "pxr/usd/sdf/path.h"
30#include "pxr/usd/sdf/predicateExpression.h"
39PXR_NAMESPACE_OPEN_SCOPE
95 bool IsStretch()
const {
96 return predicateIndex == -1 && text.empty();
100 int predicateIndex = -1;
101 bool isLiteral =
false;
104 return std::tie(l.text, l.predicateIndex, l.isLiteral) ==
105 std::tie(r.text, r.predicateIndex, r.isLiteral);
112 template <
class HashState>
113 friend void TfHashAppend(HashState &h,
Component const &c) {
114 h.Append(c.text, c.predicateIndex, c.isLiteral);
118 auto lt = std::tie(l.text, l.predicateIndex, l.isLiteral);
119 auto rt = std::tie(r.text, r.predicateIndex, r.isLiteral);
168 return std::move(_prefix);
185 std::vector<Component>
const &GetComponents() const & {
189 std::vector<Component> GetComponents() && {
193 std::vector<SdfPredicateExpression>
const &
194 GetPredicateExprs() const & {
198 std::vector<SdfPredicateExpression>
199 GetPredicateExprs() && {
203 bool IsProperty()
const {
208 explicit operator bool()
const {
213 template <
class HashState>
214 friend void TfHashAppend(HashState &h,
PathPattern const &pat) {
215 h.Append(pat._prefix, pat._components,
216 pat._predExprs, pat._isProperty);
221 return std::tie(l._prefix, l._components,
222 l._predExprs, l._isProperty) ==
223 std::tie(r._prefix, r._components,
224 r._predExprs, r._isProperty);
234 l._prefix, l._components, l._predExprs, l._isProperty);
236 r._prefix, r._components, r._predExprs, r._isProperty);
241 std::vector<Component> _components;
242 std::vector<SdfPredicateExpression> _predExprs;
267 template <
class HashState>
269 h.Append(er.path, er.name);
274 return std::tie(l.path, l.name) == std::tie(r.path, r.name);
278 operator!=(ExpressionReference
const &l, ExpressionReference
const &r) {
282 friend void swap(ExpressionReference &l, ExpressionReference &r) {
283 auto lt = std::tie(l.path, l.name);
284 auto rt = std::tie(r.path, r.name);
313 std::string
const &parseContext = {});
428 TfFunctionRef<
void (std::vector<std::pair<Op, int>>
const &)> logic,
436 SdfPath const &newPrefix)
const & {
469 return !_refs.empty();
539 explicit operator bool()
const {
550 template <
class HashState>
552 h.Append(expr._ops, expr._refs, expr._patterns, expr._parseError);
556 friend std::ostream &
561 return std::tie(l._ops, l._refs, l._patterns, l._parseError) ==
562 std::tie(r._ops, r._refs, r._patterns, r._parseError);
571 auto lt = std::tie(l._ops, l._refs, l._patterns, l._parseError);
572 auto rt = std::tie(r._ops, r._refs, r._patterns, r._parseError);
576 std::vector<Op> _ops;
577 std::vector<ExpressionReference> _refs;
578 std::vector<PathPattern> _patterns;
582 std::string _parseError;
586PXR_NAMESPACE_CLOSE_SCOPE
Objects of this class represent references to other path expressions, which will be resolved later by...
static SDF_API ExpressionReference const & Weaker()
Return the special "weaker" reference, whose syntax in an SdfPathExpression is "%_".
Objects of this class represent SdfPath matching patterns, consisting of an SdfPath prefix followed b...
SDF_API void AppendChild(std::string const &text, SdfPredicateExpression &&predExpr)
Append a prim child component to this pattern, with optional predicate expression predExpr.
SDF_API void SetPrefix(SdfPath &&p)
Set this pattern's non-speculative prefix (leading path components with no wildcards and no predicate...
SDF_API void AppendProperty(std::string const &text, SdfPredicateExpression const &predExpr)
This is an overloaded member function, provided for convenience. It differs from the above function o...
SDF_API std::string GetText() const
Return the string representation of this pattern.
SDF_API void AppendProperty(std::string const &text)
This is an overloaded member function, provided for convenience. It differs from the above function o...
SDF_API void AppendChild(std::string const &text, SdfPredicateExpression const &predExpr)
This is an overloaded member function, provided for convenience. It differs from the above function o...
SDF_API void AppendChild(std::string const &text)
This is an overloaded member function, provided for convenience. It differs from the above function o...
SdfPath const & GetPrefix() const &
Return this pattern's non-speculative prefix (leading path components with no wildcards and no predic...
SDF_API void AppendProperty(std::string const &text, SdfPredicateExpression &&predExpr)
Append a prim property component to this pattern, with optional predicate expression predExpr.
void SetPrefix(SdfPath const &p)
This is an overloaded member function, provided for convenience. It differs from the above function o...
SdfPath GetPrefix() &&
This is an overloaded member function, provided for convenience. It differs from the above function o...
SDF_API PathPattern()
Construct the empty pattern whose bool-conversion operator returns false.
Objects of this class represent a logical expression syntax tree consisting of SdfPath matching patte...
SDF_API SdfPathExpression ReplacePrefix(SdfPath const &oldPrefix, SdfPath const &newPrefix) &&
Return a new expression created by replacing literal path prefixes that start with oldPrefix with new...
static SDF_API SdfPathExpression MakeAtom(ExpressionReference &&ref)
Produce a new expression containing only the reference ref.
SDF_API bool IsAbsolute() const
Return true if all contained pattern prefixes are absolute, false otherwise.
static SDF_API SdfPathExpression const & EveryDescendant()
Return the relative expression ".//" which matches all paths descendant to an anchor path.
static SdfPathExpression MakeAtom(ExpressionReference const &ref)
This is an overloaded member function, provided for convenience. It differs from the above function o...
SDF_API SdfPathExpression MakeAbsolute(SdfPath const &anchor) &&
Return a new expression created by making any relative path prefixes in this expression absolute by S...
bool IsComplete() const
Return true if this expression is considered "complete".
static SDF_API SdfPathExpression MakeAtom(PathPattern &&pattern)
Produce a new expression containing only the pattern pattern.
SDF_API std::string GetText() const
Return a text representation of this expression that parses to the same expression.
SDF_API SdfPathExpression(std::string const &expr, std::string const &parseContext={})
Construct an expression by parsing expr.
static SdfPathExpression MakeAtom(PathPattern const &pattern)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Op
Enumerant describing a subexpression operation.
static SDF_API SdfPathExpression const & Nothing()
Return the empty expression which matches no paths.
SdfPathExpression ComposeOver(SdfPathExpression const &weaker) const &
Return a new expression created by replacing references to the "weaker expression" (i....
SdfPathExpression ReplacePrefix(SdfPath const &oldPrefix, SdfPath const &newPrefix) const &
Return a new expression created by replacing literal path prefixes that start with oldPrefix with new...
static SDF_API SdfPathExpression MakeComplement(SdfPathExpression &&right)
Produce a new expression representing the set-complement of right.
SdfPathExpression()=default
Default construction produces the "empty" expression.
static SDF_API SdfPathExpression const & Everything()
Return the expression "//" which matches all paths.
bool IsEmpty() const
Return true if this is the empty expression; i.e.
SdfPathExpression MakeAbsolute(SdfPath const &anchor) const &
Return a new expression created by making any relative path prefixes in this expression absolute by S...
static SdfPathExpression MakeOp(Op op, SdfPathExpression const &left, SdfPathExpression const &right)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool ContainsExpressionReferences() const
Return true if this expression contains any references to other collections.
SDF_API void Walk(TfFunctionRef< void(Op, int)> logic, TfFunctionRef< void(ExpressionReference const &)> ref, TfFunctionRef< void(PathPattern const &)> pattern) const
Walk this expression's syntax tree in depth-first order, calling pattern with the current PathPattern...
SDF_API SdfPathExpression ComposeOver(SdfPathExpression const &weaker) &&
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::string const & GetParseError() const &
Return parsing errors as a string if this function was constructed from a string and parse errors wer...
static SDF_API SdfPathExpression MakeOp(Op op, SdfPathExpression &&left, SdfPathExpression &&right)
Produce a new expression representing the set-algebraic operation op with operands left and right.
static SDF_API SdfPathExpression const & WeakerRef()
Return the expression "%_", consisting solely of a reference to the "weaker" path expression,...
SDF_API void WalkWithOpStack(TfFunctionRef< void(std::vector< std::pair< Op, int > > const &)> logic, TfFunctionRef< void(ExpressionReference const &)> ref, TfFunctionRef< void(PathPattern const &)> pattern) const
Equivalent to Walk(), except that the logic function is called with a const reference to the current ...
SDF_API SdfPathExpression ResolveReferences(TfFunctionRef< SdfPathExpression(ExpressionReference const &)> resolve) &&
This is an overloaded member function, provided for convenience. It differs from the above function o...
static SdfPathExpression MakeComplement(SdfPathExpression const &right)
This is an overloaded member function, provided for convenience. It differs from the above function o...
SdfPathExpression ResolveReferences(TfFunctionRef< SdfPathExpression(ExpressionReference const &)> resolve) const &
Return a new expression created by resolving collection references in this expression.
SDF_API bool ContainsWeakerExpressionReference() const
Return true if this expression contains one or more "weaker" expression references,...
A path value used to locate objects in layers or scenegraphs.
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
Represents a logical expression syntax tree consisting of predicate function calls joined by the logi...
This class provides a non-owning reference to a type-erased callable object with a specified signatur...
A component represents a pattern matching component past the initial SdfPath prefix.