All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
iterator.h
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_USD_PCP_ITERATOR_H
25 #define PXR_USD_PCP_ITERATOR_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/pcp/api.h"
29 #include "pxr/usd/pcp/node.h"
30 
31 #include "pxr/usd/sdf/primSpec.h"
33 #include "pxr/usd/sdf/site.h"
34 
35 #include "pxr/base/tf/iterator.h"
36 
37 #include <boost/iterator/iterator_facade.hpp>
38 #include <boost/iterator/reverse_iterator.hpp>
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
42 class PcpPrimIndex;
43 class PcpPrimIndex_Graph;
44 class PcpPropertyIndex;
45 
52  : public boost::iterator_facade<
53  /* Derived = */ PcpNodeIterator,
54  /* ValueType = */ PcpNodeRef,
55  /* Category = */ boost::random_access_traversal_tag,
56  /* RefType = */ PcpNodeRef
57  >
58 {
59 public:
61  PcpNodeIterator() : _graph(0), _nodeIdx(PCP_INVALID_INDEX) {}
62 
63  // Returns a compressed Sd site. For internal use only.
64  Pcp_CompressedSdSite GetCompressedSdSite(size_t layerIndex) const
65  {
66  return Pcp_CompressedSdSite(_nodeIdx, layerIndex);
67  }
68 
69 private:
70  friend class PcpPrimIndex;
71  PcpNodeIterator(PcpPrimIndex_Graph* graph, size_t nodeIdx) :
72  _graph(graph), _nodeIdx(nodeIdx) {}
73 
74  friend class boost::iterator_core_access;
75 
76  void increment() { ++_nodeIdx; }
77  void decrement() { --_nodeIdx; }
78  void advance(difference_type n) { _nodeIdx += n; }
79  difference_type distance_to(const PcpNodeIterator& other) const {
80  return (difference_type)(other._nodeIdx) - _nodeIdx;
81  }
82  bool equal(const PcpNodeIterator& other) const {
83  return (_graph == other._graph) & (_nodeIdx == other._nodeIdx);
84  }
85  reference dereference() const {
86  return PcpNodeRef(_graph, _nodeIdx);
87  }
88 
89 private:
90  PcpPrimIndex_Graph* _graph;
91  size_t _nodeIdx;
92 };
93 
100  : public boost::reverse_iterator<PcpNodeIterator>
101 {
102 public:
104  explicit PcpNodeReverseIterator(const PcpNodeIterator& iter)
105  : boost::reverse_iterator<PcpNodeIterator>(iter) { }
106 };
107 
114  : public boost::iterator_facade<
115  /* Derived = */ PcpPrimIterator,
116  /* Value = */ SdfSite,
117  /* Category = */ boost::random_access_traversal_tag,
118  /* Ref = */ SdfSite
119  >
120 {
121 public:
123  PCP_API
124  PcpPrimIterator();
125 
128  PCP_API
129  PcpPrimIterator(const PcpPrimIndex* primIndex, size_t pos);
130 
132  PCP_API
133  PcpNodeRef GetNode() const;
134 
135  // Returns the \c Pcp_SdSiteRef from which the current prim originated.
136  // For internal use only.
137  PCP_API
138  Pcp_SdSiteRef _GetSiteRef() const;
139 
140 private:
141  friend class boost::iterator_core_access;
142  PCP_API
143  void increment();
144  PCP_API
145  void decrement();
146  PCP_API
147  void advance(difference_type n);
148  PCP_API
149  difference_type distance_to(const PcpPrimIterator& other) const;
150  PCP_API
151  bool equal(const PcpPrimIterator& other) const;
152  PCP_API
153  reference dereference() const;
154 
155 private:
156  const PcpPrimIndex* _primIndex;
157  size_t _pos;
158 };
159 
166  : public boost::reverse_iterator<PcpPrimIterator>
167 {
168 public:
170  explicit PcpPrimReverseIterator(const PcpPrimIterator& iter)
171  : boost::reverse_iterator<PcpPrimIterator>(iter) { }
172 
173  PcpNodeRef GetNode() const
174  {
175  PcpPrimIterator tmp = base();
176  return (--tmp).GetNode();
177  }
178 
179  Pcp_SdSiteRef _GetSiteRef() const
180  {
181  PcpPrimIterator tmp = base();
182  return (--tmp)._GetSiteRef();
183  }
184 };
185 
192  : public boost::iterator_facade<
193  /* Derived = */ PcpPropertyIterator,
194  /* Value = */ const SdfPropertySpecHandle,
195  /* Category = */ boost::random_access_traversal_tag
196  >
197 {
198 public:
200  PCP_API
202 
205  PCP_API
206  PcpPropertyIterator(const PcpPropertyIndex& index, size_t pos = 0);
207 
209  PCP_API
210  PcpNodeRef GetNode() const;
211 
214  PCP_API
215  bool IsLocal() const;
216 
217 private:
218  friend class boost::iterator_core_access;
219  PCP_API
220  void increment();
221  PCP_API
222  void decrement();
223  PCP_API
224  void advance(difference_type n);
225  PCP_API
226  difference_type distance_to(const PcpPropertyIterator& other) const;
227  PCP_API
228  bool equal(const PcpPropertyIterator& other) const;
229  PCP_API
230  reference dereference() const;
231 
232 private:
233  const PcpPropertyIndex* _propertyIndex;
234  size_t _pos;
235 };
236 
243  : public boost::reverse_iterator<PcpPropertyIterator>
244 {
245 public:
247  explicit PcpPropertyReverseIterator(const PcpPropertyIterator& iter)
248  : boost::reverse_iterator<PcpPropertyIterator>(iter) { }
249 
250  PcpNodeRef GetNode() const
251  {
252  PcpPropertyIterator tmp = base();
253  return (--tmp).GetNode();
254  }
255 
256  bool IsLocal() const
257  {
258  PcpPropertyIterator tmp = base();
259  return (--tmp).IsLocal();
260  }
261 };
262 
263 // Helper macro for defining iterator ranges, which are simply pairs of
264 // iterators denoting the [start, end) of a series of values. These ranges
265 // may be used with TF_FOR_ALL and TF_REVERSE_FOR_ALL.
266 #define PCP_DEFINE_RANGE(Range, Iterator, ReverseIterator) \
267  typedef std::pair<Iterator, Iterator> Range; \
268  \
269  inline Iterator begin(Range &range) { return range.first; } \
270  inline Iterator begin(const Range &range) { return range.first; } \
271  inline Iterator end(Range &range) { return range.second; } \
272  inline Iterator end(const Range &range) { return range.second; } \
273  \
274  template <> \
275  struct Tf_IteratorInterface<Range, false> { \
276  typedef Iterator IteratorType; \
277  static IteratorType Begin(Range &c) { return c.first; } \
278  static IteratorType End(Range &c) { return c.second; } \
279  }; \
280  \
281  template <> \
282  struct Tf_IteratorInterface<const Range, false> { \
283  typedef Iterator IteratorType; \
284  static IteratorType Begin(Range const &c) { return c.first; } \
285  static IteratorType End(Range const &c) { return c.second; } \
286  }; \
287  \
288  template <> \
289  struct Tf_IteratorInterface<Range, true> { \
290  typedef ReverseIterator IteratorType; \
291  static IteratorType Begin(Range &c) \
292  { return IteratorType(c.second); } \
293  static IteratorType End(Range &c) \
294  { return IteratorType(c.first); } \
295  }; \
296  \
297  template <> \
298  struct Tf_IteratorInterface<const Range, true> { \
299  typedef ReverseIterator IteratorType; \
300  static IteratorType Begin(Range const &c) \
301  { return IteratorType(c.second); } \
302  static IteratorType End(Range const &c) \
303  { return IteratorType(c.first); } \
304  }; \
305  \
306  template <> \
307  struct Tf_ShouldIterateOverCopy<Range> : boost::true_type {}; \
308  \
309  template <> \
310  struct Tf_ShouldIterateOverCopy<const Range> : boost::true_type {}
311 
312 PCP_DEFINE_RANGE(PcpNodeRange, PcpNodeIterator, PcpNodeReverseIterator);
313 PCP_DEFINE_RANGE(PcpPrimRange, PcpPrimIterator, PcpPrimReverseIterator);
314 PCP_DEFINE_RANGE(PcpPropertyRange, PcpPropertyIterator,
316 
322 template <class Iterator> struct PcpIteratorTraits;
323 
324 template <>
326 {
327  typedef PcpNodeRange RangeType;
328  typedef PcpNodeReverseIterator ReverseIteratorType;
329 };
330 
331 template <>
333 {
334  typedef PcpPrimRange RangeType;
335  typedef PcpPrimReverseIterator ReverseIteratorType;
336 };
337 
338 template <>
340 {
341  typedef PcpPropertyRange RangeType;
342  typedef PcpPropertyReverseIterator ReverseIteratorType;
343 };
344 
345 PXR_NAMESPACE_CLOSE_SCOPE
346 
347 #endif // PXR_USD_PCP_ITERATOR_H
Object used to iterate over nodes in the prim index graph in weak-to-strong order.
Definition: iterator.h:99
PcpPrimIndex is an index of the all sites of scene description that contribute opinions to a specific...
Definition: primIndex.h:75
A simple iterator adapter for STL containers.
PCP_API PcpNodeRef GetNode() const
Returns the PcpNode from which the current prim originated.
PcpNode represents a node in an expression tree for compositing scene description.
Definition: node.h:67
PCP_API bool IsLocal() const
Returns true if the current property is local to the owning property index&#39;s layer stack...
PCP_API PcpNodeRef GetNode() const
Returns the PcpNode from which the current property originated.
PCP_API PcpPropertyIterator()
Constructs an invalid iterator.
Object used to iterate over nodes in the prim index graph in strong-to-weak order.
Definition: iterator.h:51
PCP_API PcpPrimIterator()
Constructs an invalid iterator.
constexpr size_t PCP_INVALID_INDEX
A value which indicates an invalid index.
Definition: types.h:197
Object used to iterate over prim specs in the prim index graph in weak-to-strong order.
Definition: iterator.h:165
Object used to iterate over prim specs in the prim index graph in strong-to-weak order.
Definition: iterator.h:113
Object used to iterate over property specs in a property index in strong-to-weak order.
Definition: iterator.h:191
Object used to iterate over property specs in a property index in weak-to-strong order.
Definition: iterator.h:242
PcpPropertyIndex is an index of all sites in scene description that contribute opinions to a specific...
Definition: propertyIndex.h:65
PcpNodeIterator()
Constructs an invalid iterator.
Definition: iterator.h:61
Traits class for retrieving useful characteristics about one of the Pcp iterator types above...
Definition: iterator.h:322