HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_WorkItemDirty.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_WORKITEM_DIRTY_H__
10 #define __PDG_WORKITEM_DIRTY_H__
11 
12 #include "PDG_API.h"
13 
14 #include "PDG_File.h"
15 #include "PDG_Types.h"
16 
17 #include <UT/UT_ArrayStringSet.h>
18 
19 class PDG_GraphContext;
20 class PDG_Node;
21 class PDG_WorkItem;
22 
24 {
25 public:
26  /// Enumeration of dirty types
27  enum Type
28  {
29  /// Invalid/uninitialized dirty operation
31 
32  /// Dirty of a single work iem
34 
35  /// Dirty of a single node
37 
38  /// Dirty of the entire graph
39  eDirtyGraph
40  };
41 
42 public:
44  : myContext(nullptr)
45  , myDirtyNode(nullptr)
46  , myDirtyType(eDirtyInvalid)
47  , myEmitGraphEvents(false)
48  , myIsDelete(false) {}
50  PDG_GraphContext* context,
51  bool is_delete,
52  Type dirty_type=eDirtyInvalid)
53  : myContext(context)
54  , myDirtyNode(nullptr)
55  , myDirtyType(dirty_type)
56  , myEmitGraphEvents(false)
57  , myIsDelete(is_delete) {}
59  PDG_GraphContext* context,
60  PDG_Node* node,
61  bool is_delete,
62  bool emit_graph_events)
63  : myContext(context)
64  , myDirtyNode(node)
65  , myDirtyType(eDirtyNode)
66  , myEmitGraphEvents(emit_graph_events)
67  , myIsDelete(is_delete) {}
68 
69  /// Returns the dirty type
70  inline Type dirtyType() const
71  { return myDirtyType; }
72 
73  /// Returns the list of work items marked for deletion
74  inline const PDG_WorkItemConstSet&
75  deleteSet() const
76  { return myDeleteSet; }
77 
78  /// Returns the list of work items marked for deletion
79  inline const PDG_WorkItemConstSet&
80  dirtySet() const
81  { return myDirtySet; }
82 
83  /// Returns the list of files from dirty work items
84  inline const PDG_File::Set&
85  dirtyFiles() const
86  { return myDirtyFiles; }
87 
88  /// Returns the list of files that are prevented from being deleted
89  inline const UT_ArrayStringSet&
90  keepFiles() const
91  { return myKeepFiles; }
92 
93  /// Returns true if the item is marked for deletion
94  inline bool isDeleted(const PDG_WorkItem* work_item) const
95  { return myDeleteSet.contains(work_item); }
96 
97  /// Returns true if the item is marked for any kind of dirtying operation
98  inline bool isDirty(const PDG_WorkItem* work_item) const
99  { return myDirtySet.contains(work_item); }
100 
101  /// Returns true if the data for the work item is dirty
102  bool isDataDirty(const PDG_WorkItem* work_item) const;
103 
104  /// Adds a work item to the dirty set(s)
105  void dirtyWorkItem(
106  const PDG_WorkItem* work_item,
107  bool is_delete);
108 
109  /// Resets this object to a clean state
110  void reset();
111 
112  /// Adds a work item and its dependencies to the dirty sets
113  void prepareDirty(PDG_WorkItem* work_item);
114 
115  /// Adds a node to the pending dirty operation
116  void prepareDirty(
117  PDG_Node* node,
118  bool will_remove_outputs);
119 
120  /// Applies the stored dirty operation
121  void applyDirty(bool remove_outputs);
122 
123  /// Updates the dirty data map for the work item, and returns true if the
124  /// dirtying operaton should proceed. Returns false if no dirtying should
125  /// occur.
126  bool updateDirtyData(
127  const PDG_WorkItem* work_item,
128  bool is_dirty_data);
129 
130  /// Updates the cache ID of the work item for a dependency
131  void updateCacheId(
132  const PDG_WorkItem* dependent,
133  const PDG_WorkItem* dependency);
134 
135  /// Flags a dependency relationship for removal. This is necessary because
136  /// it's possible for only some dependencies of a partition to be deleted
137  /// during a dependency operation, which still leaves the partition behind.
138  /// This method returns true if the removal corresponds to the last entry
139  /// in the partition, which indicates that the partition itself should
140  /// also be deleted
141  bool removeDependency(
142  const PDG_WorkItem* dependent,
143  const PDG_WorkItem* dependency);
144 
145  /// Adds a request to preserve a file, even if the file would normally be
146  /// deleted by a dirty operation.
147  void keepFilePath(const UT_StringHolder& file_path);
148 
149 private:
150  /// Dirties the work items stored in this object
151  void applyWorkItemDirty(bool remove_outputs);
152 
153 private:
154  /// Enumeration of dirty state states
155  enum class DirtyData
156  {
157  eUnset,
158  eClean,
159  eDirty
160  };
161 
162  /// Helper struct that stores information about a work item that
163  /// will be dirtied, but not deleted
164  struct DirtyInfo
165  {
166  DirtyInfo()
167  : myCacheId(-1)
168  , myDataDirty(DirtyData::eUnset) {}
169 
170  PDG_WorkItemConstSet myDependencies;
171  int myCacheId;
172  DirtyData myDataDirty;
173  };
174  using DirtyInfoMap = UT_Map<const PDG_WorkItem*, DirtyInfo>;
175 
176 private:
177  PDG_WorkItemConstSet myDeleteSet;
178  PDG_WorkItemConstSet myDirtySet;
179  DirtyInfoMap myDirtyInfoMap;
180 
181  PDG_File::Set myDirtyFiles;
182  UT_ArrayStringSet myKeepFiles;
183 
184  PDG_GraphContext* myContext;
185  PDG_Node* myDirtyNode;
186  Type myDirtyType;
187 
188  bool myIsDelete;
189  bool myEmitGraphEvents;
190 };
191 
192 #endif
const PDG_File::Set & dirtyFiles() const
Returns the list of files from dirty work items.
bool isDeleted(const PDG_WorkItem *work_item) const
Returns true if the item is marked for deletion.
const PDG_WorkItemConstSet & deleteSet() const
Returns the list of work items marked for deletion.
#define PDG_API
Definition: PDG_API.h:23
const UT_ArrayStringSet & keepFiles() const
Returns the list of files that are prevented from being deleted.
const PDG_WorkItemConstSet & dirtySet() const
Returns the list of work items marked for deletion.
GLboolean reset
Definition: glad.h:5138
Type dirtyType() const
Returns the dirty type.
PDG_WorkItemDirty(PDG_GraphContext *context, bool is_delete, Type dirty_type=eDirtyInvalid)
Type
Enumeration of dirty types.
Dirty of a single node.
bool isDirty(const PDG_WorkItem *work_item) const
Returns true if the item is marked for any kind of dirtying operation.
Invalid/uninitialized dirty operation.
Dirty of a single work iem.
PDG_WorkItemDirty(PDG_GraphContext *context, PDG_Node *node, bool is_delete, bool emit_graph_events)