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