7 #ifndef PXR_USD_SDF_PATH_EXPRESSION_EVAL_H
8 #define PXR_USD_SDF_PATH_EXPRESSION_EVAL_H
22 #include <type_traits>
28 template <
class DomainType>
32 template <
class DomainType>
51 void (SdfPathExpression::PathPattern
const &)> translatePattern);
60 explicit operator bool()
const {
65 class _PatternImplBase;
72 std::vector<int> _segmentMatchDepths;
73 int _constantDepth = -1;
74 bool _constantValue =
false;
86 void _Init(SdfPathExpression::PathPattern
const &
pattern,
144 SdfPathVector::const_iterator pathIterEnd,
145 SdfPathVector::const_iterator &pathIterInOut)
const;
159 SdfPathVector::const_iterator pathIterBegin,
160 SdfPathVector::const_iterator pathIterEnd,
161 SdfPathVector::const_iterator &pathIterInOut)
const;
201 template <
class DomainType>
205 class _PatternImpl :
public _PatternImplBase {
207 _PatternImpl() =
default;
209 _PatternImpl(SdfPathExpression::PathPattern
const &
pattern,
213 _predicates.push_back(
215 return _predicates.size()-1;
217 _Init(pattern, linkPredicate);
221 template <
class PathToObject>
224 PathToObject
const &pathToObj)
const {
225 auto runNthPredicate =
227 return _predicates[i](pathToObj(
path));
229 return _Match(objPath, runNthPredicate);
233 template <
class PathToObject>
236 _PatternIncrSearchState &
search,
237 PathToObject
const &pathToObj)
const {
238 auto runNthPredicate =
240 return _predicates[i](pathToObj(
path));
242 return _Next(search, objPath, runNthPredicate);
246 std::vector<SdfPredicateProgram<DomainType>> _predicates;
253 SdfMakePathExpressionEval<DomainType>(
258 return _patternImpls.empty();
262 template <
class PathToObject>
265 PathToObject
const &pathToObj)
const {
269 auto patternImplIter = _patternImpls.cbegin();
270 auto evalPattern = [&](
bool skip) {
272 (*patternImplIter++).Match(objPath, pathToObj);
284 template <
class PathToObject>
290 PathToObject
const &p2o)
292 , _incrSearchStates(_eval->_patternImpls.
size())
294 , _lastPathDepth(0) {}
299 , _incrSearchStates(_eval->_patternImpls.
size())
300 , _pathToObj(std::move(p2o))
301 , _lastPathDepth(0) {}
315 auto patternImplIter = _eval->_patternImpls.begin();
316 auto stateIter = _incrSearchStates.begin();
318 const bool pop = newDepth <= _lastPathDepth;
319 auto patternStateNext = [&](
bool skip) {
321 stateIter->Pop(newDepth);
323 auto const &patternImpl = *patternImplIter++;
324 auto &
state = *stateIter++;
327 : patternImpl.Next(objPath,
state, _pathToObj);
329 _lastPathDepth = newDepth;
330 return _eval->
_EvalExpr(patternStateNext);
341 std::vector<_PatternIncrSearchState> _incrSearchStates;
343 PathToObject _pathToObj;
350 template <
class PathToObject>
351 IncrementalSearcher<std::decay_t<PathToObject>>
353 return IncrementalSearcher<std::decay_t<PathToObject>>(
354 this, std::forward<PathToObject>(pathToObj));
358 std::vector<_PatternImpl> _patternImpls;
372 template <
class DomainType>
382 auto translatePattern = [&](Expr::PathPattern
const &
pattern) {
385 eval._patternImpls.emplace_back(
pattern, lib);
386 eval._ops.push_back(Eval::EvalPattern);
389 if (!Sdf_MakePathExpressionEvalImpl(eval, expr, translatePattern)) {
398 #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, PathToObject const &p2o)
std::vector< _Component > _components
bool _IsBarePredicate(_Component const &comp) const
SDF_API SdfPredicateFunctionResult _CheckMatch(_Segment const &seg, _RunNthPredFn runNthPredicate, SdfPathVector::const_iterator pathIterBegin, SdfPathVector::const_iterator pathIterEnd, SdfPathVector::const_iterator &pathIterInOut) const
bool EndsAt(size_t idx) const
SDF_API void Pop(int newDepth)
SdfPredicateProgram< DomainType > SdfLinkPredicateExpression(SdfPredicateExpression const &expr, SdfPredicateLibrary< DomainType > const &lib)
GLsizei const GLchar *const * path
SDF_API SdfPredicateFunctionResult _Match(SdfPath const &path, _RunNthPredFn runNthPredicate) const
bool StartsAt(size_t idx) const
IncrementalSearcher< std::decay_t< PathToObject > > MakeIncrementalSearcher(PathToObject &&pathToObj) 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)
SDF_API size_t GetPathElementCount() const
Returns the number of path elements in this path.
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)
size_t _SegmentMinMatchElts(_Segment const &seg) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
IncrementalSearcher(SdfPathExpressionEval const *eval, PathToObject &&p2o)
SDF_API SdfPredicateFunctionResult _Next(_PatternIncrSearchState &searchState, SdfPath const &path, _RunNthPredFn runNthPredicate) const
SdfPathExpressionEval< DomainType > SdfMakePathExpressionEval(SdfPathExpression const &expr, SdfPredicateLibrary< DomainType > const &lib)
SDF_API SdfPredicateFunctionResult _EvalExpr(TfFunctionRef< SdfPredicateFunctionResult(bool)> invokePattern) const
#define PXR_NAMESPACE_CLOSE_SCOPE
SdfPredicateFunctionResult Match(SdfPath const &objPath, PathToObject const &pathToObj) const
Test objPath for a match with this expression.
std::vector< _Segment > _segments
SDF_API SdfPredicateFunctionResult _CheckExactMatch(_Segment const &seg, _RunNthPredFn runNthPredicate, SdfPathVector::const_iterator pathIterEnd, SdfPathVector::const_iterator &pathIterInOut) const
TfFunctionRef< SdfPredicateFunctionResult(int, SdfPath const &)> _RunNthPredFn
SdfPredicateFunctionResult Next(SdfPath const &objPath)
enum Sdf_PathExpressionEvalBase::_PatternImplBase::@588 _matchObjType