7#ifndef PXR_USD_USD_PRIM_RANGE_H
8#define PXR_USD_USD_PRIM_RANGE_H
11#include "pxr/usd/usd/api.h"
19PXR_NAMESPACE_OPEN_SCOPE
124 using _UnderlyingIterator = Usd_PrimDataConstPtr;
127 UsdPrim* operator->() {
return &_prim; }
130 explicit _PtrProxy(
const UsdPrim& prim) : _prim(prim) {}
134 using iterator_category = std::forward_iterator_tag;
137 using pointer = _PtrProxy;
138 using difference_type = std::ptrdiff_t;
144 : _underlyingIterator(e._range->_end)
145 , _range(e._range) {}
147 reference operator*()
const {
return dereference(); }
148 pointer operator->()
const {
return pointer(dereference()); }
150 iterator& operator++() {
155 iterator operator++(
int) {
156 iterator result = *
this;
172 return _range == other._range &&
173 _underlyingIterator == other._underlyingIterator &&
174 _proxyPrimPath == other._proxyPrimPath &&
175 _depth == other._depth &&
176 _pruneChildrenFlag == other._pruneChildrenFlag &&
177 _isPost == other._isPost;
182 return _range == other._range &&
183 _underlyingIterator == _range->_end;
188 return !(*
this == other);
193 return !(*
this == other);
200 Usd_PrimDataConstPtr prim,
203 : _underlyingIterator(prim)
205 , _proxyPrimPath(proxyPrimPath)
208 USD_API
void increment();
210 inline reference dereference()
const {
211 return UsdPrim(_underlyingIterator, _proxyPrimPath);
214 _UnderlyingIterator _underlyingIterator =
nullptr;
217 unsigned int _depth = 0;
221 bool _pruneChildrenFlag =
false;
224 bool _isPost =
false;
227 using const_iterator = iterator;
233 , _postOrder(false) {}
239 Usd_PrimDataConstPtr p = get_pointer(start._Prim());
240 _Init(p, p ? p->GetNextPrim() :
nullptr, start._ProxyPrimPath());
246 const Usd_PrimFlagsPredicate &predicate) {
247 Usd_PrimDataConstPtr p = get_pointer(start._Prim());
248 _Init(p, p ? p->GetNextPrim() :
nullptr,
249 start._ProxyPrimPath(), predicate);
265 result._postOrder =
true;
280 const Usd_PrimFlagsPredicate &predicate) {
282 result._postOrder =
true;
318 return iterator(
this, _begin, _initProxyPrimPath, _initDepth);
322 return iterator(
this, _begin, _initProxyPrimPath, _initDepth);
348 _begin = newBegin._underlyingIterator;
349 _initProxyPrimPath = newBegin._proxyPrimPath;
350 _initDepth = newBegin._depth;
357 explicit operator bool()
const {
return !
empty(); }
361 return this == &other ||
362 (_begin == other._begin &&
363 _end == other._end &&
364 _initProxyPrimPath == other._initProxyPrimPath &&
365 _predicate == other._predicate &&
366 _postOrder == other._postOrder &&
367 _initDepth == other._initDepth);
372 return !(*
this == other);
377 Usd_PrimDataConstPtr
end,
379 const Usd_PrimFlagsPredicate &predicate =
381 _Init(
begin,
end, proxyPrimPath, predicate);
386 void _Init(
const Usd_PrimData *first,
387 const Usd_PrimData *last,
389 const Usd_PrimFlagsPredicate &predicate =
393 _initProxyPrimPath = proxyPrimPath;
394 _predicate = _begin ?
395 Usd_CreatePredicateForTraversal(_begin, proxyPrimPath, predicate) :
401 iterator b =
begin();
402 if (b._underlyingIterator != _end &&
403 !Usd_EvalPredicate(_predicate, b._underlyingIterator,
405 b._pruneChildrenFlag =
true;
414 Usd_PrimDataConstPtr _begin;
415 Usd_PrimDataConstPtr _end;
417 Usd_PrimFlagsPredicate _predicate;
418 unsigned int _initDepth;
423PXR_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.