24 #ifndef PXR_USD_USD_PRIM_RANGE_H
25 #define PXR_USD_USD_PRIM_RANGE_H
28 #include "pxr/usd/usd/api.h"
36 PXR_NAMESPACE_OPEN_SCOPE
142 Usd_PrimDataConstPtr,
144 boost::forward_traversal_tag,
148 iterator() : iterator_adaptor_(
nullptr) {}
152 : iterator_adaptor_(e._range->_end)
153 , _range(e._range) {}
166 return _range == other._range &&
167 base() == other.base() &&
168 _proxyPrimPath == other._proxyPrimPath &&
169 _depth == other._depth &&
170 _pruneChildrenFlag == other._pruneChildrenFlag &&
171 _isPost == other._isPost;
176 return _range == other._range && base() == _range->_end;
181 return !(*
this == other);
186 return !(*
this == other);
191 friend class boost::iterator_core_access;
194 Usd_PrimDataConstPtr prim,
197 : iterator_adaptor_(prim)
199 , _proxyPrimPath(proxyPrimPath)
202 USD_API
void increment();
204 inline reference dereference()
const {
205 return UsdPrim(base(), _proxyPrimPath);
210 unsigned int _depth = 0;
214 bool _pruneChildrenFlag =
false;
217 bool _isPost =
false;
220 using const_iterator = iterator;
226 , _postOrder(false) {}
232 Usd_PrimDataConstPtr p = get_pointer(start._Prim());
233 _Init(p, p ? p->GetNextPrim() :
nullptr, start._ProxyPrimPath());
239 const Usd_PrimFlagsPredicate &predicate) {
240 Usd_PrimDataConstPtr p = get_pointer(start._Prim());
241 _Init(p, p ? p->GetNextPrim() :
nullptr,
242 start._ProxyPrimPath(), predicate);
258 result._postOrder =
true;
273 const Usd_PrimFlagsPredicate &predicate) {
275 result._postOrder =
true;
306 Stage(
const UsdStagePtr &stage,
311 return iterator(
this, _begin, _initProxyPrimPath, _initDepth);
315 return iterator(
this, _begin, _initProxyPrimPath, _initDepth);
341 _begin = newBegin.base();
342 _initProxyPrimPath = newBegin._proxyPrimPath;
343 _initDepth = newBegin._depth;
350 explicit operator bool()
const {
return !
empty(); }
354 return this == &other ||
355 (_begin == other._begin &&
356 _end == other._end &&
357 _initProxyPrimPath == other._initProxyPrimPath &&
358 _predicate == other._predicate &&
359 _postOrder == other._postOrder &&
360 _initDepth == other._initDepth);
365 return !(*
this == other);
370 Usd_PrimDataConstPtr
end,
372 const Usd_PrimFlagsPredicate &predicate =
374 _Init(begin, end, proxyPrimPath, predicate);
379 void _Init(
const Usd_PrimData *first,
380 const Usd_PrimData *last,
382 const Usd_PrimFlagsPredicate &predicate =
386 _initProxyPrimPath = proxyPrimPath;
387 _predicate = _begin ?
388 Usd_CreatePredicateForTraversal(_begin, proxyPrimPath, predicate) :
394 iterator b =
begin();
395 if (b.base() != _end &&
396 !Usd_EvalPredicate(_predicate, b.base(), proxyPrimPath)) {
397 b._pruneChildrenFlag =
true;
406 Usd_PrimDataConstPtr _begin;
407 Usd_PrimDataConstPtr _end;
409 Usd_PrimFlagsPredicate _predicate;
410 unsigned int _initDepth;
415 PXR_NAMESPACE_CLOSE_SCOPE
417 #endif // PXR_USD_USD_PRIM_RANGE_H
iterator begin() const
Return an iterator to the start of this range.
unspecified UsdPrimDefaultPredicate
The default predicate used for prim traversals in methods like UsdPrim::GetChildren, UsdStage::Traverse, and by UsdPrimRange.
bool operator==(EndSentinel const &other) const
Return true if this iterator is equivalent to other.
This class lets us represent past-the-end without the full weight of an iterator. ...
static UsdPrimRange AllPrimsPreAndPostVisit(const UsdPrim &start)
Construct a PrimRange that traverses the subtree rooted at start in depth-first order, visiting all prims (including deactivated, undefined, and abstract prims) with pre- and post-order visitation.
void set_begin(iterator const &newBegin)
Set the start of this range to newBegin.
UsdPrimRange(const UsdPrim &start, const Usd_PrimFlagsPredicate &predicate)
Construct a PrimRange that traverses the subtree rooted at start in depth-first order, visiting prims that pass predicate.
bool operator!=(iterator const &other) const
Return true if this iterator is not equivalent to other.
static UsdPrimRange AllPrims(const UsdPrim &start)
Construct a PrimRange that traverses the subtree rooted at start in depth-first order, visiting all prims (including deactivated, undefined, and abstract prims).
const_iterator cend() const
Return the past-the-end const_iterator for this range.
const_iterator cbegin() const
Return a const_iterator to the start of this range.
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
bool operator==(UsdPrimRange const &other) const
Return true if this range is equivalent to other.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
bool empty() const
Return true if this range contains no prims, false otherwise.
A path value used to locate objects in layers or scenegraphs.
USD_API void PruneChildren()
Behave as if the current prim has no children when next advanced.
static USD_API UsdPrimRange Stage(const UsdStagePtr &stage, const Usd_PrimFlagsPredicate &predicate=UsdPrimDefaultPredicate)
Create a PrimRange that traverses all the prims on stage, and visits those that pass the default pred...
UsdPrim front() const
Return the first element of this range. The range must not be empty().
UsdPrimRange(const UsdPrim &start)
Construct a PrimRange that traverses the subtree rooted at start in depth-first order, visiting prims that pass the default predicate (as defined by UsdPrimDefaultPredicate).
iterator(EndSentinel e)
Allow implicit conversion from EndSentinel.
An forward-iterable range that traverses a subtree of prims rooted at a given prim in depth-first ord...
void increment_begin()
Modify this range by advancing the beginning by one.
bool IsPostVisit() const
Return true if the iterator points to a prim visited the second time (in post order) for a pre- and p...
static UsdPrimRange PreAndPostVisit(const UsdPrim &start)
Create a PrimRange that traverses the subtree rooted at start in depth-first order, visiting prims that pass the default predicate (as defined by UsdPrimDefaultPredicate) with pre- and post-order visitation.
unspecified UsdPrimAllPrimsPredicate
Predicate that includes all prims.
iterator end() const
Return the past-the-end iterator for this range.
static UsdPrimRange PreAndPostVisit(const UsdPrim &start, const Usd_PrimFlagsPredicate &predicate)
Create a PrimRange that traverses the subtree rooted at start in depth-first order, visiting prims that pass predicate with pre- and post-order visitation.
A forward iterator into a UsdPrimRange.
bool operator!=(EndSentinel const &other) const
Return true if this iterator is not equivalent to other.
bool operator==(iterator const &other) const
Return true if this iterator is equivalent to other.
bool operator!=(UsdPrimRange const &other) const
Return true if this range is not equivalent to other.