HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_AttributeSplit.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_SPLIT_H__
10 #define __PDG_ATTRIBUTE_SPLIT_H__
11 
12 #include "PDG_API.h"
13 
14 #include "PDG_AttributeMap.h"
15 #include "PDG_NodeTypes.h"
16 #include "PDG_WorkItem.h"
17 #include "PDG_WorkItemTypes.h"
18 
19 #include <UT/UT_ArrayMap.h>
20 #include <UT/UT_ArrayStringMap.h>
21 #include <UT/UT_StringArray.h>
22 #include <UT/UT_StringHolder.h>
23 
24 /**
25  * Utility class for splitting a list of work items by an attribute value,
26  * into a map to subsets of the original work item list.
27  */
29 {
30 public:
31  /// Value -> work item list map, used when splitting a list of work
32  /// items into multiple list by an attribute value.
33  template <typename Value>
35 
36  /// String value -> work item list map, used when splitting a list of
37  /// work items without specifying a specific attribute type.
39 
40  /// Integer value -> work item list map, used when splitting a list of
41  /// work items into batches.
43 
44 public:
45  /// Batches work items by frame. Iterates over a list of work items and
46  /// attempts to extract N contiguous lists that span an increasing frame
47  /// range.
48  static void batchWorkItemsByFrame(
49  BatchSplitArray& batches,
50  PDG_WorkItemArray& missing_items,
51  const PDG_WorkItemArray& work_items,
52  const PDG_NodeArray* input_nodes,
53  bool save_missing = true);
54 
55  /// Splits a list of input work items into a split map by the specified
56  /// attribute value. Work items that are missing the attribute are
57  /// returned in a second output list. The list of unique attribute values
58  /// is also returned as a third output.
59  ///
60  /// This variation of the function is templated on a specific type of
61  /// attribute, and uses that type natively for the map key and when
62  /// accessing attribute values. An alternative version exists below that
63  /// is not templated on the type and simply uses the common, string
64  /// represenation of the attribute value instead.
65  template <typename Attribute>
66  static bool splitWorkItems(
68  PDG_WorkItemArray& missing_items,
69  typename Attribute::Array& unique_values,
70  const PDG_WorkItemArray& work_items,
71  const UT_StringHolder& attrib_name,
72  bool save_missing = true)
73  {
74  bool conflict = false;
75  for (auto&& work_item : work_items)
76  {
77  auto&& ref = work_item->attributes().refRO<Attribute>(attrib_name);
78  if (!ref || !ref->valid(0))
79  {
81  conflict = true;
82  if (save_missing)
83  missing_items.append(work_item);
84  continue;
85  }
86 
87  typename Attribute::Data value = ref->value(0);
88  auto&& iter = split.find(value);
89  if (iter == split.end())
90  {
91  unique_values.append(value);
92  split[value].append(work_item);
93  continue;
94  }
95 
96  iter->second.append(work_item);
97  }
98 
99  unique_values.sort();
100  return conflict;
101  }
102 
103  /// Same as above, but values are converted to strings and accessed without
104  /// any type information. The attribute name string can contain multiple
105  /// attrib names, separated by spaces
106  static bool splitWorkItems(
107  StringSplitMap& split,
108  PDG_WorkItemArray& missing_items,
109  UT_StringArray& unique_values,
110  const PDG_WorkItemArray& work_items,
111  const UT_StringHolder& attrib_names,
112  const UT_StringHolder* default_value,
113  bool save_missing = true,
114  bool partial_match = false);
115 };
116 
117 #endif
GLsizei const GLfloat * value
Definition: glcorearb.h:824
#define PDG_API
Definition: PDG_API.h:23
static bool splitWorkItems(SplitMap< typename Attribute::Data > &split, PDG_WorkItemArray &missing_items, typename Attribute::Array &unique_values, const PDG_WorkItemArray &work_items, const UT_StringHolder &attrib_name, bool save_missing=true)
iterator find(const Key &key)
Definition: UT_ArrayMap.h:158
GLint ref
Definition: glcorearb.h:124
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER class IMF_EXPORT_TEMPLATE_TYPE Array
Definition: ImfForward.h:21
exint append()
Definition: UT_Array.h:142
Definition: core.h:1131
void OIIO_UTIL_API split(string_view str, std::vector< string_view > &result, string_view sep=string_view(), int maxsplit=-1)
constexpr FMT_INLINE value()
Definition: core.h:1154