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 public:
41  /// Splits a list of input work items into a split map by the specified
42  /// attribute value. Work items that are missing the attribute are
43  /// returned in a second output list. The list of unique attribute values
44  /// is also returned as a third output.
45  ///
46  /// This variation of the function is templated on a specific type of
47  /// attribute, and uses that type natively for the map key and when
48  /// accessing attribute values. An alternative version exists below that
49  /// is not templated on the type and simply uses the common, string
50  /// represenation of the attribute value instead.
51  template <typename Attribute>
52  static bool splitWorkItems(
54  PDG_WorkItemArray& missing_items,
55  typename Attribute::Array& unique_values,
56  const PDG_WorkItemArray& work_items,
57  const UT_StringHolder& attrib_name,
58  bool save_missing = true)
59  {
60  bool conflict = false;
61  for (auto&& work_item : work_items)
62  {
63  auto&& ref = work_item->attributes().refRO<Attribute>(attrib_name);
64  if (!ref || !ref->valid(0))
65  {
67  conflict = true;
68  if (save_missing)
69  missing_items.append(work_item);
70  continue;
71  }
72 
73  typename Attribute::Data value = ref->value(0);
74  auto&& iter = split.find(value);
75  if (iter == split.end())
76  {
77  unique_values.append(value);
78  split[value].append(work_item);
79  continue;
80  }
81 
82  iter->second.append(work_item);
83  }
84 
85  unique_values.sort();
86  return conflict;
87  }
88 
89  /// Same as above, but values are converted to strings and accessed without
90  /// any type information. The attribute name string can contain multiple
91  /// attrib names, separated by spaces
92  static bool splitWorkItems(
93  StringSplitMap& split,
94  PDG_WorkItemArray& missing_items,
95  UT_StringArray& unique_values,
96  const PDG_WorkItemArray& work_items,
97  const UT_StringHolder& attrib_names,
98  const UT_StringHolder* default_value,
99  bool save_missing = true,
100  bool partial_match = false);
101 };
102 
103 #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
void OIIO_UTIL_API split(string_view str, std::vector< string_view > &result, string_view sep=string_view(), int maxsplit=-1)