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