HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_AttributeData.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_DATA_H__
10 #define __PDG_ATTRIBUTE_DATA_H__
11 
12 #include "PDG_API.h"
13 
14 #include "PDG_AttributeTypes.h"
15 #include "PDG_EventTypes.h"
16 #include "PDG_File.h"
17 
18 #include <SYS/SYS_Hash.h>
19 #include <SYS/SYS_Types.h>
20 
21 #include <UT/UT_Array.h>
22 #include <UT/UT_NonCopyable.h>
23 #include <UT/UT_Options.h>
24 #include <UT/UT_StringArray.h>
25 #include <UT/UT_StringHolder.h>
26 #include <UT/UT_ValArray.h>
27 
28 class UT_JSONValue;
29 class UT_JSONWriter;
30 class UT_WorkBuffer;
31 
32 /**
33  * Base class for all types of PDG attribute data
34  */
36 {
37 public:
38  /// Attribute data version number
39  static constexpr PDG_AttributeType TypeEnum = PDG_AttributeType::eUndefined;
40 
41  /// Static stringholder keys, used during json serialization and
42  /// deserialization.
47  static const UT_StringHolder theOwnKey;
49 
50 public:
51  /// Constructs a new instance with a specified type and owning map, called
52  /// by child classes.
54  virtual ~PDG_AttributeData();
55 
56  /// Returns the memory usage of the attribute and its data
57  virtual int64 getMemoryUsage(bool inclusive) const = 0;
58 
59  /// Return a hash value derived from the attribute data
60  virtual bool hash(SYS_HashType& hash_value,
61  UT_WorkBuffer& errors) const = 0;
62 
63  /// Deep copies this attribute
64  virtual PDG_AttributeData* clone() const = 0;
65 
66  /// Serializes the data to a JSON writer
67  virtual bool saveData(UT_JSONWriter&) const = 0;
68 
69  /// Serializes the data to a UT options
70  virtual void saveData(
71  const UT_StringHolder&,
72  UT_OptionsHolder&) const = 0;
73 
74  /// Loads data from a JSON value
75  virtual bool loadData(const UT_JSONValue&) = 0;
76 
77  /// Loads data from a dict
78  virtual bool loadData(
79  const UT_StringHolder&,
80  const UT_OptionsHolder&) = 0;
81 
82  /// Compares this data object with another data object
83  virtual bool compare(const PDG_AttributeData*) const = 0;
84 
85  /// Applies a merge op to the data in this attribute
86  virtual PDG_AttributeMergeError merge(
87  PDG_AttributeMergeOp merge_op,
88  int stride) = 0;
89 
90  /// Static utility for constructing an attribute of the specified type,
91  /// used during deserialization
92  static PDG_AttributeData* fromType(PDG_AttributeType type);
93 
94  /// Static utility for returnign an event from type from an attribute type
95  static PDG_EventType eventType(PDG_AttributeType type);
96 
97  /// Returns an attribute type enum from the specified string name
99  const UT_StringHolder& type_name);
100 
101  /// Returns an intrinsic type from an attribue name
102  static PDG_AttributeIntrinsic intrinsicFromName(const UT_StringRef& name);
103 
104  /// Returns an attribute name from a intrinsic type a name string
105  static UT_StringHolder nameFromIntrinsic(
106  PDG_AttributeIntrinsic attrib_type,
107  const UT_StringHolder& name);
108 
109  /// Returns true if the specified string is a valid attribute name. A
110  /// valid name cannot start with __pdg prefix unless allow_interal is
111  /// true. All names must begin with a letter or _ character and only
112  /// contain letters/numbers/_ for subsequent character. E.g. they
113  /// must match UT_String::isValidVariableName.
114  static bool validName(const UT_StringHolder& str,
115  bool allow_internal=false);
116 
117  /// Forces the string into a valid attribute name as described above, and
118  /// returns true if any changes were made. If allow_internal is false then
119  /// a __pdg prefix is replaced with __.
120  static bool makeValidName(UT_StringHolder& name,
121  const UT_StringHolder& str,
122  bool allow_internal=false);
123 
124  /// Returns the string name for the specififed attribute type
125  static UT_StringHolder typeName(PDG_AttributeType type);
126 
127  /// Returns the string name for the specified merge op
128  static UT_StringHolder mergeName(PDG_AttributeMergeOp merge);
129 
130 protected:
131  /// Merge op utility for string array data
133  PDG_AttributeMergeOp merge_op,
134  int stride);
135 
136  /// Merge op utility for file array data
138  PDG_AttributeMergeOp merge_op,
139  int stride);
140 
141  /// Merge op utility for float array data
143  PDG_AttributeMergeOp merge_op,
144  int stride);
145 
146  /// Merge op utility for int array data
148  PDG_AttributeMergeOp merge_op,
149  int stride);
150 
151  /// Merge op utility for dict array data
153  PDG_AttributeMergeOp merge_op,
154  int stride);
155 };
156 
157 #endif
PDG_AttributeIntrinsic
Enumeration of types of attribute that can be queried from work items.
Undefined or uninitialized attribute type.
#define PDG_API
Definition: PDG_API.h:23
VEX_API VEX_GeoPrimType typeFromString(const char *)
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
CompareResults OIIO_API compare(const ImageBuf &A, const ImageBuf &B, float failthresh, float warnthresh, ROI roi={}, int nthreads=0)
constexpr std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size(){return subtype_count< typename std::tuple_element< I, T >::type >::value+tuple_type_size< T, I+1 >);}template< typename T > struct type_count< T, typename std::enable_if< is_tuple_like< T >::value >::type >{static constexpr int value{tuple_type_size< T, 0 >)};};template< typename T > struct subtype_count{static constexpr int value{is_mutable_container< T >::value?expected_max_vector_size:type_count< T >::value};};template< typename T, typename Enable=void > struct type_count_min{static const int value{0};};template< typename T >struct type_count_min< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_tuple_like< T >::value &&!is_wrapper< T >::value &&!is_complex< T >::value &&!std::is_void< T >::value >::type >{static constexpr int value{type_count< T >::value};};template< typename T > struct type_count_min< T, typename std::enable_if< is_complex< T >::value >::type >{static constexpr int value{1};};template< typename T >struct type_count_min< T, typename std::enable_if< is_wrapper< T >::value &&!is_complex< T >::value &&!is_tuple_like< T >::value >::type >{static constexpr int value{subtype_count_min< typename T::value_type >::value};};template< typename T, std::size_t I >constexpr typename std::enable_if< I==type_count_base< T >::value, int >::type tuple_type_size_min(){return 0;}template< typename T, std::size_t I > constexpr typename std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size_min(){return subtype_count_min< typename std::tuple_element< I, T >::type >::value+tuple_type_size_min< T, I+1 >);}template< typename T > struct type_count_min< T, typename std::enable_if< is_tuple_like< T >::value >::type >{static constexpr int value{tuple_type_size_min< T, 0 >)};};template< typename T > struct subtype_count_min{static constexpr int value{is_mutable_container< T >::value?((type_count< T >::value< expected_max_vector_size)?type_count< T >::value:0):type_count_min< T >::value};};template< typename T, typename Enable=void > struct expected_count{static const int value{0};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_wrapper< T >::value &&!std::is_void< T >::value >::type >{static constexpr int value{1};};template< typename T > struct expected_count< T, typename std::enable_if< is_mutable_container< T >::value >::type >{static constexpr int value{expected_max_vector_size};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&is_wrapper< T >::value >::type >{static constexpr int value{expected_count< typename T::value_type >::value};};enum class object_category:int{char_value=1, integral_value=2, unsigned_integral=4, enumeration=6, boolean_value=8, floating_point=10, number_constructible=12, double_constructible=14, integer_constructible=16, string_assignable=23, string_constructible=24, other=45, wrapper_value=50, complex_number=60, tuple_value=70, container_value=80,};template< typename T, typename Enable=void > struct classify_object{static constexpr object_category value{object_category::other};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&!std::is_same< T, char >::value &&std::is_signed< T >::value &&!is_bool< T >::value &&!std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::integral_value};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&std::is_unsigned< T >::value &&!std::is_same< T, char >::value &&!is_bool< T >::value >::type >{static constexpr object_category value{object_category::unsigned_integral};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_same< T, char >::value &&!std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::char_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_bool< T >::value >::type >{static constexpr object_category value{object_category::boolean_value};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_floating_point< T >::value >::type >{static constexpr object_category value{object_category::floating_point};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&std::is_assignable< T &, std::string >::value >::type >{static constexpr object_category value{object_category::string_assignable};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&(type_count< T >::value==1)&&std::is_constructible< T, std::string >::value >::type >{static constexpr object_category value{object_category::string_constructible};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::enumeration};};template< typename T > struct classify_object< T, typename std::enable_if< is_complex< T >::value >::type >{static constexpr object_category value{object_category::complex_number};};template< typename T > struct uncommon_type{using type=typename std::conditional<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&!std::is_constructible< T, std::string >::value &&!is_complex< T >::value &&!is_mutable_container< T >::value &&!std::is_enum< T >::value, std::true_type, std::false_type >::type;static constexpr bool value=type::value;};template< typename T >struct classify_object< T, typename std::enable_if<(!is_mutable_container< T >::value &&is_wrapper< T >::value &&!is_tuple_like< T >::value &&uncommon_type< T >::value)>::type >{static constexpr object_category value{object_category::wrapper_value};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::number_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&!is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::integer_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::double_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< is_tuple_like< T >::value &&((type_count< T >::value >=2 &&!is_wrapper< T >::value)||(uncommon_type< T >::value &&!is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value)||(uncommon_type< T >::value &&type_count< T >::value >=2))>::type >{static constexpr object_category value{object_category::tuple_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_mutable_container< T >::value >::type >{static constexpr object_category value{object_category::container_value};};template< typename T, enable_if_t< classify_object< T >::value==object_category::char_value, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"CHAR";}template< typename T, enable_if_t< classify_object< T >::value==object_category::integral_value||classify_object< T >::value==object_category::integer_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"INT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::unsigned_integral, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"UINT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::floating_point||classify_object< T >::value==object_category::number_constructible||classify_object< T >::value==object_category::double_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"FLOAT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::enumeration, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"ENUM";}template< typename T, enable_if_t< classify_object< T >::value==object_category::boolean_value, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"BOOLEAN";}template< typename T, enable_if_t< classify_object< T >::value==object_category::complex_number, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"COMPLEX";}template< typename T, enable_if_t< classify_object< T >::value >=object_category::string_assignable &&classify_object< T >::value<=object_category::other, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"TEXT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::container_value||classify_object< T >::value==object_category::wrapper_value, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value==1, detail::enabler >=detail::dummy >inline std::string type_name(){return type_name< typename std::decay< typename std::tuple_element< 0, T >::type >::type >);}template< typename T, std::size_t I >inline typename std::enable_if< I==type_count_base< T >::value, std::string >::type tuple_name(){return std::string{};}template< typename T, std::size_t I >inline typename std::enable_if<(I< type_count_base< T >::value), std::string >::type tuple_name(){auto str=std::string{type_name< typename std::decay< typename std::tuple_element< I, T >::type >::type >)}+ ','+tuple_name< T, I+1 >);if(str.back()== ',') str.pop_back();return str;}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler > > std::string type_name()
Recursively generate the tuple type name.
Definition: CLI11.h:1729
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:872
long long int64
Definition: SYS_Types.h:116
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.
static const UT_StringHolder theTypeKey
static const UT_StringHolder theValueKey
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
PDG_AttributeMergeError
Enumerations of errors that can occur when merging attributes.
PDG_EventType
static const UT_StringHolder theRuntimeKey
static const UT_StringHolder theConcatKey
size_t hash_value(const CH_ChannelRef &ref)
type
Definition: core.h:1059
static const UT_StringHolder theFlagKey
static const UT_StringHolder theOwnKey
Definition: format.h:895