HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_PageIterator.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_PageIterator.h ( GA Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GA_PageIterator__
12 #define __GA_PageIterator__
13 
14 #include "GA_API.h"
15 #include "GA_Iterator.h"
16 #include "GA_Range.h"
17 #include "GA_SplittableRange.h"
18 #include "GA_Types.h"
19 
21 
22 #include <stddef.h>
23 
24 
26 {
27 public:
29  const UT_JobInfo *jobinfo=NULL)
30  : myRange(range)
31  , myJobInfo(jobinfo)
32  , myCurr(0)
33  , myPageCount(range.getPageCount())
34  , myEndIterator(false)
35  {
36  if (myJobInfo)
37  myCurr = myJobInfo->nextTask();
38  }
40  : myRange(pit.myRange)
41  , myJobInfo(pit.myJobInfo)
42  , myCurr(pit.myCurr)
43  , myPageCount(pit.myPageCount)
44  , myEndIterator(pit.myEndIterator)
45  {
46  }
48 
49  /// Assignment operator
51  {
52  myRange = src.myRange;
53  myJobInfo = src.myJobInfo;
54  myCurr = src.myCurr;
55  myPageCount = src.myPageCount;
56  myEndIterator = src.myEndIterator;
57  return *this;
58  }
59  /// Equality operator
60  bool operator==(const GA_PageIterator &src) const
61  {
62  if (myEndIterator || src.myEndIterator)
63  return atEnd() && src.atEnd();
64  return myRange == src.myRange &&
65  myJobInfo == src.myJobInfo &&
66  myCurr == src.myCurr &&
67  myPageCount == src.myPageCount;
68  }
69  bool operator!=(const GA_PageIterator &src) const
70  { return !(*this == src); }
71 
72  /// @{
73  /// Return the offset for the beginning of the current page
75  {
76  return myRange.getFirstOffsetInPage(myCurr);
77  }
78  GA_Offset operator*() const { return getFirstOffsetInPage(); }
79  /// @}
80 
81  /// @{
82  /// Iterator interface
83  /// @warning The post-increment operator has a side-effect since the value
84  /// returned is the iterator @b after the increment (not before)
85  void rewind() { myCurr = 0; }
86  bool atEnd() const { return myCurr >= myPageCount; }
87  void advance()
88  {
89  if (myJobInfo)
90  myCurr = myJobInfo->nextTask();
91  else
92  myCurr++;
93  }
94  GA_PageIterator &operator++() { advance(); return *this; }
95  // No post inc as it is harmful.
96  /// @}
97 
98  /// @{
99  /// Begin iterating over the offsets in a page
100  GA_Iterator begin() const { return GA_Iterator(
101  myRange.getPageElementRange(myCurr)); }
102  GA_Iterator end() const { return myRange.end(); }
103  /// @}
104 private:
105  bool isEnd() const { return myEndIterator || atEnd(); }
106 
107  GA_SplittableRange myRange;
108  const UT_JobInfo *myJobInfo;
109  GA_Size myCurr, myPageCount;
110  bool myEndIterator;
111 };
112 
113 /// Define macros roughly equivalent to FOR_INFOTASKS (in
114 /// UT_ThreadedAlgorithm). This will break up the full range into a load
115 /// balanced iteration over pages. For example:
116 /// GA_FOR_INFOTASKS(info, gdp->getPointRange(), it)
117 /// {
118 /// doSomething(it.getOrder()); // Use point number
119 /// doSomething(it.getOffset()); // Use point offset
120 /// }
121 #define GA_FOR_INFORANGE(info, full_range, IT_NAME) \
122  GA_SplittableRange lcl_prange(full_range); \
123  for (GA_PageIterator pit=lcl_prange.beginPages(info); \
124  !pit.atEnd(); ++pit) \
125  for (GA_Iterator IT_NAME = pit.begin(); !IT_NAME.atEnd(); ++IT_NAME)
126 
127 /// Like FOR_INFOTASKS_BOSS, iterate with an optional opInterrupt for every
128 /// block completed.
129 #define GA_FOR_INFORANGE_BOSS(info, full_range, IT_NAME, boss) \
130  GA_SplittableRange lcl_prange(full_range); \
131  for (GA_PageIterator pit=lcl_prange.beginPages(info); \
132  !pit.atEnd() && !boss->opInterrupt(); ++pit) \
133  for (GA_Iterator IT_NAME = pit.begin(); !IT_NAME.atEnd(); ++IT_NAME)
134 
135 /// Iterate over all points for the given info
136 #define GA_FOR_INFO_ALLPOINTS(gdp, info, IT_NAME) \
137  GA_SplittableRange lcl_prange(gdp->getPointRange()); \
138  for (GA_PageIterator pit=lcl_prange.beginPages(info); \
139  !pit.atEnd(); ++pit) \
140  for (GA_Iterator IT_NAME = pit.begin(); !IT_NAME.atEnd(); ++IT_NAME)
141 
142 /// Iterate over all points for the given info with a UT_Interrupt
143 #define GA_FOR_INFO_ALLPOINTS_BOSS(gdp, info, IT_NAME, boss) \
144  GA_SplittableRange lcl_prange(gdp->getPointRange()); \
145  for (GA_PageIterator pit=lcl_prange.beginPages(info); \
146  !pit.atEnd() && !boss->opInterrupt(); ++pit) \
147  for (GA_Iterator IT_NAME = pit.begin(); !IT_NAME.atEnd(); ++IT_NAME)
148 
149 
150 /// Iterate over all points for the given info with a UT_Interrupt
151 #define GA_FOR_INFO_GROUP_POINTS_BOSS(gdp, pointgrp, info, IT_NAME, boss) \
152  GA_SplittableRange lcl_prange(gdp->getPointRange(pointgrp)); \
153  for (GA_PageIterator pit=lcl_prange.beginPages(info); \
154  !pit.atEnd() && !boss->opInterrupt(); ++pit) \
155  for (GA_Iterator IT_NAME = pit.begin(); !IT_NAME.atEnd(); ++IT_NAME)
156 
157 
158 #endif
GLenum GLint * range
Definition: glcorearb.h:1924
GA_PageIterator(const GA_PageIterator &pit)
Iteration over a range of elements.
Definition: GA_Iterator.h:28
GA_PageIterator & operator=(const GA_PageIterator &src)
Assignment operator.
#define GA_API
Definition: GA_API.h:12
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
GA_Iterator end() const
GA_Size GA_Offset
Definition: GA_Types.h:617
GA_Offset getFirstOffsetInPage() const
bool atEnd() const
GA_Offset operator*() const
bool operator!=(const GA_PageIterator &src) const
GA_PageIterator(const GA_SplittableRange &range, const UT_JobInfo *jobinfo=NULL)
GA_Iterator begin() const
bool operator==(const GA_PageIterator &src) const
Equality operator.
GA_PageIterator & operator++()
GLenum src
Definition: glcorearb.h:1792