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_Types.h"
16 #include "PDG_WorkItem.h"
17 
18 #include <UT/UT_ArrayMap.h>
19 #include <UT/UT_ArrayStringMap.h>
20 #include <UT/UT_StringArray.h>
21 #include <UT/UT_StringHolder.h>
22 
23 /**
24  * Utility class for splitting a list of work items by an attribute value,
25  * into a map to subsets of the original work item list.
26  */
28 {
29 public:
30  /// Value -> work item list map, used when splitting a list of work
31  /// items into multiple list by an attribute value.
32  template <typename Value>
34 
35  /// String value -> work item list map, used when splitting a list of
36  /// work items without specifying a specific attribute type.
38 
39  /// Integer value -> work item list map, used when splitting a list of
40  /// work items into batches.
42 
43 public:
44  /// Batches work items by frame. Iterates over a list of work items and
45  /// attempts to extract N contiguous lists that span an increasing frame
46  /// range.
47  static void batchWorkItemsByFrame(
48  BatchSplitArray& batches,
49  PDG_WorkItemArray& missing_items,
50  const PDG_WorkItemArray& work_items,
51  const PDG_NodeArray* input_nodes,
52  bool save_missing = true);
53 
54  /// Splits a list of input work items into a split map by the specified
55  /// attribute value. Work items that are missing the attribute are
56  /// returned in a second output list. The list of unique attribute values
57  /// is also returned as a third output.
58  ///
59  /// This variation of the function is templated on a specific type of
60  /// attribute, and uses that type natively for the map key and when
61  /// accessing attribute values. An alternative version exists below that
62  /// is not templated on the type and simply uses the common, string
63  /// represenation of the attribute value instead.
64  template <typename Attribute>
65  static bool splitWorkItems(
67  PDG_WorkItemArray& missing_items,
68  typename Attribute::Array& unique_values,
69  const PDG_WorkItemArray& work_items,
70  const UT_StringHolder& attrib_name,
71  bool save_missing = true)
72  {
73  bool conflict = false;
74  for (auto&& work_item : work_items)
75  {
76  auto&& ref = work_item->attributes().refRO<Attribute>(attrib_name);
77  if (!ref || !ref->valid(0))
78  {
80  conflict = true;
81  if (save_missing)
82  missing_items.append(work_item);
83  continue;
84  }
85 
86  typename Attribute::Data value = ref->value(0);
87  auto&& iter = split.find(value);
88  if (iter == split.end())
89  {
90  unique_values.append(value);
91  split[value].append(work_item);
92  continue;
93  }
94 
95  iter->second.append(work_item);
96  }
97 
98  unique_values.sort();
99  return conflict;
100  }
101 
102  /// Same as above, but values are converted to strings and accessed without
103  /// any type information. The attribute name string can contain multiple
104  /// attrib names, separated by spaces
105  static bool splitWorkItems(
106  StringSplitMap& split,
107  PDG_WorkItemArray& missing_items,
108  UT_StringArray& unique_values,
109  const PDG_WorkItemArray& work_items,
110  const UT_StringHolder& attrib_names,
111  const UT_StringHolder* default_value,
112  bool save_missing = true,
113  bool partial_match = false);
114 };
115 
116 #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:22
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