HDK
|
#include <TypeDesc.h>
Classes | |
class | DataBlock |
Data block holding large data needed by the type description. More... | |
struct | Hasher |
Hash operator. More... | |
Public Types | |
enum | BaseType { BASETYPE_NONE, BASETYPE_BOOLEAN, BASETYPE_INTEGER, BASETYPE_FLOAT, BASETYPE_STRING, BASETYPE_STRUCT, BASETYPE_LAST } |
enum | Semantic { SEMANTIC_NONE, SEMANTIC_COLOR, SEMANTIC_VECTOR, SEMANTIC_MATRIX, SEMANTIC_FILENAME, SEMANTIC_CLOSURE, SEMANTIC_SHADER, SEMANTIC_MATERIAL, SEMANTIC_ENUM, SEMANTIC_LAST } |
enum | BASETYPE { UNKNOWN, NONE, UINT8, UCHAR =UINT8, INT8, CHAR =INT8, UINT16, USHORT =UINT16, INT16, SHORT =INT16, UINT32, UINT =UINT32, INT32, INT =INT32, UINT64, ULONGLONG =UINT64, INT64, LONGLONG =INT64, HALF, FLOAT, DOUBLE, STRING, PTR, USTRINGHASH, LASTBASE } |
enum | AGGREGATE { SCALAR = 1, VEC2 = 2, VEC3 = 3, VEC4 = 4, MATRIX33 = 9, MATRIX44 = 16 } |
enum | VECSEMANTICS { NOXFORM = 0, NOSEMANTICS = 0, COLOR, POINT, VECTOR, NORMAL, TIMECODE, KEYCODE, RATIONAL, BOX } |
using | DataBlockPtr = std::shared_ptr< DataBlock > |
Public Member Functions | |
constexpr | TypeDesc () noexcept |
Empty constructor. More... | |
constexpr | TypeDesc (std::string_view name, uint8_t basetype, uint8_t semantic, uint16_t size, const DataBlock *data) noexcept |
Constructor. More... | |
uint32_t | typeId () const |
const string & | getName () const |
Return the name of the type. More... | |
unsigned char | getBaseType () const |
Return the basetype for the type. More... | |
unsigned char | getSemantic () const |
Return the semantic for the type. More... | |
size_t | getSize () const |
bool | isScalar () const |
Return true if the type is a scalar type. More... | |
bool | isAggregate () const |
Return true if the type is an aggregate type. More... | |
bool | isArray () const |
Return true if the type is an array type. More... | |
bool | isFloat2 () const |
Return true if the type is an aggregate of 2 floats. More... | |
bool | isFloat3 () const |
Return true if the type is an aggregate of 3 floats. More... | |
bool | isFloat4 () const |
Return true if the type is an aggregate of 4 floats. More... | |
bool | isClosure () const |
Return true if the type represents a closure. More... | |
bool | isStruct () const |
Return true if the type represents a struct. More... | |
StructMemberDescVecPtr | getStructMembers () const |
bool | operator== (TypeDesc rhs) const |
Equality operator. More... | |
bool | operator!= (TypeDesc rhs) const |
Inequality operator. More... | |
bool | operator< (TypeDesc rhs) const |
Less-than operator. More... | |
ValuePtr | createValueFromStrings (const string &value) const |
Create a Value from a string for a given typeDesc. More... | |
OIIO_HOSTDEVICE constexpr | TypeDesc (BASETYPE btype=UNKNOWN, AGGREGATE agg=SCALAR, VECSEMANTICS semantics=NOSEMANTICS, int arraylen=0) noexcept |
OIIO_HOSTDEVICE constexpr | TypeDesc (BASETYPE btype, int arraylen) noexcept |
Construct an array of a non-aggregate BASETYPE. More... | |
OIIO_HOSTDEVICE constexpr | TypeDesc (BASETYPE btype, AGGREGATE agg, int arraylen) noexcept |
TypeDesc (string_view typestring) | |
OIIO_HOSTDEVICE constexpr | TypeDesc (const TypeDesc &t) noexcept=default |
Copy constructor. More... | |
const char * | c_str () const |
OIIO_HOSTDEVICE OIIO_CONSTEXPR14 size_t | numelements () const noexcept |
OIIO_HOSTDEVICE OIIO_CONSTEXPR14 size_t | basevalues () const noexcept |
OIIO_HOSTDEVICE constexpr bool | is_array () const noexcept |
Does this TypeDesc describe an array? More... | |
OIIO_HOSTDEVICE constexpr bool | is_unsized_array () const noexcept |
OIIO_HOSTDEVICE constexpr bool | is_sized_array () const noexcept |
Does this TypeDesc describe an array, whose length is specified? More... | |
OIIO_HOSTDEVICE size_t | size () const noexcept |
OIIO_HOSTDEVICE OIIO_CONSTEXPR14 TypeDesc | elementtype () const noexcept |
OIIO_HOSTDEVICE size_t | elementsize () const noexcept |
OIIO_HOSTDEVICE constexpr TypeDesc | scalartype () const |
size_t | basesize () const noexcept |
bool | is_floating_point () const noexcept |
bool | is_signed () const noexcept |
True if it's a signed type that allows for negative values. More... | |
OIIO_HOSTDEVICE constexpr bool | is_unknown () const noexcept |
Shortcut: is it UNKNOWN? More... | |
OIIO_HOSTDEVICE constexpr | operator bool () const noexcept |
if (typedesc) is the same as asking whether it's not UNKNOWN. More... | |
size_t | fromstring (string_view typestring) |
OIIO_HOSTDEVICE constexpr bool | operator== (const TypeDesc &t) const noexcept |
OIIO_HOSTDEVICE constexpr bool | operator!= (const TypeDesc &t) const noexcept |
OIIO_HOSTDEVICE constexpr bool | equivalent (const TypeDesc &b) const noexcept |
Member version of equivalent. More... | |
OIIO_HOSTDEVICE constexpr bool | is_vec2 (BASETYPE b=FLOAT) const noexcept |
Is this a 2-vector aggregate (of the given type, float by default)? More... | |
OIIO_HOSTDEVICE constexpr bool | is_vec3 (BASETYPE b=FLOAT) const noexcept |
Is this a 3-vector aggregate (of the given type, float by default)? More... | |
OIIO_HOSTDEVICE constexpr bool | is_vec4 (BASETYPE b=FLOAT) const noexcept |
Is this a 4-vector aggregate (of the given type, float by default)? More... | |
OIIO_HOSTDEVICE constexpr bool | is_box2 (BASETYPE b=FLOAT) const noexcept |
Is this an array of aggregates that represents a 2D bounding box? More... | |
OIIO_HOSTDEVICE constexpr bool | is_box3 (BASETYPE b=FLOAT) const noexcept |
Is this an array of aggregates that represents a 3D bounding box? More... | |
OIIO_HOSTDEVICE void | unarray (void) noexcept |
bool | operator< (const TypeDesc &x) const noexcept |
Static Public Member Functions | |
static BASETYPE | basetype_merge (TypeDesc a, TypeDesc b) |
Public Attributes | |
unsigned char | basetype |
C data type at the heart of our type. More... | |
unsigned char | aggregate |
What kind of AGGREGATE is it? More... | |
unsigned char | vecsemantics |
Hint: What does the aggregate represent? More... | |
unsigned char | reserved |
Reserved for future expansion. More... | |
int | arraylen |
Array length, 0 = not array, -1 = unsized. More... | |
Static Public Attributes | |
static const string | NONE_TYPE_NAME |
static const TypeDesc | TypeFloat |
static const TypeDesc | TypeColor |
static const TypeDesc | TypeString |
static const TypeDesc | TypeInt |
static const TypeDesc | TypeHalf |
static const TypeDesc | TypePoint |
static const TypeDesc | TypeVector |
static const TypeDesc | TypeNormal |
static const TypeDesc | TypeMatrix |
static const TypeDesc | TypeMatrix33 |
static const TypeDesc | TypeMatrix44 |
static const TypeDesc | TypeTimeCode |
static const TypeDesc | TypeKeyCode |
static const TypeDesc | TypeFloat4 |
static const TypeDesc | TypeRational |
Friends | |
std::ostream & | operator<< (std::ostream &o, const TypeDesc &t) |
OIIO_HOSTDEVICE friend constexpr bool | operator== (const TypeDesc &t, BASETYPE b) noexcept |
OIIO_HOSTDEVICE friend constexpr bool | operator== (BASETYPE b, const TypeDesc &t) noexcept |
OIIO_HOSTDEVICE friend constexpr bool | operator!= (const TypeDesc &t, BASETYPE b) noexcept |
OIIO_HOSTDEVICE friend constexpr bool | operator!= (BASETYPE b, const TypeDesc &t) noexcept |
OIIO_HOSTDEVICE friend constexpr bool | equivalent (const TypeDesc &a, const TypeDesc &b) noexcept |
A TypeDesc describes simple data types.
It frequently comes up (in my experience, with renderers and image handling programs) that you want a way to describe data that is passed through APIs through blind pointers. These are some simple classes that provide a simple type descriptor system. This is not meant to be comprehensive – for example, there is no provision for structs, unions, pointers, const, or 'nested' type definitions. Just simple integer and floating point, common aggregates such as 3-points, and reasonably-lengthed arrays thereof.
A type descriptor for MaterialX data types.
All types need to have a type descriptor registered in order for shader generators to know about the type. It can be used for type comparisons as well as getting more information about the type. Type descriptors for all standard library data types are defined by default and can be accessed from the Type namespace, e.g. Type::FLOAT. Custom struct types defined through typedef elements in a data library are loaded in and registered by calling the ShaderGenerator::registerTypeDefs method. The TypeSystem class, see below, is used to manage all type descriptions. It can be used to query the registered types.
Definition at line 39 of file TypeDesc.h.
using TypeDesc::DataBlockPtr = std::shared_ptr<DataBlock> |
Definition at line 81 of file TypeDesc.h.
enum TypeDesc::AGGREGATE |
AGGREGATE describes whether our TypeDesc is a simple scalar of one of the BASETYPE's, or one of several simple aggregates.
Note that aggregates and arrays are different. A TypeDesc(FLOAT,3)
is an array of three floats, a TypeDesc(FLOAT,VEC3)
is a single 3-component vector comprised of floats, and TypeDesc(FLOAT,3,VEC3)
is an array of 3 vectors, each of which is comprised of 3 floats.
Definition at line 97 of file typedesc.h.
enum TypeDesc::BaseType |
Enumerator | |
---|---|
BASETYPE_NONE | |
BASETYPE_BOOLEAN | |
BASETYPE_INTEGER | |
BASETYPE_FLOAT | |
BASETYPE_STRING | |
BASETYPE_STRUCT | |
BASETYPE_LAST |
Definition at line 42 of file TypeDesc.h.
enum TypeDesc::BASETYPE |
BASETYPE is a simple enum describing the base data types that correspond (mostly) to the C/C++ built-in types.
Definition at line 56 of file typedesc.h.
enum TypeDesc::Semantic |
Enumerator | |
---|---|
SEMANTIC_NONE | |
SEMANTIC_COLOR | |
SEMANTIC_VECTOR | |
SEMANTIC_MATRIX | |
SEMANTIC_FILENAME | |
SEMANTIC_CLOSURE | |
SEMANTIC_SHADER | |
SEMANTIC_MATERIAL | |
SEMANTIC_ENUM | |
SEMANTIC_LAST |
Definition at line 53 of file TypeDesc.h.
VECSEMANTICS gives hints about what the data represent (for example, if a spatial vector quantity should transform as a point, direction vector, or surface normal).
Definition at line 110 of file typedesc.h.
|
inlinenoexcept |
Empty constructor.
Definition at line 84 of file TypeDesc.h.
|
inlinenoexcept |
Constructor.
Definition at line 94 of file TypeDesc.h.
|
inlinenoexcept |
Construct from a BASETYPE and optional aggregateness, semantics, and arrayness.
Definition at line 133 of file typedesc.h.
|
inlinenoexcept |
Construct an array of a non-aggregate BASETYPE.
Definition at line 143 of file typedesc.h.
|
inlinenoexcept |
Construct an array from BASETYPE, AGGREGATE, and array length, with unspecified (or moot) semantic hints.
Definition at line 148 of file typedesc.h.
TypeDesc::TypeDesc | ( | string_view | typestring | ) |
Construct from a string (e.g., "float[3]"). If no valid type could be assembled, set base to UNKNOWN.
Examples: ``` TypeDesc("int") == TypeDesc(TypeDesc::INT) // C++ int32_t TypeDesc("float") == TypeDesc(TypeDesc::FLOAT) // C++ float TypeDesc("uint16") == TypeDesc(TypeDesc::UINT16) // C++ uint16_t TypeDesc("float[4]") == TypeDesc(TypeDesc::FLOAT, 4) // array TypeDesc("point") == TypeDesc(TypeDesc::FLOAT, TypeDesc::VEC3, TypeDesc::POINT) ```
|
defaultnoexcept |
Copy constructor.
|
noexcept |
Return the base type size, i.e., stripped of both array-ness and aggregateness.
Given base data types of a and b, return a basetype that is a best guess for one that can handle both without any loss of range or precision.
|
inlinenoexcept |
Return the number of basetype values: the aggregate count multiplied by the array length (or 1 if not an array). Invalid to call this for arrays of undetermined size.
Definition at line 189 of file typedesc.h.
const char* TypeDesc::c_str | ( | ) | const |
Return the name, for printing and whatnot. For example, "float", "int[5]", "normal"
Create a Value from a string for a given typeDesc.
|
inlinenoexcept |
Return the size, in bytes, of one element of this type (that is, ignoring whether it's an array).
Definition at line 228 of file typedesc.h.
|
inlinenoexcept |
Return the type of one element, i.e., strip out the array-ness.
Definition at line 222 of file typedesc.h.
|
inlinenoexcept |
Member version of equivalent.
Definition at line 294 of file typedesc.h.
size_t TypeDesc::fromstring | ( | string_view | typestring | ) |
Set *this to the type described in the string. Return the length of the part of the string that describes the type. If no valid type could be assembled, return 0 and do not modify *this.
|
inline |
Return the basetype for the type.
Definition at line 111 of file TypeDesc.h.
const string& TypeDesc::getName | ( | ) | const |
Return the name of the type.
|
inline |
Return the semantic for the type.
Definition at line 114 of file TypeDesc.h.
|
inline |
Return the number of elements the type is composed of. Will return 1 for scalar types and a size greater than 1 for aggregate type. For array types 0 is returned since the number of elements is undefined until an array is instantiated.
Definition at line 120 of file TypeDesc.h.
StructMemberDescVecPtr TypeDesc::getStructMembers | ( | ) | const |
Return a pointer to the struct member description. Will return nullptr if this is not a struct type.
|
inlinenoexcept |
Does this TypeDesc describe an array?
Definition at line 194 of file typedesc.h.
|
inlinenoexcept |
Is this an array of aggregates that represents a 2D bounding box?
Definition at line 316 of file typedesc.h.
|
inlinenoexcept |
Is this an array of aggregates that represents a 3D bounding box?
Definition at line 322 of file typedesc.h.
|
noexcept |
True if it's a floating-point type (versus a fundamentally integral type or something else like a string).
|
noexcept |
True if it's a signed type that allows for negative values.
|
inlinenoexcept |
Does this TypeDesc describe an array, whose length is specified?
Definition at line 201 of file typedesc.h.
|
inlinenoexcept |
Shortcut: is it UNKNOWN?
Definition at line 246 of file typedesc.h.
|
inlinenoexcept |
Does this TypeDesc describe an array, but whose length is not specified?
Definition at line 198 of file typedesc.h.
|
inlinenoexcept |
Is this a 2-vector aggregate (of the given type, float by default)?
Definition at line 301 of file typedesc.h.
|
inlinenoexcept |
Is this a 3-vector aggregate (of the given type, float by default)?
Definition at line 306 of file typedesc.h.
|
inlinenoexcept |
Is this a 4-vector aggregate (of the given type, float by default)?
Definition at line 311 of file typedesc.h.
|
inline |
Return true if the type is an aggregate type.
Definition at line 126 of file TypeDesc.h.
|
inline |
Return true if the type is an array type.
Definition at line 129 of file TypeDesc.h.
|
inline |
Return true if the type represents a closure.
Definition at line 141 of file TypeDesc.h.
|
inline |
Return true if the type is an aggregate of 2 floats.
Definition at line 132 of file TypeDesc.h.
|
inline |
Return true if the type is an aggregate of 3 floats.
Definition at line 135 of file TypeDesc.h.
|
inline |
Return true if the type is an aggregate of 4 floats.
Definition at line 138 of file TypeDesc.h.
|
inline |
Return true if the type is a scalar type.
Definition at line 123 of file TypeDesc.h.
|
inline |
Return true if the type represents a struct.
Definition at line 144 of file TypeDesc.h.
|
inlinenoexcept |
Return the number of elements: 1 if not an array, or the array length. Invalid to call this for arrays of undetermined size.
Definition at line 180 of file typedesc.h.
|
inlinenoexcept |
if (typedesc) is the same as asking whether it's not UNKNOWN.
Definition at line 249 of file typedesc.h.
|
inline |
Inequality operator.
Definition at line 157 of file TypeDesc.h.
|
inlinenoexcept |
Compare two TypeDesc values for inequality.
Definition at line 266 of file typedesc.h.
|
inline |
Less-than operator.
Definition at line 163 of file TypeDesc.h.
|
noexcept |
Test for lexicographic 'less', comes in handy for lots of STL containers and algorithms.
|
inline |
Equality operator.
Definition at line 151 of file TypeDesc.h.
|
inlinenoexcept |
Compare two TypeDesc values for equality.
Definition at line 259 of file typedesc.h.
|
inline |
Return just the underlying C scalar type, i.e., strip out the array-ness and the aggregateness.
Definition at line 232 of file typedesc.h.
|
inlinenoexcept |
Return the size, in bytes, of this type.
Definition at line 205 of file typedesc.h.
|
inline |
Return the unique id assigned to this type. The id is a hash of the given type name.
Definition at line 105 of file TypeDesc.h.
|
inlinenoexcept |
Demote the type to a non-array
Definition at line 329 of file typedesc.h.
|
friend |
TypeDesc's are equivalent if they are equal, or if their only inequality is differing vector semantics.
Definition at line 288 of file typedesc.h.
|
friend |
Compare a TypeDesc to a basetype (it's the same if it has the same base type and is not an aggregate or an array).
Definition at line 279 of file typedesc.h.
|
friend |
Definition at line 282 of file typedesc.h.
|
friend |
Definition at line 174 of file typedesc.h.
|
friend |
Compare a TypeDesc to a basetype (it's the same if it has the same base type and is not an aggregate or an array).
Definition at line 270 of file typedesc.h.
|
friend |
Definition at line 273 of file typedesc.h.
unsigned char TypeDesc::aggregate |
What kind of AGGREGATE is it?
Definition at line 126 of file typedesc.h.
int TypeDesc::arraylen |
Array length, 0 = not array, -1 = unsized.
Definition at line 129 of file typedesc.h.
unsigned char TypeDesc::basetype |
C data type at the heart of our type.
Definition at line 125 of file typedesc.h.
|
static |
Definition at line 177 of file TypeDesc.h.
unsigned char TypeDesc::reserved |
Reserved for future expansion.
Definition at line 128 of file typedesc.h.
|
static |
Definition at line 348 of file typedesc.h.
|
static |
Definition at line 347 of file typedesc.h.
|
static |
Definition at line 360 of file typedesc.h.
|
static |
Definition at line 351 of file typedesc.h.
|
static |
Definition at line 350 of file typedesc.h.
|
static |
Definition at line 359 of file typedesc.h.
|
static |
Definition at line 355 of file typedesc.h.
|
static |
Definition at line 356 of file typedesc.h.
|
static |
Definition at line 357 of file typedesc.h.
|
static |
Definition at line 354 of file typedesc.h.
|
static |
Definition at line 352 of file typedesc.h.
|
static |
Definition at line 361 of file typedesc.h.
|
static |
Definition at line 349 of file typedesc.h.
|
static |
Definition at line 358 of file typedesc.h.
|
static |
Definition at line 353 of file typedesc.h.
unsigned char TypeDesc::vecsemantics |
Hint: What does the aggregate represent?
Definition at line 127 of file typedesc.h.