HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UN_Iterator.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UN_Iterator.h ( UN Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UN_Iterator_h__
13 #define __UN_Iterator_h__
14 
15 #include "UN_API.h"
16 #include "UN_Types.h"
17 #include <UT/UT_Array.h> // for UN_WireArrayPortIterator
18 #include <SYS/SYS_Types.h>
19 #include <iterator>
20 
21 class UN_GraphData;
22 class UN_Node;
23 class UN_Port;
24 class UN_Wire;
25 
26 
27 // ============================================================================
28 /// Iterator for traversing the given data ID array.
29 /// The iterator dereferences as a handle to the data object.
30 /// Used for iterating children of a node, parameters of a node, etc.
31 
32 template <typename HANDLE, typename ID_ARRAY>
34 {
35 public:
36  using iterator_category = std::input_iterator_tag;
37  using value_type = HANDLE;
38  using difference_type = std::ptrdiff_t;
39  using pointer = value_type*;
41 
42  /// Constructor for the start iterator of the given data array.
43  UN_DataArrayIterator( UN_GraphData *graph_data,
44  ID_ARRAY &&data_ids,
45  exint begin = 0 )
46  : myGraphData( graph_data )
47  , myDataIDs( data_ids )
48  , myCurrent( begin )
49  {}
50 
51  /// Constructor for the end iterator.
52  UN_DataArrayIterator( UN_GraphData *graph_data, exint end )
53  : myGraphData( graph_data )
54  , myCurrent( end )
55  {}
56 
57  /// Increment operator.
59  {
60  ++myCurrent;
61  return *this;
62  }
63 
64  /// Comparison operator.
65  bool operator !=( const UN_DataArrayIterator &other ) const
66  {
67  return myCurrent != other.myCurrent
68  || myGraphData != other.myGraphData;
69  }
70 
71  /// Dereferencing operator, returns the handle to the current data object.
72  HANDLE operator*() const
73  {
74  return handle();
75  }
76 
77  /// Returns the handle to the current data object.
78  HANDLE handle() const
79  {
80  return myDataIDs.isValidIndex( myCurrent )
81  ? HANDLE( myGraphData, myDataIDs[ myCurrent ])
82  : HANDLE();
83  }
84 
85 
86 private:
87  /// The graph that owns the data objects.
88  UN_GraphData * myGraphData;
89 
90  /// The ID numbers of the data ojects that are bing iterated over.
91  ID_ARRAY myDataIDs;
92 
93  /// The current data object when iterating.
94  exint myCurrent;
95 };
96 
97 
98 // ============================================================================
99 /// Iterator for traversing the input or the output ports of wire objects
100 /// in the given wire ID array.
101 /// The iterator dereferences as a handle to the port data object.
102 /// Used for iterating connected ports.
103 template <bool IS_SOURCE_ITERATOR>
105  public UN_DataArrayIterator<UN_Wire, UN_WireIDList>
106 {
107 public:
108  using iterator_category = std::input_iterator_tag;
110  using difference_type = std::ptrdiff_t;
111  using pointer = value_type*;
113 
114  /// Constructor for the start iterator of the given data array.
115  UN_WireArrayPortIterator( UN_GraphData *graph_data,
116  UN_WireIDList &&data_ids,
117  exint begin = 0 )
118  : UN_DataArrayIterator<UN_Wire, UN_WireIDList>(
119  graph_data, std::move(data_ids), begin)
120  {}
121 
122  /// Constructor for the end iterator.
123  UN_WireArrayPortIterator( UN_GraphData *graph_data, exint end )
124  : UN_DataArrayIterator<UN_Wire, UN_WireIDList>(
125  graph_data, end )
126  {}
127 
128  /// Dereferencing operator, returns the handle to the connected port
129  /// of the data object.
130  UN_Port operator*() const;
131 };
132 
133 // These are implemented in .C file.
136 
137 
138 // ============================================================================
139 /// Iterator for traversing the node data objects that are arranged in
140 /// a parental tree hierarchy.
141 /// The iterator dereferences as a handle to node data object.
142 /// Used for iterating connected nodes in nested subnetworks.
144 {
145 public:
146  using iterator_category = std::input_iterator_tag;
148  using difference_type = std::ptrdiff_t;
149  using pointer = value_type*;
151 
152  /// Constructor for the start iterator of the given node ancestral tree.
153  UN_NodeDescendantIterator( UN_GraphData *graph_data, UN_NodeID node_id )
154  : myGraphData( graph_data )
155  {
156  pushChild( node_id );
157  }
158 
159  /// Constructor for the end iterator.
160  UN_NodeDescendantIterator( UN_GraphData *graph_data )
161  : myGraphData( graph_data )
162  {}
163 
164  /// Increment operator.
166  {
167  UN_NodeID node_id = popChild();
168  pushChild( node_id );
169  return *this;
170  }
171 
172  /// Comparison operator.
173  bool operator !=( const UN_NodeDescendantIterator &other ) const
174  {
175  // Loops compare iterators only against the 'end' iterator,
176  // which has an empty array, so comparing sizes is enough.
177  return myNodeIDs.size() != other.myNodeIDs.size()
178  || myGraphData != other.myGraphData;
179  }
180 
181  /// Dereferencing operator, returns the handle to the current node data obj.
182  UN_Node operator*() const;
183 
184 
185 private:
186  /// Adds the children of the given node to the stack for traversal.
187  void pushChild( UN_NodeID parent_id );
188 
189  /// Removes and returns the top (the current) child on the traversal stack.
190  UN_NodeID popChild();
191 
192 private:
193  /// The graph that owns the node objects.
194  UN_GraphData * myGraphData;
195 
196  /// The stack of pending node IDs to traverse.
197  UN_NodeIDList myNodeIDs;
198 };
199 
200 
201 // ============================================================================
202 /// Iterator for traversing the wires inside the given node.
203 /// The iterator dereferences as a handle to the wire data object.
204 /// Used for iterating wires inside a node.
205 template <bool CHILD_ONLY>
207 {
208 public:
209  using iterator_category = std::input_iterator_tag;
211  using difference_type = std::ptrdiff_t;
212  using pointer = value_type*;
214 
215  /// Constructor for the start and end iterator for node's wires.
216  UN_NodeWireIterator( UN_GraphData *graph_data, UN_NodeID node_id )
217  : myGraphData( graph_data )
218  {
219  myNodeIDs.append( node_id );
220  advance();
221  }
222 
223  /// Constructor for the end iterator.
224  UN_NodeWireIterator( UN_GraphData *graph_data )
225  : myGraphData( graph_data )
226  {}
227 
228 
229  /// Increment operator.
231  {
232  advance();
233  return *this;
234  }
235 
236  /// Comparison operator.
237  bool operator !=( const UN_NodeWireIterator &other ) const
238  {
239  // Loops compare iterators only against the 'end' iterator,
240  // which has an empty array, so comparing sizes is enough.
241  return myWireIDs.size() != other.myWireIDs.size()
242  || myGraphData != other.myGraphData;
243  }
244 
245  /// Dereferencing operator, returns the handle to the wire inside the node.
246  UN_Wire operator*() const;
247 
248 
249 private:
250  /// Moves to the next wire in the iteration.
251  void advance();
252 
253 private:
254  /// The graph that owns the node objects.
255  UN_GraphData * myGraphData;
256 
257  /// The list of pending wires in the current node to traverse.
258  UN_WireIDList myWireIDs;
259 
260  /// The stack of pending nodes to traverse.
261  UN_NodeIDList myNodeIDs;
262 };
263 
264 
265 
266 #endif
267 
UN_Port operator*() const
bool operator!=(const UN_DataArrayIterator &other) const
Comparison operator.
Definition: UN_Iterator.h:65
UN_NodeWireIterator(UN_GraphData *graph_data)
Constructor for the end iterator.
Definition: UN_Iterator.h:224
UN_NodeDescendantIterator & operator++()
Increment operator.
Definition: UN_Iterator.h:165
UN_DataArrayIterator(UN_GraphData *graph_data, ID_ARRAY &&data_ids, exint begin=0)
Constructor for the start iterator of the given data array.
Definition: UN_Iterator.h:43
int64 exint
Definition: SYS_Types.h:125
std::ptrdiff_t difference_type
Definition: UN_Iterator.h:110
#define UN_API
Definition: UN_API.h:11
UN_NodeWireIterator(UN_GraphData *graph_data, UN_NodeID node_id)
Constructor for the start and end iterator for node's wires.
Definition: UN_Iterator.h:216
UN_DataArrayIterator(UN_GraphData *graph_data, exint end)
Constructor for the end iterator.
Definition: UN_Iterator.h:52
std::input_iterator_tag iterator_category
Definition: UN_Iterator.h:108
std::ptrdiff_t difference_type
Definition: UN_Iterator.h:148
GLuint GLuint end
Definition: glcorearb.h:475
UN_WireArrayPortIterator(UN_GraphData *graph_data, UN_WireIDList &&data_ids, exint begin=0)
Constructor for the start iterator of the given data array.
Definition: UN_Iterator.h:115
IMATH_HOSTDEVICE constexpr Color4< T > operator*(S a, const Color4< T > &v) IMATH_NOEXCEPT
Reverse multiplication: S * Color4.
Definition: ImathColor.h:732
UN_NodeWireIterator & operator++()
Increment operator.
Definition: UN_Iterator.h:230
UN_DataArrayIterator & operator++()
Increment operator.
Definition: UN_Iterator.h:58
UN_NodeDescendantIterator(UN_GraphData *graph_data)
Constructor for the end iterator.
Definition: UN_Iterator.h:160
UN_WireArrayPortIterator(UN_GraphData *graph_data, exint end)
Constructor for the end iterator.
Definition: UN_Iterator.h:123
std::input_iterator_tag iterator_category
Definition: UN_Iterator.h:146
std::ptrdiff_t difference_type
Definition: UN_Iterator.h:211
std::input_iterator_tag iterator_category
Definition: UN_Iterator.h:209
HANDLE operator*() const
Dereferencing operator, returns the handle to the current data object.
Definition: UN_Iterator.h:72
HANDLE handle() const
Returns the handle to the current data object.
Definition: UN_Iterator.h:78
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
UN_NodeDescendantIterator(UN_GraphData *graph_data, UN_NodeID node_id)
Constructor for the start iterator of the given node ancestral tree.
Definition: UN_Iterator.h:153
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.
Definition: node.h:558