HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_WorkItemHolder.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_WORK_ITEM_HOLDER_H__
10 #define __PDG_WORK_ITEM_HOLDER_H__
11 
12 #include "PDG_API.h"
13 
14 #include "PDG_AttributeTypes.h"
15 #include "PDG_DependencyHolder.h"
16 #include "PDG_WorkItemTypes.h"
17 
18 #include <PDGT/PDGT_ValueArgs.h>
19 
20 #include <UT/UT_Map.h>
21 #include <UT/UT_NonCopyable.h>
22 #include <UT/UT_StringHolder.h>
23 
24 class PDG_BatchWorkItem;
25 class PDG_GraphContext;
26 class PDG_Processor;
28 struct PDG_WorkItemOptions;
30 class PDG_WorkItem;
31 
32 class UT_OptionsHolder;
33 class UT_WorkBuffer;
34 
35 /**
36  * Factory object that constructs and validates work items, for use with
37  * onGenerate.. The items are held in the Holder until the callbacks and
38  * committed to the node after the callback returns.
39  *
40  **/
42 {
43 public:
44  /// Enumeration of possible commit result
46  {
47  // Unable to commit work items, either because it was attempted as part
48  // of a non-static generation or a root injection during a cook. At
49  // some point we might lift the restriction for dynamic generation, but
50  // for now we return this. NOT an error - the callback will just continue
51  // on its way
53 
54  // Commit failed due to some sort of actual error
56 
57  // Commit failed due to a cancel - a "success", but we've been
58  // interrupted
60 
61  // Commit completed successfully, the callback can carry on
63 
64  // Commit was not attempted since the item count required to do so was
65  // not reached.
66  eCommitNone
67  };
68 
69 public:
71  PDG_GraphContext* context,
72  PDG_Processor* processor,
73  bool commitable,
74  bool is_static);
76 
78 
79  PDG_WorkItem* addWorkItem(
80  CommitResult& result,
81  UT_WorkBuffer& errors);
82  PDG_WorkItem* addWorkItem(
83  CommitResult& result,
84  const PDG_WorkItemOptions& options,
85  UT_WorkBuffer& errors);
86  PDG_WorkItem* addWorkItem(
87  CommitResult& result,
88  const PDG_WorkItemOptions& options,
89  const PDGT_ValueArgs& extra_args,
90  UT_WorkBuffer& errors);
91 
92  PDG_WorkItem* addWorkItemFromJSONString(
93  CommitResult& result,
94  const UT_StringHolder& json_data,
95  PDG_WorkItem* parent,
96  PDG_AttributeCollision strategy,
97  bool preserve_type,
98  bool preserve_index,
99  bool add_attributes,
100  UT_WorkBuffer& errors);
101  bool addWorkItemArrayFromJSONString(
102  CommitResult& result,
103  PDG_WorkItemArray& work_items,
104  const UT_StringHolder& json_data,
105  PDG_WorkItem* parent,
106  PDG_AttributeCollision strategy,
107  bool preserve_type,
108  bool preserve_index,
109  bool add_attributes,
110  UT_WorkBuffer& errors);
111 
112  PDG_WorkItem* addWorkItemFromDict(
113  CommitResult& result,
114  const UT_OptionsHolder& dict,
115  PDG_WorkItem* parent,
116  PDG_AttributeCollision strategy,
117  bool preserve_type,
118  bool preserve_index,
119  bool add_attributes,
120  UT_WorkBuffer& errors);
121  bool addWorkItemArrayFromDict(
122  CommitResult& result,
123  PDG_WorkItemArray& work_items,
124  const UT_OptionsHolder& dict,
125  PDG_WorkItem* parent,
126  PDG_AttributeCollision strategy,
127  bool preserve_type,
128  bool preserve_index,
129  bool add_attributes,
130  UT_WorkBuffer& errors);
131 
132  PDG_WorkItem* addWorkItemFromJSONFile(
133  CommitResult& result,
134  const UT_StringHolder& file_path,
135  PDG_WorkItem* parent,
136  PDG_AttributeCollision strategy,
137  bool preserve_type,
138  bool preserve_index,
139  bool add_attributes,
140  UT_WorkBuffer& errors);
141  bool addWorkItemArrayFromJSONFile(
142  CommitResult& result,
143  PDG_WorkItemArray& work_items,
144  const UT_StringHolder& file_path,
145  PDG_WorkItem* parent,
146  PDG_AttributeCollision strategy,
147  bool preserve_type,
148  bool preserve_index,
149  bool add_attributes,
150  UT_WorkBuffer& errors);
151 
152  PDG_WorkItem* addWorkItemFromWorkItem(
153  CommitResult& result,
154  const PDG_WorkItem* work_item,
155  PDG_WorkItem* parent,
156  PDG_AttributeCollision strategy,
157  bool preserve_type,
158  bool preserve_index,
159  bool add_attributes,
160  UT_WorkBuffer& errors);
161 
162  const PDG_Processor* node() const
163  { return myProcessor; }
165  { return myAddedWorkItems; }
168  { return myAddedBatchItems; }
170  { return myAllWorkItems; }
172  { return myAllBatchItems; }
173 
174  void addExtraWorkItems(
175  const PDG_WorkItemArray& items);
176 
177  bool isEmpty() const
178  { return myAddedWorkItems.isEmpty(); }
179  bool isCommitable() const
180  { return myIsCommitable; }
181 
182  int commitCount() const
183  { return myCommitCount; }
185  { myCommitCount = count; }
186 
187  bool useNodePriority() const;
188 
189  CommitResult commit();
190 
191  void setExistingWorkItems(
192  const PDG_WorkItemArray& items);
193  void claimAddedWorkItems(
194  PDG_WorkItemPtrArray& work_items,
195  PDG_BatchWorkItemPtrArray& batches);
196 
197 private:
198  PDG_WorkItem* addWorkItemFromSerialization(
199  CommitResult& result,
200  const PDG_WorkItemSerialization& serialization,
201  PDG_WorkItem* parent,
202  PDG_AttributeCollision strategy,
203  bool preserve_type,
204  bool preserve_index,
205  bool add_attributes,
206  UT_WorkBuffer& errors);
207 
208  CommitResult autoCommit();
209  PDG_WorkItem* claimExistingItem(PDG_WorkItem* parent,
210  int index);
211 private:
212  struct ExistingTable
213  {
214  ExistingTable() : myFirstIndex(0) {}
215 
216  int myFirstIndex;
217  PDG_WorkItemArray myWorkItems;
218  };
219 
221 
222  static UT_StringHolder theItemNameAttrib;
223  static UT_StringHolder theItemIdAttrib;
224  static UT_StringHolder theCookedStatusAttrib;
225 
226 private:
227  PDG_WorkItemArray myAllWorkItems;
228  PDG_WorkItemPtrArray myAddedWorkItems;
229 
230  PDG_BatchWorkItemArray myAllBatchItems;
231  PDG_BatchWorkItemPtrArray myAddedBatchItems;
232 
233  ExistingMap myExistingWorkItems;
234 
235  PDG_GraphContext* myContext;
236  PDG_Processor* myProcessor;
237  PDG_WorkItemDataType* myWorkItemDataType;
238 
239  int myCommitCount;
240  bool myIsCommitable;
241  bool myIsStatic;
242  bool myHasExisting;
243 };
244 
245 #endif
const PDG_BatchWorkItemPtrArray & addedBatchItems() const
Unsorted map container.
Definition: UT_Map.h:114
bool isCommitable() const
#define PDG_API
Definition: PDG_API.h:23
**But if you need a result
Definition: thread.h:622
const PDG_WorkItemArray & allWorkItems() const
GLintptr GLsizeiptr GLboolean commit
Definition: glcorearb.h:3363
void setCommitCount(int count)
CommitResult
Enumeration of possible commit result.
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
const PDG_BatchWorkItemArray & allBatchItems() const
GLuint index
Definition: glcorearb.h:786
PDG_AttributeCollision
const PDG_WorkItemPtrArray & addedWorkItems() const
GLint GLsizei count
Definition: glcorearb.h:405