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
103 bool IsStretch()
const {
104 return predicateIndex == -1 && text.empty();
108 int predicateIndex = -1;
109 bool isLiteral =
false;
112 return std::tie(l.text, l.predicateIndex, l.isLiteral) ==
113 std::tie(r.text, r.predicateIndex, r.isLiteral);
120 template <
class HashState>
121 friend void TfHashAppend(HashState &h,
Component const &c) {
122 h.Append(c.text, c.predicateIndex, c.isLiteral);
126 auto lt = std::tie(l.text, l.predicateIndex, l.isLiteral);
127 auto rt = std::tie(r.text, r.predicateIndex, r.isLiteral);
176 return std::move(_prefix);
193 std::vector<Component>
const &GetComponents() const & {
197 std::vector<Component> GetComponents() && {
201 std::vector<SdfPredicateExpression>
const &
202 GetPredicateExprs() const & {
206 std::vector<SdfPredicateExpression>
207 GetPredicateExprs() && {
211 bool IsProperty()
const {
216 explicit operator bool()
const {
221 template <
class HashState>
222 friend void TfHashAppend(HashState &h,
PathPattern const &pat) {
223 h.Append(pat._prefix, pat._components,
224 pat._predExprs, pat._isProperty);
229 return std::tie(l._prefix, l._components,
230 l._predExprs, l._isProperty) ==
231 std::tie(r._prefix, r._components,
232 r._predExprs, r._isProperty);
242 l._prefix, l._components, l._predExprs, l._isProperty);
244 r._prefix, r._components, r._predExprs, r._isProperty);
249 std::vector<Component> _components;
250 std::vector<SdfPredicateExpression> _predExprs;
275 template <
class HashState>
277 h.Append(er.path, er.name);
282 return std::tie(l.path, l.name) == std::tie(r.path, r.name);
286 operator!=(ExpressionReference
const &l, ExpressionReference
const &r) {
290 friend void swap(ExpressionReference &l, ExpressionReference &r) {
291 auto lt = std::tie(l.path, l.name);
292 auto rt = std::tie(r.path, r.name);
321 std::string
const &parseContext = {});
448 TfFunctionRef<
void (std::vector<std::pair<Op, int>>
const &)> logic,
456 SdfPath const &newPrefix)
const & {
489 return !_refs.empty();
559 explicit operator bool()
const {
570 template <
class HashState>
572 h.Append(expr._ops, expr._refs, expr._patterns, expr._parseError);
576 friend std::ostream &
581 return std::tie(l._ops, l._refs, l._patterns, l._parseError) ==
582 std::tie(r._ops, r._refs, r._patterns, r._parseError);
591 auto lt = std::tie(l._ops, l._refs, l._patterns, l._parseError);
592 auto rt = std::tie(r._ops, r._refs, r._patterns, r._parseError);
596 std::vector<Op> _ops;
597 std::vector<ExpressionReference> _refs;
598 std::vector<PathPattern> _patterns;
602 std::string _parseError;
606PXR_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 PathPattern(SdfPath const &prefix)
Construct a PathPattern with the prefix path.
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.
SDF_API PathPattern(SdfPath &&prefix)
Construct a PathPattern with the prefix path.
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...
static SdfPathExpression MakeAtom(SdfPath const &path)
Produce a new expression that matches path exactly.
std::string const & GetParseError() const &
Return parsing errors as a string if this function was constructed from a string and parse errors wer...
static SdfPathExpression MakeAtom(SdfPath &&path)
This is an overloaded member function, provided for convenience. It differs from the above function o...
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.