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_Include.h"
17 #include <UT/UT_StringArray.h>
18 #include <iterator>
19 
20 class UN_GraphData;
21 
22 
23 // ============================================================================
24 /// Iterator for traversing the given data ID array and
25 /// returning a data handle when the iterator is dereferenced.
26 /// HANDLE - is a class derived from UN_Handle or UN_ConstHandle
27 /// GRAPH_DATA is UN_GraphData class, either const or non-const
28 /// ID_ITERATOR is an underlying iterator to the UN_DataID entries,
29 /// usually UN_Array<ID>, and can be either forward or backward.
30 template <typename HANDLE, typename GRAPH_DATA, typename DATA_ID_ITERATOR>
32 {
33 public:
34  using iterator_category = std::input_iterator_tag;
35  using value_type = HANDLE;
36  using difference_type = std::ptrdiff_t;
37  using pointer = value_type*;
39 
40  /// Constructor for the start iterator of the given data ID array.
41  UN_HandleIterator( GRAPH_DATA *graph_data,
42  const DATA_ID_ITERATOR &data_id_iterator )
43  : myGraphData( graph_data )
44  , myDataIDIterator( data_id_iterator )
45  {}
46 
47  /// @{ Comparison operators.
48  bool operator ==( const UN_HandleIterator &other ) const
49  { return myDataIDIterator == other.myDataIDIterator; }
50  bool operator !=( const UN_HandleIterator &other) const
51  { return myDataIDIterator != other.myDataIDIterator; }
52  /// @}
53 
54  /// Increment operator.
56  {
57  ++myDataIDIterator;
58  return *this;
59  }
60 
61  /// Dereferencing operator, returns the handle to the current data object.
62  HANDLE operator*() const
63  {
64  return handle();
65  }
66 
67  /// Dereferencing operator, returns the handle to the current data object.
68  HANDLE handle() const
69  {
70  return HANDLE( myGraphData, *myDataIDIterator );
71  }
72 
73 private:
74  /// The graph that owns the data objects.
75  GRAPH_DATA * myGraphData;
76 
77  /// The underlying data ID iterator to which to delegate the calls.
78  DATA_ID_ITERATOR myDataIDIterator;
79 };
80 
81 
82 // ============================================================================
83 /// Iterator for traversing two string arrays at the same time.
85 {
86 public:
87  using iterator_category = std::input_iterator_tag;
88  using value_type = std::pair<const UT_StringHolder&,const UT_StringHolder&>;
90  using pointer = value_type*;
92 
94  const UT_StringArray &types,
95  exint current )
96  : myNames( names )
97  , myTypes( types )
98  , myCurrent( current )
99  {
100  UT_ASSERT( names.size() == types.size() );
101  UT_ASSERT( current >= 0 );
102  UT_ASSERT( current <= names.size() ); // curr == size for end iterator
103  }
104 
105 
106  /// Equality comparison operator.
107  bool operator ==( const UN_NameAndTypeIterator &b ) const
108  {
109  return myCurrent == b.myCurrent;
110  }
111 
112  /// Inequality comparison operator.
113  bool operator !=( const UN_NameAndTypeIterator &b ) const
114  {
115  return myCurrent != b.myCurrent;
116  }
117 
118  /// Pre-increment operator.
120  {
121  ++myCurrent;
122  return *this;
123  }
124 
125  /// Returns the current pair of strings (usually name and type).
127  {
128  return myCurrent < myNames.size()
129  ? value_type( name(), type() )
132  }
133 
134  /// Returns the name string.
135  const UT_StringHolder & name() const
136  {
137  return myNames[ myCurrent ];
138  }
139 
140  /// Returns the type string.
141  const UT_StringHolder & type() const
142  {
143  return myTypes[ myCurrent ];
144  }
145 
146 private:
147  /// The arrays the iterator is iterating over, and the current positon.
148  const UT_StringArray & myNames;
149  const UT_StringArray & myTypes;
150  exint myCurrent = 0;
151 };
152 
153 
154 #endif
155 
type
Definition: core.h:556
int64 exint
Definition: SYS_Types.h:125
UN_NameAndTypeIterator(const UT_StringArray &names, const UT_StringArray &types, exint current)
Definition: UN_Iterator.h:93
UN_NameAndTypeIterator & operator++()
Pre-increment operator.
Definition: UN_Iterator.h:119
value_type & reference
Definition: UN_Iterator.h:91
#define UN_API
Definition: UN_API.h:11
exint size() const
Definition: UT_Array.h:667
uint64 value_type
Definition: GA_PrimCompat.h:29
value_type & reference
Definition: UN_Iterator.h:38
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
bool operator==(const UN_HandleIterator &other) const
Comparison operators.
Definition: UN_Iterator.h:48
UN_HandleIterator(GRAPH_DATA *graph_data, const DATA_ID_ITERATOR &data_id_iterator)
Constructor for the start iterator of the given data ID array.
Definition: UN_Iterator.h:41
std::input_iterator_tag iterator_category
Definition: UN_Iterator.h:34
static const UT_StringHolder theEmptyString
value_type * pointer
Definition: UN_Iterator.h:37
std::ptrdiff_t difference_type
Definition: UN_Iterator.h:36
const UT_StringHolder & type() const
Returns the type string.
Definition: UN_Iterator.h:141
GLuint const GLchar * name
Definition: glcorearb.h:786
std::pair< const UT_StringHolder &, const UT_StringHolder & > value_type
Definition: UN_Iterator.h:88
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
bool operator!=(const UN_HandleIterator &other) const
Comparison operators.
Definition: UN_Iterator.h:50
std::input_iterator_tag iterator_category
Definition: UN_Iterator.h:87
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:165
HANDLE operator*() const
Dereferencing operator, returns the handle to the current data object.
Definition: UN_Iterator.h:62
value_type operator*() const
Returns the current pair of strings (usually name and type).
Definition: UN_Iterator.h:126
GLsizei GLenum GLenum * types
Definition: glcorearb.h:2542
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
const UT_StringHolder & name() const
Returns the name string.
Definition: UN_Iterator.h:135
HANDLE handle() const
Dereferencing operator, returns the handle to the current data object.
Definition: UN_Iterator.h:68
value_type * pointer
Definition: UN_Iterator.h:90
UN_HandleIterator & operator++()
Increment operator.
Definition: UN_Iterator.h:55
Iterator for traversing two string arrays at the same time.
Definition: UN_Iterator.h:84