24 #ifndef PXR_USD_SDF_PATH_EXPRESSION_EVAL_H
25 #define PXR_USD_SDF_PATH_EXPRESSION_EVAL_H
39 #include <type_traits>
45 template <
class DomainType>
49 template <
class DomainType>
68 void (SdfPathExpression::PathPattern
const &)> translatePattern);
77 explicit operator bool()
const {
82 class _PatternImplBase;
87 void Pop(
int newDepth) {
88 while (!_segmentMatchDepths.empty() &&
89 _segmentMatchDepths.back() >= newDepth) {
90 _segmentMatchDepths.pop_back();
92 if (newDepth <= _constantDepth) {
97 std::vector<int> _segmentMatchDepths;
98 int _constantDepth = -1;
99 bool _constantValue =
false;
108 void _Init(SdfPathExpression::PathPattern
const &
pattern,
117 runNthPredicate)
const;
124 runNthPredicate)
const;
180 template <
class DomainType>
184 class _PatternImpl :
public _PatternImplBase {
186 _PatternImpl() =
default;
188 _PatternImpl(SdfPathExpression::PathPattern
const &
pattern,
192 _predicates.push_back(
194 return _predicates.size()-1;
196 _Init(pattern, linkPredicate);
200 template <
class ObjectToPath,
class PathToObject>
202 Match(DomainType
const &obj,
203 ObjectToPath
const &objToPath,
204 PathToObject
const &pathToObj)
const {
205 auto runNthPredicate =
207 return _predicates[i](pathToObj(
path));
209 return _Match(objToPath(obj), runNthPredicate);
213 template <
class ObjectToPath,
class PathToObject>
215 Next(DomainType
const &obj,
216 _PatternIncrSearchState &
search,
217 ObjectToPath
const &objToPath,
218 PathToObject
const &pathToObj)
const {
219 auto runNthPredicate =
221 return _predicates[i](pathToObj(
path));
223 return _Next(search, objToPath(obj), runNthPredicate);
227 std::vector<SdfPredicateProgram<DomainType>> _predicates;
234 SdfMakePathExpressionEval<DomainType>(
239 return _patternImpls.empty();
243 template <
class ObjectToPath,
class PathToObject>
246 ObjectToPath
const &objToPath,
247 PathToObject
const &pathToObj)
const {
251 auto patternImplIter = _patternImpls.cbegin();
252 auto evalPattern = [&](
bool skip) {
254 (*patternImplIter++).Match(obj, objToPath, pathToObj);
266 template <
class ObjectToPath,
class PathToObject>
272 ObjectToPath
const &o2p,
273 PathToObject
const &p2o)
275 , _incrSearchStates(_eval->_patternImpls.
size())
278 , _lastPathDepth(0) {}
284 , _incrSearchStates(_eval->_patternImpls.
size())
285 , _objToPath(std::move(o2p))
286 , _pathToObj(std::move(p2o))
287 , _lastPathDepth(0) {}
301 auto patternImplIter = _eval->_patternImpls.begin();
302 auto stateIter = _incrSearchStates.begin();
303 int newDepth = _objToPath(obj).GetPathElementCount();
304 const int popLevel = (newDepth <= _lastPathDepth) ? newDepth : 0;
305 auto patternStateNext = [&](
bool skip) {
307 stateIter->Pop(popLevel);
310 : (*patternImplIter++).Next(
311 obj, *stateIter++, _objToPath, _pathToObj);
313 _lastPathDepth = newDepth;
314 return _eval->
_EvalExpr(patternStateNext);
321 _eval, std::move(_objToPath), std::move(_pathToObj)
327 std::vector<_PatternIncrSearchState> _incrSearchStates;
329 ObjectToPath _objToPath;
330 PathToObject _pathToObj;
337 template <
class ObjectToPath,
class PathToObject>
338 IncrementalSearcher<std::decay_t<ObjectToPath>,
339 std::decay_t<PathToObject>>
341 PathToObject &&pathToObj)
const {
342 return IncrementalSearcher<
343 std::decay_t<ObjectToPath>,
344 std::decay_t<PathToObject>>(
345 this, std::forward<ObjectToPath>(objToPath),
346 std::forward<PathToObject>(pathToObj));
350 std::vector<_PatternImpl> _patternImpls;
364 template <
class DomainType>
374 auto translatePattern = [&](Expr::PathPattern
const &
pattern) {
377 eval._patternImpls.emplace_back(
pattern, lib);
378 eval._ops.push_back(Eval::EvalPattern);
381 if (!Sdf_MakePathExpressionEvalImpl(eval, expr, translatePattern)) {
390 #endif // PXR_USD_SDF_PATH_EXPRESSION_EVAL_H
friend SDF_API bool Sdf_MakePathExpressionEvalImpl(Sdf_PathExpressionEvalBase &eval, SdfPathExpression const &expr, TfFunctionRef< void(SdfPathExpression::PathPattern const &)> translatePattern)
IncrementalSearcher(SdfPathExpressionEval const *eval, ObjectToPath const &o2p, PathToObject const &p2o)
std::vector< _Component > _components
SdfPredicateFunctionResult Next(DomainType const &obj)
bool EndsAt(size_t idx) const
SdfPredicateProgram< DomainType > SdfLinkPredicateExpression(SdfPredicateExpression const &expr, SdfPredicateLibrary< DomainType > const &lib)
SDF_API SdfPredicateFunctionResult _Next(_PatternIncrSearchState &searchState, SdfPath const &path, TfFunctionRef< SdfPredicateFunctionResult(int, SdfPath const &)> runNthPredicate) const
GLsizei const GLchar *const * path
bool StartsAt(size_t idx) const
std::vector< ArchRegex > _regexes
std::vector< std::string > _explicitNames
static SdfPredicateFunctionResult MakeConstant(bool value)
Create with value and 'ConstantOverDescendants'.
HUSD_API bool eval(VtValue &val, T &ret_val)
auto search(const T &set, const V &val) -> std::pair< bool, decltype(std::begin(detail::smart_deref(set)))>
A search function.
SDF_API void _Init(SdfPathExpression::PathPattern const &pattern, TfFunctionRef< int(SdfPredicateExpression const &)> linkPredicate)
IncrementalSearcher< std::decay_t< ObjectToPath >, std::decay_t< PathToObject > > MakeIncrementalSearcher(ObjectToPath &&objToPath, PathToObject &&pathToObj) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
SdfPathExpressionEval< DomainType > SdfMakePathExpressionEval(SdfPathExpression const &expr, SdfPredicateLibrary< DomainType > const &lib)
SDF_API SdfPredicateFunctionResult _Match(SdfPath const &path, TfFunctionRef< SdfPredicateFunctionResult(int, SdfPath const &)> runNthPredicate) const
SDF_API SdfPredicateFunctionResult _EvalExpr(TfFunctionRef< SdfPredicateFunctionResult(bool)> invokePattern) const
#define PXR_NAMESPACE_CLOSE_SCOPE
std::vector< _Segment > _segments
IncrementalSearcher(SdfPathExpressionEval const *eval, ObjectToPath &&o2p, PathToObject &&p2o)
SdfPredicateFunctionResult Match(DomainType const &obj, ObjectToPath const &objToPath, PathToObject const &pathToObj) const
Test obj for a match with this expression.