24#ifndef PXR_USD_USD_PRIM_RANGE_H
25#define PXR_USD_USD_PRIM_RANGE_H
28#include "pxr/usd/usd/api.h"
36PXR_NAMESPACE_OPEN_SCOPE
141 using _UnderlyingIterator = Usd_PrimDataConstPtr;
144 UsdPrim* operator->() {
return &_prim; }
147 explicit _PtrProxy(
const UsdPrim& prim) : _prim(prim) {}
151 using iterator_category = std::forward_iterator_tag;
154 using pointer = _PtrProxy;
155 using difference_type = std::ptrdiff_t;
161 : _underlyingIterator(e._range->_end)
162 , _range(e._range) {}
164 reference operator*()
const {
return dereference(); }
165 pointer operator->()
const {
return pointer(dereference()); }
167 iterator& operator++() {
172 iterator operator++(
int) {
173 iterator result = *
this;
189 return _range == other._range &&
190 _underlyingIterator == other._underlyingIterator &&
191 _proxyPrimPath == other._proxyPrimPath &&
192 _depth == other._depth &&
193 _pruneChildrenFlag == other._pruneChildrenFlag &&
194 _isPost == other._isPost;
199 return _range == other._range &&
200 _underlyingIterator == _range->_end;
205 return !(*
this == other);
210 return !(*
this == other);
217 Usd_PrimDataConstPtr prim,
220 : _underlyingIterator(prim)
222 , _proxyPrimPath(proxyPrimPath)
225 USD_API
void increment();
227 inline reference dereference()
const {
228 return UsdPrim(_underlyingIterator, _proxyPrimPath);
231 _UnderlyingIterator _underlyingIterator =
nullptr;
234 unsigned int _depth = 0;
238 bool _pruneChildrenFlag =
false;
241 bool _isPost =
false;
244 using const_iterator = iterator;
250 , _postOrder(false) {}
256 Usd_PrimDataConstPtr p = get_pointer(start._Prim());
257 _Init(p, p ? p->GetNextPrim() :
nullptr, start._ProxyPrimPath());
263 const Usd_PrimFlagsPredicate &predicate) {
264 Usd_PrimDataConstPtr p = get_pointer(start._Prim());
265 _Init(p, p ? p->GetNextPrim() :
nullptr,
266 start._ProxyPrimPath(), predicate);
282 result._postOrder =
true;
297 const Usd_PrimFlagsPredicate &predicate) {
299 result._postOrder =
true;
335 return iterator(
this, _begin, _initProxyPrimPath, _initDepth);
339 return iterator(
this, _begin, _initProxyPrimPath, _initDepth);
365 _begin = newBegin._underlyingIterator;
366 _initProxyPrimPath = newBegin._proxyPrimPath;
367 _initDepth = newBegin._depth;
374 explicit operator bool()
const {
return !
empty(); }
378 return this == &other ||
379 (_begin == other._begin &&
380 _end == other._end &&
381 _initProxyPrimPath == other._initProxyPrimPath &&
382 _predicate == other._predicate &&
383 _postOrder == other._postOrder &&
384 _initDepth == other._initDepth);
389 return !(*
this == other);
394 Usd_PrimDataConstPtr
end,
396 const Usd_PrimFlagsPredicate &predicate =
398 _Init(
begin,
end, proxyPrimPath, predicate);
403 void _Init(
const Usd_PrimData *first,
404 const Usd_PrimData *last,
406 const Usd_PrimFlagsPredicate &predicate =
410 _initProxyPrimPath = proxyPrimPath;
411 _predicate = _begin ?
412 Usd_CreatePredicateForTraversal(_begin, proxyPrimPath, predicate) :
418 iterator b =
begin();
419 if (b._underlyingIterator != _end &&
420 !Usd_EvalPredicate(_predicate, b._underlyingIterator,
422 b._pruneChildrenFlag =
true;
431 Usd_PrimDataConstPtr _begin;
432 Usd_PrimDataConstPtr _end;
434 Usd_PrimFlagsPredicate _predicate;
435 unsigned int _initDepth;
440PXR_NAMESPACE_CLOSE_SCOPE
A path value used to locate objects in layers or scenegraphs.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
This class lets us represent past-the-end without the full weight of an iterator.
A forward iterator into a UsdPrimRange.
bool IsPostVisit() const
Return true if the iterator points to a prim visited the second time (in post order) for a pre- and p...
USD_API void PruneChildren()
Behave as if the current prim has no children when next advanced.
bool operator!=(iterator const &other) const
Return true if this iterator is not equivalent to other.
bool operator==(EndSentinel const &other) const
Return true if this iterator is equivalent to other.
bool operator==(iterator const &other) const
Return true if this iterator is equivalent to other.
bool operator!=(EndSentinel const &other) const
Return true if this iterator is not equivalent to other.
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...
iterator begin() const
Return an iterator to the start of this range.
static UsdPrimRange AllPrims(const UsdPrim &start)
Construct a PrimRange that traverses the subtree rooted at start in depth-first order,...
static UsdPrimRange AllPrimsPreAndPostVisit(const UsdPrim &start)
Construct a PrimRange that traverses the subtree rooted at start in depth-first order,...
const_iterator cbegin() const
Return a const_iterator to the start of this range.
static UsdPrimRange PreAndPostVisit(const UsdPrim &start)
Create a PrimRange that traverses the subtree rooted at start in depth-first order,...
UsdPrimRange(const UsdPrim &start)
Construct a PrimRange that traverses the subtree rooted at start in depth-first order,...
bool empty() const
Return true if this range contains no prims, false otherwise.
iterator end() const
Return the past-the-end iterator for this range.
void increment_begin()
Modify this range by advancing the beginning by one.
bool operator==(UsdPrimRange const &other) const
Return true if this range is equivalent to other.
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...
const_iterator cend() const
Return the past-the-end const_iterator for this range.
UsdPrimRange(const UsdPrim &start, const Usd_PrimFlagsPredicate &predicate)
Construct a PrimRange that traverses the subtree rooted at start in depth-first order,...
UsdPrim front() const
Return the first element of this range. The range must not be empty().
static UsdPrimRange PreAndPostVisit(const UsdPrim &start, const Usd_PrimFlagsPredicate &predicate)
Create a PrimRange that traverses the subtree rooted at start in depth-first order,...
bool operator!=(UsdPrimRange const &other) const
Return true if this range is not equivalent to other.
void set_begin(iterator const &newBegin)
Set the start of this range to newBegin.
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
unspecified UsdPrimDefaultPredicate
The default predicate used for prim traversals in methods like UsdPrim::GetChildren,...
unspecified UsdPrimAllPrimsPredicate
Predicate that includes all prims.