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_Types.h"
14 
15 #include <UT/UT_ArrayMap.h>
16 #include <UT/UT_Map.h>
17 #include <UT/UT_StringMap.h>
18 #include <UT/UT_WorkBuffer.h>
19 
20 class PDG_WorkItem;
21 
22 /**
23  * Factory/holder object that creates or updates partitions
24  */
26 {
27 public:
29 
30 public:
31  /// Constructs a new partition holder
33 
34  /// Adds a work item to the partition with the specified index
35  bool addItemToPartition(
36  PDG_WorkItem* work_item,
37  int index,
38  bool required,
39  UT_WorkBuffer& errors);
40 
41  /// Adds a work item to the partition with the specified name
42  bool addItemToPartition(
43  PDG_WorkItem* work_item,
44  const UT_StringHolder& name,
45  bool required,
46  UT_WorkBuffer& errors);
47 
48  /// Adds a work item to all partitions, without having to know the indices
49  /// or number of partitions that exist
50  void addItemToAllPartitions(PDG_WorkItem* work_item);
51 
52  /// Sets the frame for the partition with the given index.
53  void setPartitionFrame(
54  int index,
55  OptionalFrame frame);
56 
57  /// Sets the frame for the partition with the given name
58  void setPartitionFrame(
59  const UT_StringHolder& name,
60  OptionalFrame frame);
61 
62  /// Returns the partition map
63  const IndexMap& partitions() const
64  { return myPartitions; }
65 
66  /// Returns the items that should be marked as required for each partition
67  const IndexMap& required() const
68  { return myRequiredMap; }
69 
70  /// Returns the all set, e.g. the set of items that should be added to all
71  /// partitions
72  const PDG_WorkItemSet& allSet() const
73  { return myAllSet; }
74 
75 
76  /// Returns the current max index of all partitions added to the holder
77  int maxIndex() const
78  { return myMaxIndex; }
79 
80  /// Returns the number of partitions added to the holder. This is reset
81  /// after setSplitValue is called.
82  int numPartitions() const
83  { return myNumPartitions; }
84 
85  /// Returns the split attribute name
87  { return mySplitAttrib; }
88 
89  /// Returns the current split attribute value
90  const UT_StringHolder& splitValue() const
91  { return mySplitValue; }
92 
93  /// Returns true if this holder is being used for partitioning with a
94  /// split attribute.
95  bool isSplitting() const
96  { return myIsSplitting; }
97 
98  /// Returns the array of work items that are missing the split attribute,
99  /// or nullptr if isSplitting() returns false;
101  { return mySplitMissing; }
103  { return mySplitMissing; }
104 
105  /// Return the frame specified for the partition with the given index
106  OptionalFrame frameForPartition(int index) const;
107 
108  /// Returns true if the holder only consists of entries in the All Set.
109  bool isAllSetOnly() const;
110 
111  /// Sets the global split attribute information for this holder. Called
112  /// once during partitioning with a split attribute.
113  void setSplitInfo(const UT_StringHolder& name);
114 
115  /// Sets the local split attribute information for this holder. Called
116  /// once for each split attribute value during partitioning.
117  void setSplitValue(const UT_StringHolder& value,
118  int index_offset);
119 
120  /// Converts named partitions into real partitions
121  void resolveNames();
122 
123 private:
124  using IndexFrameMap = UT_Map<int, OptionalFrame>;
125  using StringFrameMap = UT_StringMap<OptionalFrame>;
127 
128  IndexMap myPartitions;
129  IndexMap myRequiredMap;
130  IndexFrameMap myFrameMap;
131 
132  StringMap myNamedPartitions;
133  StringMap myNamedRequiredMap;
134  StringFrameMap myNamedFrameMap;
135 
136  PDG_WorkItemSet myAllSet;
137  PDG_WorkItemArray mySplitMissing;
138 
139  UT_StringHolder mySplitAttrib;
140  UT_StringHolder mySplitValue;
141  int myMaxIndex;
142  int myIndexOffset;
143  int myNumPartitions;
144  bool myIsSplitting;
145 };
146 
147 #endif
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 > OptionalFrame
Definition: PDG_Types.h:86
const UT_StringHolder & splitAttribute() const
Returns the split attribute name.
const PDG_WorkItemArray & splitMissing() const
GLuint const GLchar * name
Definition: glcorearb.h:786
const PDG_WorkItemSet & 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.
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