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_DependencyHolder.h"
15 #include "PDG_Types.h"
16 
17 #include <PDGT/PDGT_ValueArgs.h>
18 
19 #include <UT/UT_NonCopyable.h>
20 #include <UT/UT_StringHolder.h>
21 
22 class PDG_BatchWorkItem;
23 class PDG_GraphContext;
24 class PDG_Processor;
26 struct PDG_WorkItemOptions;
28 class PDG_WorkItem;
29 
30 class UT_WorkBuffer;
31 
32 /**
33  * Factory object that constructs and validates work items, for use with
34  * onGenerate.. The items are held in the Holder until the callbacks and
35  * committed to the node after the callback returns.
36  *
37  **/
39 {
40 public:
41  /// Enumeration of possible commit result
43  {
44  // Unable to commit work items, either because it was attempted as part
45  // of a non-static generation or a root injection during a cook. At
46  // some point we might lift the restriction for dynamic generation, but
47  // for now we return this. NOT an error - the callback will just continue
48  // on its way
50 
51  // Commit failed due to some sort of actual error
53 
54  // Commit failed due to a cancel - a "success", but we've been
55  // interrupted
57 
58  // Commit completed successfully, the callback can carry on
60 
61  // Commit was not attempted since the item count required to do so was
62  // not reached.
63  eCommitNone
64  };
65 
66 public:
68  PDG_GraphContext* context,
69  PDG_Processor* processor,
70  PDG_WorkItem* upstream_item,
71  bool commitable,
72  bool is_static);
74 
76 
77  PDG_WorkItem* addWorkItem(
78  CommitResult& result,
79  UT_WorkBuffer& errors);
80  PDG_WorkItem* addWorkItem(
81  CommitResult& result,
82  const PDG_WorkItemOptions& options,
83  UT_WorkBuffer& errors);
84  PDG_WorkItem* addWorkItem(
85  CommitResult& result,
86  const PDG_WorkItemOptions& options,
87  const PDGT_ValueArgs& extra_args,
88  UT_WorkBuffer& errors);
89 
90  PDG_WorkItem* addWorkItemFromJSONString(
91  CommitResult& result,
92  const UT_StringHolder& json_data,
93  PDG_WorkItem* parent,
94  PDG_AttributeCollision strategy,
95  bool preserve_type,
96  bool preserve_index,
97  bool add_attributes,
98  UT_WorkBuffer& errors);
99  bool addWorkItemArrayFromJSONString(
100  CommitResult& result,
101  PDG_WorkItemArray& work_items,
102  const UT_StringHolder& json_data,
103  PDG_WorkItem* parent,
104  PDG_AttributeCollision strategy,
105  bool preserve_type,
106  bool preserve_index,
107  bool add_attributes,
108  UT_WorkBuffer& errors);
109 
110  PDG_WorkItem* addWorkItemFromJSONFile(
111  CommitResult& result,
112  const UT_StringHolder& file_path,
113  PDG_WorkItem* parent,
114  PDG_AttributeCollision strategy,
115  bool preserve_type,
116  bool preserve_index,
117  bool add_attributes,
118  UT_WorkBuffer& errors);
119  bool addWorkItemArrayFromJSONFile(
120  CommitResult& result,
121  PDG_WorkItemArray& work_items,
122  const UT_StringHolder& file_path,
123  PDG_WorkItem* parent,
124  PDG_AttributeCollision strategy,
125  bool preserve_type,
126  bool preserve_index,
127  bool add_attributes,
128  UT_WorkBuffer& errors);
129 
130  PDG_WorkItem* addWorkItemFromWorkItem(
131  CommitResult& result,
132  const PDG_WorkItem* work_item,
133  PDG_WorkItem* parent,
134  PDG_AttributeCollision strategy,
135  bool preserve_type,
136  bool preserve_index,
137  bool add_attributes,
138  UT_WorkBuffer& errors);
139 
140  const PDG_Processor* node() const
141  { return myProcessor; }
143  { return myAddedWorkItems; }
145  { return myAddedBatchItems; }
147  { return myAllWorkItems; }
149  { return myAllBatchItems; }
150 
151  void addExtraWorkItems(
152  const PDG_WorkItemArray& items);
153 
154  bool isEmpty() const
155  { return myAddedWorkItems.isEmpty(); }
156  bool isCommitable() const
157  { return myIsCommitable; }
158 
159  int commitCount() const
160  { return myCommitCount; }
162  { myCommitCount = count; }
163 
164  bool useNodePriority() const;
165 
166  CommitResult commit();
167  void clearAddedItems(bool delete_items);
168  void setExistingItems(
169  const PDG_WorkItemArray& items);
170 
171 private:
172  PDG_WorkItem* addWorkItemFromJSON(
173  CommitResult& result,
174  const PDG_WorkItemSerialization& serialization,
175  PDG_WorkItem* parent,
176  PDG_AttributeCollision strategy,
177  bool preserve_type,
178  bool preserve_index,
179  bool add_attributes,
180  UT_WorkBuffer& errors);
181 
182  CommitResult autoCommit();
183  PDG_WorkItem* claimExistingItem(PDG_WorkItem* parent,
184  int index);
185 private:
186  struct ExistingTable
187  {
188  ExistingTable() : myFirstIndex(0) {}
189 
190  int myFirstIndex;
191  PDG_WorkItemArray myWorkItems;
192  };
193 
195 
196  static UT_StringHolder theItemNameAttrib;
197  static UT_StringHolder theItemIdAttrib;
198  static UT_StringHolder theCookedStatusAttrib;
199 
200 private:
201  PDG_WorkItemArray myAllWorkItems;
202  PDG_WorkItemArray myAddedWorkItems;
203 
204  PDG_BatchWorkItemSet myAllBatchItems;
205  PDG_BatchWorkItemSet myAddedBatchItems;
206 
207  ExistingMap myExistingWorkItems;
208 
209  PDG_GraphContext* myContext;
210  PDG_Processor* myProcessor;
211  PDG_WorkItem* myUpstreamItem;
212  PDG_WorkItemDataType* myWorkItemDataType;
213 
214  int myCommitCount;
215  bool myIsCommitable;
216  bool myIsStatic;
217  bool myHasExisting;
218 };
219 
220 #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.
PDG_AttributeCollision
Definition: PDG_Types.h:528
GLuint index
Definition: glcorearb.h:786
#define const
Definition: zconf.h:214
GLint GLsizei count
Definition: glcorearb.h:405
const PDG_WorkItemArray & addedWorkItems() const