HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_AttributeMerge.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_ATTRIBUTE_MERGE_H__
10 #define __PDG_ATTRIBUTE_MERGE_H__
11 
12 #include "PDG_API.h"
13 
14 #include "PDG_AttributeMap.h"
15 #include "PDG_AttributePattern.h"
16 #include "PDG_AttributeTypes.h"
17 #include "PDG_Types.h"
18 
19 #include <UT/UT_Array.h>
20 #include <UT/UT_ArrayStringSet.h>
21 #include <UT/UT_NonCopyable.h>
22 #include <UT/UT_StringMap.h>
23 #include <UT/UT_UniquePtr.h>
24 #include <UT/UT_VectorTypes.h>
25 
26 #include <utility>
27 
28 class PDG_Node;
29 
30 /**
31  * Utility class for merging work item attributes. Stores a list of patterns
32  * and operations that determine how attributes should be merged. The array
33  * order determines the order the patterns are applied.
34  */
36 {
37 public:
38  /// Enumeration of types of data types to merge
40  {
41  /// Merge operation should include regular attributes, which are all
42  /// attributes except for inputs and outputs.
43  eAttribRegular = 0x01,
44 
45  /// Merge operation should copy incoming output files to the dest
46  /// map's input file attrib
47  eAttribInput = 0x02,
48 
49  /// Merge operation should copy incoming output files to the dest
50  /// map's output file attrib
51  eAttribOutput = 0x04,
52 
53  /// Convenience value for merging all attribute types
54  eAttribAll = 0x07
55  };
56 
57  /// Enumeration of different flatten operations, which determines if the
58  /// dynamic and static attribute maps of the source should be combined.
60  {
61  /// Never flatten the attribute maps
63 
64  /// Always flatten the attribute maps
66 
67  /// Use the context runtime state to determine if the maps should be
68  /// flattened
69  eAttribFlattenContext
70  };
71 
72  /// Merge pattern entry consisting of a pattern and merge operation, used
73  /// for filtering attributes
75  {
76  explicit MergeData(PDG_AttributeMergeOp merge_op)
77  : myMergeOp(merge_op)
78  , myPreserveArray(false)
79  {
80  }
81 
83  PDG_AttributeMergeOp merge_op,
84  bool preserve_array)
85  : myPattern(pattern)
86  , myMergeOp(merge_op)
87  , myPreserveArray(preserve_array)
88  {
89  }
90 
94  };
95 
96  /// A collection of merge patterns
98 
99  /// The default, empty merge pattern
100  static const Pattern theEmptyPattern;
101 
102 public:
103  /// Constructs a new attribute merge operation from the specified
104  /// merge types, operation and is_deep flag
106  int attribute_types,
107  const Pattern& pattern=theEmptyPattern,
108  bool is_deep=false);
109 
110  /// Returns the attribute type filter
111  inline int attribTypes() const
112  { return myAttributeTypes; }
113 
114  /// Returns true if merging should always do a deep copy of attribs
115  inline bool isDeep() const
116  { return myIsDeep; }
117 
118  /// Returns true if the merge operation is between dependents within the
119  /// same node
120  bool isInternalDependent() const
121  { return myIsInternalDependent; }
122 
123  /// Returns the attribute collision strategy
125  { return myCollisionStrategy; }
126 
127  /// Sets the attribute flatten mode
129  { myAttribFlatten = flatten; }
130 
131  /// Sets the default merge operation
133  PDG_AttributeMergeOp merge_op)
134  { myDefaultOp.myMergeOp = merge_op; }
135 
136  /// Adds a merge type for input files
138  PDG_AttributeMergeOp merge_op)
139  { myInputOp.myMergeOp = merge_op; }
140 
141  /// Adds a merge type for output files
143  PDG_AttributeMergeOp merge_op)
144  { myOutputOp.myMergeOp = merge_op; }
145 
146  /// Sets the is merge added flag
147  void setIsMergeAdded(bool merge_added)
148  { myIsMergeAdded = merge_added; }
149 
150  /// Sets the collision strategy, used when an existing attribute is found
151  /// and a decision needs to be made about overwrting it.
153  PDG_AttributeCollision strategy)
154  { myCollisionStrategy = strategy; }
155 
156  /// Adds an attibute name to the list of forced ignore attributes
158  { myForceIgnore.insert(name); }
159 
160  /// Sets a flag that indicates this merge is being applied to work items
161  /// from the same node
162  void setIsInternalDependent(bool dependent)
163  { myIsInternalDependent = dependent; }
164 
165  /// Returns true if the merge should flatten the dynamic and static
166  /// attribute maps into a single table
167  bool isMergeFlatten() const;
168 
169  /// Returns true if the merge should also included added files when
170  /// merging outputs, which is typically only used during deseralization
171  bool isMergeAdded() const;
172 
173  /// Reports warnings on the specified node from the merge errors recorded
174  /// in the map
175  void reportErrors(PDG_Node* node) const;
176 
177  /// Compares two patterns for equality
178  static bool arePatternsEqual(const Pattern& left,
179  const Pattern& right);
180 
181 private:
182  /// Struct for holding details about a merge error
183  struct MergeError
184  {
185  int myLeftStride;
186  int myRightStride;
187  PDG_AttributeType myLeftType;
188  PDG_AttributeType myRightType;
189  PDG_AttributeMergeOp myMergeOp;
190  PDG_AttributeMergeError myError;
191  };
192 
193  /// Struct for holding pending merge operations
194  struct MergePending
195  {
196  PDG_AttributeMergeOp myMergeOp;
198  int myStride;
199  };
200 
201  /// String map of attrib name -> merge error. We only store one error
202  /// per attribute to avoid too much noise.
203  using MergeErrors = UT_StringMap<MergeError>;
204 
205  /// All collection of pending operations that need to be applied
206  using Pending = UT_StringMap<MergePending>;
207 
208 private:
209  friend class PDG_AttributeMap;
210 
211  /// Adds a merge error
212  void addMergeError(
213  const UT_StringHolder& name,
214  int left_stride,
215  int right_stride,
218  PDG_AttributeMergeOp merge_op,
220 
221  /// Adds a collision error
222  void addCollisionError(
223  const UT_StringHolder& name);
224 
225  /// Adds a pending operation that needs to be applied after merging is
226  /// completed
227  int addPendingOp(
228  const UT_StringHolder& name,
229  const MergeData* merge_data,
231  int current_length,
232  int new_length);
233 
234  /// Returns pending operations stored in this object
235  const Pending& pendingOps() const
236  { return myPendingOps; }
237 
238  /// Returns true if the specified merge op requires post processing
239  static bool requiresPending(
240  PDG_AttributeMergeOp merge_op);
241 
242  /// Returns the merge type for the specified attribute name by matching
243  /// it against the patterns.
244  const MergeData* matchAttrib(
245  const UT_StringHolder& name,
246  PDG_AttributeType type) const;
247 
248 private:
249  MergeErrors myMergeErrors;
250  UT_ArrayStringSet myCollisionErrors;
251 
252  Pending myPendingOps;
253  const Pattern& myMergePattern;
254 
255  UT_ArrayStringSet myForceIgnore;
256 
257  int myAttributeTypes;
258  AttribFlatten myAttribFlatten;
259 
260  MergeData myDefaultOp;
261  MergeData myInputOp;
262  MergeData myOutputOp;
263 
264  PDG_AttributeCollision myCollisionStrategy;
265 
266  bool myIsDeep;
267  bool myIsMergeAdded;
268  bool myIsInternalDependent;
269 };
270 
271 #endif
GLint left
Definition: glcorearb.h:2005
void setIsMergeAdded(bool merge_added)
Sets the is merge added flag.
#define PDG_API
Definition: PDG_API.h:23
GLdouble right
Definition: glad.h:2817
PDG_AttributeMergeOp myMergeOp
MergeData(const UT_StringHolder &pattern, PDG_AttributeMergeOp merge_op, bool preserve_array)
void addForceIgnore(const UT_StringHolder &name)
Adds an attibute name to the list of forced ignore attributes.
ImageBuf OIIO_API flatten(const ImageBuf &src, ROI roi={}, int nthreads=0)
bool isDeep() const
Returns true if merging should always do a deep copy of attribs.
void setAttribCollision(PDG_AttributeCollision strategy)
void setOutputMerge(PDG_AttributeMergeOp merge_op)
Adds a merge type for output files.
< returns > If no error
Definition: snippets.dox:2
AttribTable
Enumeration of attribute tables.
PDG_AttributePattern myPattern
PDG_AttributeCollision attribCollision() const
Returns the attribute collision strategy.
GLuint const GLchar * name
Definition: glcorearb.h:786
PDG_AttributeMergeOp
Enumeration of different ways that attributes can be combined.
GLushort pattern
Definition: glad.h:2583
static const Pattern theEmptyPattern
The default, empty merge pattern.
void setIsInternalDependent(bool dependent)
PDG_AttributeCollision
Definition: PDG_Types.h:528
PDG_AttributeType
Enumeration of possible attribute types.
void setAttribFlatten(AttribFlatten flatten)
Sets the attribute flatten mode.
AttribType
Enumeration of types of data types to merge.
Never flatten the attribute maps.
int attribTypes() const
Returns the attribute type filter.
PDG_AttributeMergeError
Enumerations of errors that can occur when merging attributes.
bool isInternalDependent() const
void setInputMerge(PDG_AttributeMergeOp merge_op)
Adds a merge type for input files.
Always flatten the attribute maps.
MergeData(PDG_AttributeMergeOp merge_op)
type
Definition: core.h:1059
void setDefaultMerge(PDG_AttributeMergeOp merge_op)
Sets the default merge operation.