HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_PartitionHolder.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  * COMMENTS:
7  */
8 
9 #ifndef PDG_PARTITION_HOLDER
10 #define PDG_PARTITION_HOLDER
11 
12 #include "PDG_API.h"
13 #include "PDG_WorkItemTypes.h"
14 
15 #include <UT/UT_ArrayMap.h>
16 #include <UT/UT_ArrayStringMap.h>
17 #include <UT/UT_WorkBuffer.h>
18 
19 class PDG_WorkItem;
20 
21 /**
22  * Factory/holder object that creates or updates partitions
23  */
25 {
26 public:
28 
29 public:
30  /// Constructs a new partition holder with a list of valid work items
32  const PDG_WorkItemArray& work_item);
33 
34  /// Adds a work item to the partition with the specified index
35  bool addItemToPartition(
36  PDG_WorkItemID id,
37  int index,
38  bool required,
39  UT_WorkBuffer& errors);
40 
41  /// Adds a work item to the partition with the specified index
42  bool addItemToPartition(
43  PDG_WorkItem* work_item,
44  int index,
45  bool required,
46  UT_WorkBuffer& errors);
47 
48  /// Adds a work item to the partition with the specified name
49  bool addItemToPartition(
50  PDG_WorkItem* work_item,
51  const UT_StringHolder& name,
52  bool required,
53  UT_WorkBuffer& errors);
54 
55  /// Adds a work item to all partitions, without having to know the indices
56  /// or number of partitions that exist
57  bool addItemToAllPartitions(
58  PDG_WorkItem* work_item,
59  UT_WorkBuffer& errors);
60 
61  /// Sets the frame for the partition with the given index.
62  void setPartitionFrame(
63  int index,
64  fpreal frame);
65 
66  /// Sets the frame for the partition with the given name
67  void setPartitionFrame(
68  const UT_StringHolder& name,
69  fpreal frame);
70 
71  /// Returns the partition map
72  const IndexMap& partitions() const
73  { return myPartitions; }
74 
75  /// Returns the items that should be marked as required for each partition
76  const IndexMap& required() const
77  { return myRequiredMap; }
78 
79  /// Returns the all set, e.g. the set of items that should be added to all
80  /// partitions
81  const PDG_WorkItemIDSet& allSet() const
82  { return myAllSet; }
83 
84 
85  /// Returns the current max index of all partitions added to the holder
86  int maxIndex() const
87  { return myMaxIndex; }
88 
89  /// Returns the number of partitions added to the holder. This is reset
90  /// after setSplitValue is called.
91  int numPartitions() const
92  { return myNumPartitions; }
93 
94  /// Returns the split attribute name
96  { return mySplitAttrib; }
97 
98  /// Returns the current split attribute value
99  const UT_StringHolder& splitValue() const
100  { return mySplitValue; }
101 
102  /// Returns true if this holder is being used for partitioning with a
103  /// split attribute.
104  bool isSplitting() const
105  { return myIsSplitting; }
106 
107  /// Returns the array of work items that are missing the split attribute,
108  /// or nullptr if isSplitting() returns false;
110  { return mySplitMissing; }
112  { return mySplitMissing; }
113 
114  /// Returns the input work item for the specifed ID, or null if the ID
115  /// is not a valid input
117  {
118  auto&& iter = myWorkItemMap.find(id);
119  if (iter == myWorkItemMap.end())
120  return nullptr;
121 
122  return iter->second;
123  }
124 
125  /// Return the frame specified for the partition with the given index
126  PDG_OptionalFrame frameForPartition(int index) const;
127 
128  /// Returns true if the holder only consists of entries in the All Set.
129  bool isAllSetOnly() const;
130 
131  /// Sets the global split attribute information for this holder. Called
132  /// once during partitioning with a split attribute.
133  void setSplitInfo(const UT_StringHolder& name);
134 
135  /// Sets the local split attribute information for this holder. Called
136  /// once for each split attribute value during partitioning.
137  void setSplitValue(const UT_StringHolder& value,
138  int index_offset);
139 
140  /// Converts named partitions into real partitions
141  void resolveNames();
142 
143  /// Determines the loop stack work item for a set of work item IDs, and
144  /// returns false if the IDs don't form a valid partition for a loop.
145  bool checkLoop(
146  UT_WorkBuffer& errors,
147  const PDG_WorkItemIDSet& ids,
148  PDG_WorkItem** current_item,
149  bool check_all) const;
150 
151  /// Determines the loop stack work item for a list of work items, and
152  /// return false if the items don't form a valid partition for a loop
153  bool checkLoop(
154  UT_WorkBuffer& errors,
155  const PDG_WorkItemArray& work_items,
156  PDG_WorkItem** current_item) const;
157 
158 private:
159  bool validForLoop(
160  UT_WorkBuffer& errors,
161  PDG_WorkItem* work_item,
162  PDG_WorkItem** current_item,
163  int* current_size) const;
164  bool validForLoop(
165  UT_WorkBuffer& errors,
166  const PDG_WorkItemIDSet& ids,
167  PDG_WorkItem** current_item,
168  int* current_size) const;
169 
170 private:
171  using IndexFrameMap = UT_ArrayMap<int, fpreal>;
172  using StringFrameMap = UT_ArrayStringMap<fpreal>;
174 
175  IndexMap myPartitions;
176  IndexMap myRequiredMap;
177  IndexFrameMap myFrameMap;
178 
179  StringMap myNamedPartitions;
180  StringMap myNamedRequiredMap;
181  StringFrameMap myNamedFrameMap;
182 
183  PDG_WorkItemIDSet myAllSet;
184  PDG_WorkItemArray mySplitMissing;
185 
186  PDG_WorkItemIDMap myWorkItemMap;
187 
188  UT_StringHolder mySplitAttrib;
189  UT_StringHolder mySplitValue;
190 
191  int myMaxIndex;
192  int myIndexOffset;
193  int myNumPartitions;
194 
195  bool myIsSplitting;
196  bool myHasLoopInputs;
197 };
198 
199 #endif
exint PDG_WorkItemID
Type defs for unique work item IDs.
PDG_WorkItemArray & splitMissing()
#define PDG_API
Definition: PDG_API.h:23
int maxIndex() const
Returns the current max index of all partitions added to the holder.
UT_Optional< fpreal > PDG_OptionalFrame
Optional frame value, used when constructing work items and partitions.
const UT_StringHolder & splitAttribute() const
Returns the split attribute name.
PDG_WorkItem * partitionInput(PDG_WorkItemID id) const
const PDG_WorkItemArray & splitMissing() const
GLuint const GLchar * name
Definition: glcorearb.h:786
const PDG_WorkItemIDSet & allSet() const
const IndexMap & required() const
Returns the items that should be marked as required for each partition.
const UT_StringHolder & splitValue() const
Returns the current split attribute value.
fpreal64 fpreal
Definition: SYS_Types.h:277
GLuint index
Definition: glcorearb.h:786
const IndexMap & partitions() const
Returns the partition map.
std::unordered_map< string, string > StringMap
An unordered map with strings as both keys and values.
Definition: Library.h:59
Definition: core.h:1131
GLuint * ids
Definition: glcorearb.h:652