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; }
167  { return myAddedBatchItems; }
169  { return myAllWorkItems; }
171  { return myAllBatchItems; }
172 
173  void addExtraWorkItems(
174  const PDG_WorkItemArray& items);
175 
176  bool isEmpty() const
177  { return myAddedWorkItems.isEmpty(); }
178  bool isCommitable() const
179  { return myIsCommitable; }
180 
181  int commitCount() const
182  { return myCommitCount; }
184  { myCommitCount = count; }
185 
186  bool useNodePriority() const;
187 
188  CommitResult commit();
189  void clearAddedItems(bool delete_items);
190  void setExistingItems(
191  const PDG_WorkItemArray& items);
192 
193 private:
194  PDG_WorkItem* addWorkItemFromSerialization(
195  CommitResult& result,
196  const PDG_WorkItemSerialization& serialization,
197  PDG_WorkItem* parent,
198  PDG_AttributeCollision strategy,
199  bool preserve_type,
200  bool preserve_index,
201  bool add_attributes,
202  UT_WorkBuffer& errors);
203 
204  CommitResult autoCommit();
205  PDG_WorkItem* claimExistingItem(PDG_WorkItem* parent,
206  int index);
207 private:
208  struct ExistingTable
209  {
210  ExistingTable() : myFirstIndex(0) {}
211 
212  int myFirstIndex;
213  PDG_WorkItemArray myWorkItems;
214  };
215 
217 
218  static UT_StringHolder theItemNameAttrib;
219  static UT_StringHolder theItemIdAttrib;
220  static UT_StringHolder theCookedStatusAttrib;
221 
222 private:
223  PDG_WorkItemArray myAllWorkItems;
224  PDG_WorkItemArray myAddedWorkItems;
225 
226  PDG_BatchWorkItemSet myAllBatchItems;
227  PDG_BatchWorkItemSet myAddedBatchItems;
228 
229  ExistingMap myExistingWorkItems;
230 
231  PDG_GraphContext* myContext;
232  PDG_Processor* myProcessor;
233  PDG_WorkItemDataType* myWorkItemDataType;
234 
235  int myCommitCount;
236  bool myIsCommitable;
237  bool myIsStatic;
238  bool myHasExisting;
239 };
240 
241 #endif
Unsorted map container.
Definition: UT_Map.h:107
const PDG_BatchWorkItemSet & addedBatchItems() const
bool isCommitable() const
#define PDG_API
Definition: PDG_API.h:23
const PDG_BatchWorkItemSet & allBatchItems() const
**But if you need a result
Definition: thread.h:613
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.
GLuint index
Definition: glcorearb.h:786
PDG_AttributeCollision
GLint GLsizei count
Definition: glcorearb.h:405
const PDG_WorkItemArray & addedWorkItems() const