7#ifndef PXR_USD_PCP_ITERATOR_H
8#define PXR_USD_PCP_ITERATOR_H
11#include "pxr/usd/pcp/api.h"
12#include "pxr/usd/pcp/node.h"
16#include "pxr/usd/sdf/site.h"
22PXR_NAMESPACE_OPEN_SCOPE
25class PcpPrimIndex_Graph;
40 explicit _PtrProxy(
const PcpNodeRef& nodeRef) : _nodeRef(nodeRef) {}
44 using iterator_category = std::random_access_iterator_tag;
47 using pointer = _PtrProxy;
48 using difference_type = std::ptrdiff_t;
54 Pcp_CompressedSdSite GetCompressedSdSite(
size_t layerIndex)
const
56 return Pcp_CompressedSdSite(_nodeIdx, layerIndex);
59 reference operator*()
const {
return dereference(); }
60 pointer operator->()
const {
return pointer(dereference()); }
61 reference operator[](
const difference_type index)
const {
63 advanced.advance(index);
64 return advanced.dereference();
68 return -distance_to(other);
95 result.advance(increment);
101 result.advance(-decrement);
120 return !equal(other);
125 return _nodeIdx < other._nodeIdx;
130 return _nodeIdx <= other._nodeIdx;
135 return _nodeIdx > other._nodeIdx;
140 return _nodeIdx >= other._nodeIdx;
146 _graph(graph), _nodeIdx(nodeIdx) {}
148 void increment() { ++_nodeIdx; }
149 void decrement() { --_nodeIdx; }
150 void advance(difference_type n) { _nodeIdx += n; }
152 return (difference_type)(other._nodeIdx) - _nodeIdx;
155 return (_graph == other._graph) & (_nodeIdx == other._nodeIdx);
157 reference dereference()
const {
162 PcpPrimIndex_Graph* _graph =
nullptr;
172 :
public Tf_ProxyReferenceReverseIterator<PcpNodeIterator>
177 : Tf_ProxyReferenceReverseIterator<PcpNodeIterator>(iter) {}
189 SdfSite* operator->() {
return &_site; }
192 explicit _PtrProxy(
const SdfSite& site) : _site(site) {}
196 using iterator_category = std::random_access_iterator_tag;
199 using pointer = _PtrProxy;
200 using difference_type = std::ptrdiff_t;
218 Pcp_SdSiteRef _GetSiteRef()
const;
220 reference operator*()
const {
return dereference(); }
221 pointer operator->()
const {
return pointer(dereference()); }
222 reference operator[](
const difference_type index)
const {
224 advanced.advance(index);
225 return advanced.dereference();
229 return -distance_to(other);
256 result.advance(increment);
262 result.advance(-decrement);
281 return !equal(other);
286 return _pos < other._pos;
291 return _pos <= other._pos;
296 return _pos > other._pos;
301 return _pos >= other._pos;
310 void advance(difference_type n);
316 reference dereference()
const;
329 :
public Tf_ProxyReferenceReverseIterator<PcpPrimIterator>
334 : Tf_ProxyReferenceReverseIterator<PcpPrimIterator>(iter) { }
339 return (--tmp).GetNode();
342 Pcp_SdSiteRef _GetSiteRef()
const
345 return (--tmp)._GetSiteRef();
357 using iterator_category = std::random_access_iterator_tag;
358 using value_type =
const SdfPropertySpecHandle;
359 using reference =
const SdfPropertySpecHandle&;
360 using pointer =
const SdfPropertySpecHandle*;
361 using difference_type = std::ptrdiff_t;
381 reference operator*()
const {
return dereference(); }
382 pointer operator->()
const {
return &(dereference()); }
383 reference operator[](
const difference_type index)
const {
385 advanced.advance(index);
386 return advanced.dereference();
390 return -distance_to(other);
417 result.advance(increment);
423 result.advance(-decrement);
442 return !equal(other);
447 return _pos < other._pos;
452 return _pos <= other._pos;
457 return _pos > other._pos;
462 return _pos >= other._pos;
471 void advance(difference_type n);
477 reference dereference()
const;
490 :
public std::reverse_iterator<PcpPropertyIterator>
495 : std::reverse_iterator<PcpPropertyIterator>(iter) { }
500 return (--tmp).GetNode();
506 return (--tmp).IsLocal();
513#define PCP_DEFINE_RANGE(Range, Iterator, ReverseIterator) \
514 typedef std::pair<Iterator, Iterator> Range; \
516 inline Iterator begin(Range &range) { return range.first; } \
517 inline Iterator begin(const Range &range) { return range.first; } \
518 inline Iterator end(Range &range) { return range.second; } \
519 inline Iterator end(const Range &range) { return range.second; } \
522 struct Tf_IteratorInterface<Range, false> { \
523 typedef Iterator IteratorType; \
524 static IteratorType Begin(Range &c) { return c.first; } \
525 static IteratorType End(Range &c) { return c.second; } \
529 struct Tf_IteratorInterface<const Range, false> { \
530 typedef Iterator IteratorType; \
531 static IteratorType Begin(Range const &c) { return c.first; } \
532 static IteratorType End(Range const &c) { return c.second; } \
536 struct Tf_IteratorInterface<Range, true> { \
537 typedef ReverseIterator IteratorType; \
538 static IteratorType Begin(Range &c) \
539 { return IteratorType(c.second); } \
540 static IteratorType End(Range &c) \
541 { return IteratorType(c.first); } \
545 struct Tf_IteratorInterface<const Range, true> { \
546 typedef ReverseIterator IteratorType; \
547 static IteratorType Begin(Range const &c) \
548 { return IteratorType(c.second); } \
549 static IteratorType End(Range const &c) \
550 { return IteratorType(c.first); } \
554 struct Tf_ShouldIterateOverCopy<Range> : std::true_type {}; \
557 struct Tf_ShouldIterateOverCopy<const Range> : std::true_type {}
574 typedef PcpNodeRange RangeType;
581 typedef PcpPrimRange RangeType;
588 typedef PcpPropertyRange RangeType;
592PXR_NAMESPACE_CLOSE_SCOPE
A simple iterator adapter for STL containers.
Object used to iterate over nodes in the prim index graph in strong-to-weak order.
PcpNodeIterator()=default
Constructs an invalid iterator.
PcpNode represents a node in an expression tree for compositing scene description.
Object used to iterate over nodes in the prim index graph in weak-to-strong order.
PcpPrimIndex is an index of the all sites of scene description that contribute opinions to a specific...
Object used to iterate over prim specs in the prim index graph in strong-to-weak order.
PCP_API PcpPrimIterator()
Constructs an invalid iterator.
PCP_API PcpPrimIterator(const PcpPrimIndex *primIndex, size_t pos)
Constructs a prim iterator beginning at position pos in the prim stack of prim index primIndex.
PCP_API PcpNodeRef GetNode() const
Returns the PcpNode from which the current prim originated.
Object used to iterate over prim specs in the prim index graph in weak-to-strong order.
PcpPropertyIndex is an index of all sites in scene description that contribute opinions to a specific...
Object used to iterate over property specs in a property index in strong-to-weak order.
PCP_API PcpPropertyIterator(const PcpPropertyIndex &index, size_t pos=0)
Constructs a property iterator for index beginning at position pos in the property stack.
PCP_API PcpPropertyIterator()
Constructs an invalid iterator.
PCP_API bool IsLocal() const
Returns true if the current property is local to the owning property index's layer stack,...
PCP_API PcpNodeRef GetNode() const
Returns the PcpNode from which the current property originated.
Object used to iterate over property specs in a property index in weak-to-strong order.
An SdfSite is a simple representation of a location in a layer where opinions may possibly be found.
#define TF_DEV_AXIOM(cond)
The same as TF_AXIOM, but compiled only in dev builds.
Traits class for retrieving useful characteristics about one of the Pcp iterator types above.
constexpr size_t PCP_INVALID_INDEX
A value which indicates an invalid index.