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_NonCopyable.h>
22 #include <UT/UT_StringArray.h>
23 #include <UT/UT_StringHolder.h>
24 #include <UT/UT_ValArray.h>
25 
26 class UT_JSONValue;
27 class UT_JSONWriter;
28 class UT_WorkBuffer;
29 
30 /**
31  * Base class for all types of PDG attribute data
32  */
34 {
35 public:
36  /// Attribute data version number
37  static constexpr PDG_AttributeType TypeEnum = PDG_AttributeType::eUndefined;
38 
39  /// Static stringholder keys, used during json serialization and
40  /// deserialization.
45  static const UT_StringHolder theOwnKey;
47 
48 public:
49  /// Constructs a new instance with a specified type and owning map, called
50  /// by child classes.
52  virtual ~PDG_AttributeData();
53 
54  /// Returns the memory usage of the attribute and its data
55  virtual int64 getMemoryUsage(bool inclusive) const = 0;
56 
57  /// Return a hash value derived from the attribute data
58  virtual bool hash(SYS_HashType& hash_value,
59  UT_WorkBuffer& errors) const = 0;
60 
61  /// Deep copies this attribute
62  virtual PDG_AttributeData* clone() const = 0;
63 
64  /// Serializes the data to a JSON writer
65  virtual bool saveData(UT_JSONWriter&) const = 0;
66 
67  /// Loads data from a JSON value
68  virtual bool loadData(const UT_JSONValue&) = 0;
69 
70  /// Compares this data object with another data object
71  virtual bool compare(const PDG_AttributeData*) const = 0;
72 
73  /// Applies a merge op to the data in this attribute
74  virtual PDG_AttributeMergeError merge(
75  PDG_AttributeMergeOp merge_op,
76  int stride) = 0;
77 
78 
79  /// Static utility for constructing an attribute of the specified type,
80  /// used during deserialization
81  static PDG_AttributeData* fromType(PDG_AttributeType type);
82 
83  /// Static utility for returnign an event from type from an attribute type
84  static PDG_EventType eventType(PDG_AttributeType type);
85 
86  /// Returns an attribute type enum from the specified string name
88  const UT_StringHolder& type_name);
89 
90  /// Returns an intrinsic type from an attribue name
91  static PDG_AttributeIntrinsic intrinsicFromName(const UT_StringRef& name);
92 
93  /// Returns an attribute name from a intrinsic type a name string
94  static UT_StringHolder nameFromIntrinsic(
95  PDG_AttributeIntrinsic attrib_type,
96  const UT_StringHolder& name);
97 
98  /// Returns true if the specified string is a valid attribute name. A
99  /// valid name cannot start with __pdg prefix unless allow_interal is
100  /// true. All names must begin with a letter or _ character and only
101  /// contain letters/numbers/_ for subsequent character. E.g. they
102  /// must match UT_String::isValidVariableName.
103  static bool validName(const UT_StringHolder& str,
104  bool allow_internal=false);
105 
106  /// Forces the string into a valid attribute name as described above, and
107  /// returns true if any changes were made. If allow_internal is false then
108  /// a __pdg prefix is replaced with __.
109  static bool makeValidName(UT_StringHolder& name,
110  const UT_StringHolder& str,
111  bool allow_internal=false);
112 
113  /// Returns the string name for the specififed attribute type
114  static UT_StringHolder typeName(PDG_AttributeType type);
115 
116  /// Returns the string name for the specified merge op
117  static UT_StringHolder mergeName(PDG_AttributeMergeOp merge);
118 
119 protected:
120  /// Merge op utility for string array data
122  PDG_AttributeMergeOp merge_op,
123  int stride);
124 
125  /// Merge op utility for file array data
127  PDG_AttributeMergeOp merge_op,
128  int stride);
129 
130  /// Merge op utility for float array data
132  PDG_AttributeMergeOp merge_op,
133  int stride);
134 
135  /// Merge op utility for int array data
137  PDG_AttributeMergeOp merge_op,
138  int stride);
139 };
140 
141 #endif
PDG_AttributeIntrinsic
Enumeration of types of attribute that can be queried from work items.
#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
Undefined or uninitialized attribute type.
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
PDG_AttributeType
Enumeration of possible attribute types.
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
PDG_AttributeMergeError
Enumerations of errors that can occur when merging attributes.
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