HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_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: GA_Iterator.h (GA Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GA_Iterator__
12 #define __GA_Iterator__
13 
14 #include "GA_API.h"
15 #include "GA_IndexMap.h"
16 #include "GA_IteratorState.h"
17 #include "GA_Range.h"
18 #include "GA_Types.h"
19 #include <UT/UT_Assert.h>
20 #include <SYS/SYS_Inline.h>
21 
22 
23 /// @brief Iteration over a range of elements
24 ///
25 /// An iterator is used to iterate over the elements of a given range. All
26 /// state information for the iteration is stored by the iterator, external
27 /// to the range in question. All iterators are constructed rewound, so in
28 /// most cases there is no need for an explicit rewind() call.
30 {
31 public:
32  GA_Iterator();
33  explicit GA_Iterator(const GA_Range &range);
34  /// Ensure safe iteration if elements from the range are deleted during
35  /// traversal.
37  GA_Iterator(const GA_Iterator &iterator);
38  ~GA_Iterator();
39 
40  /// Test to see whether the iterator is valid
41  bool isValid() const { return myRange.isValid(); }
42 
43  /// @{
44  /// Standard operators
45  const GA_Iterator &operator=(const GA_Iterator &src);
46  bool operator==(const GA_Iterator &src) const;
47  bool operator!=(const GA_Iterator &src) const
48  { return !(*this == src); }
49  /// @}
50 
51  /// Query the element type that is being iterated over
53  {
54  return myRange.getOwner();
55  }
56 
57  /// @{
58  /// Query state of the iterator
60  {
61  UT_ASSERT_P(!atEnd());
62  return myCurrent;
63  }
65  {
66  UT_ASSERT_P(!atEnd());
67  return myCurrent;
68  }
69  /// @}
70 
71  /// @{
72  /// Query the ordered index for the current state. Note that this will
73  /// perform a lookup into the index map, which may not be extremely
74  /// efficient.
76  {
77  UT_ASSERT_P(!atEnd());
78  if (myRange.getRTI())
79  {
80  return myRange.getRTI()->getIndexMap().indexFromOffset(myCurrent);
81  }
82  return GA_INVALID_INDEX;
83  }
84  /// @}
85 
86  /// @{
87  /// Standard iterator methods.
88  /// @warning We do not have a post-increment as it would have to
89  /// be written in a side-effect free way that would cause problmse.
90  /// @note All non-default constructors call rewind() already, so an
91  /// explicit call is usually not needed.
92  void rewind();
93  bool atEnd() const { return myCurrent >= myEnd; }
94  void advance()
95  {
96  UT_ASSERT_P(!atEnd());
97  myCurrent++;
98  if (myCurrent == myEnd)
99  {
100  // We hit the end of our cached block, so iterate to the next block
101  myRange.iterateNext(myState, myCurrent, myEnd);
102  }
103  }
104  GA_Iterator &operator++() { advance(); return *this; }
105  /// @}
106 
107  /// Perform a block iteration. The block iteration will provide a
108  /// contiguous block of offsets which can be operated upon in batch.
109  /// Blocks are constrained to occupy a single page, so no block can
110  /// cross a page boundary. Consequently contiguous sequences that
111  /// cross page boundaries are automatically split into multiple blocks.
112  /// The (start, end] range is like Python in that @c start is included
113  /// in the range, but @c end is not. For example:@code
114  /// for (it.rewind(); iterator.blockAdvance(start, end); )
115  /// for (; start < end; ++start)
116  /// operation(start);
117  /// @endcode
118  bool blockAdvance(GA_Offset &start, GA_Offset &end);
119 
120  /// Like blockAdvance, except that the block isn't guaranteed to be
121  /// all within one page. The block is the maximum contiguous block
122  /// returned by the GA_Range.
123  bool fullBlockAdvance(GA_Offset &start, GA_Offset &end);
124 
125 private:
126  GA_Range myRange;
127  GA_IteratorState myState;
128  GA_Offset myCurrent, myEnd; // Block information
129 };
130 
131 static SYS_FORCE_INLINE bool
133 {
134  return iter.atEnd();
135 }
136 static SYS_FORCE_INLINE bool
138 {
139  return iter.atEnd();
140 }
141 static SYS_FORCE_INLINE bool
143 {
144  return !iter.atEnd();
145 }
146 static SYS_FORCE_INLINE bool
148 {
149  return !iter.atEnd();
150 }
151 
152 #endif
GA_Offset operator*() const
Definition: GA_Iterator.h:64
GLenum GLint * range
Definition: glcorearb.h:1925
Iteration over a range of elements.
Definition: GA_Iterator.h:29
bool isValid() const
Test to see whether the iterator is valid.
Definition: GA_Iterator.h:41
GLuint start
Definition: glcorearb.h:475
GA_AttributeOwner getOwner() const
Query the element type that is being iterated over.
Definition: GA_Iterator.h:52
#define GA_API
Definition: GA_API.h:14
GA_Offset getOffset() const
Definition: GA_Iterator.h:59
bool operator!=(const GA_Iterator &src) const
Definition: GA_Iterator.h:47
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_Index getIndex() const
Definition: GA_Iterator.h:75
GA_Size GA_Offset
Definition: GA_Types.h:646
bool atEnd() const
Definition: GA_Iterator.h:93
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
GLuint GLuint end
Definition: glcorearb.h:475
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
GA_Iterator & operator++()
Definition: GA_Iterator.h:104
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:640
GA_AttributeOwner
Definition: GA_Types.h:35
LeafData & operator=(const LeafData &)=delete
#define GA_INVALID_INDEX
Definition: GA_Types.h:686
void advance()
Definition: GA_Iterator.h:94
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542
GLenum src
Definition: glcorearb.h:1793