HDK
|
#include <TypeDesc.h>
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, 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 } |
Public Member Functions | |
bool | operator== (const TypeDesc &rhs) const |
Equality operator overload. More... | |
bool | operator!= (const TypeDesc &rhs) const |
Inequality operator overload. More... | |
const string & | getName () const |
Return the name of the type. More... | |
unsigned char | getBaseType () const |
Return the basetype for the type. More... | |
int | getChannelIndex (char channel) const |
unsigned char | getSemantic () const |
Return the semantic for the type. More... | |
size_t | getSize () const |
bool | isEditable () 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... | |
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 |
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 const TypeDesc * | registerType (const string &name, unsigned char basetype, unsigned char semantic=SEMANTIC_NONE, size_t size=1, bool editable=true, const ChannelMap &channelMapping=ChannelMap()) |
static const TypeDesc * | get (const string &name) |
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 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. A unique type descriptor pointer is the identifier used for types, and can be used for type comparisons as well as getting more information about the type. All standard library data types are registered by default and their type descriptors can be accessed from the Type namespace, e.g. MaterialX::Type::FLOAT. If custom types are used they must be registered by calling TypeDesc::registerType(). Descriptors for registered types can be retreived using TypeDesc::get(), see below.
Definition at line 27 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 96 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 30 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 41 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 109 of file typedesc.h.
|
inlinenoexcept |
Construct from a BASETYPE and optional aggregateness, semantics, and arrayness.
Definition at line 132 of file typedesc.h.
|
inlinenoexcept |
Construct an array of a non-aggregate BASETYPE.
Definition at line 142 of file typedesc.h.
|
inlinenoexcept |
Construct an array from BASETYPE, AGGREGATE, and array length, with unspecified (or moot) semantic hints.
Definition at line 147 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) ```
|
inlinenoexcept |
Copy constructor.
Definition at line 166 of file typedesc.h.
|
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 191 of file typedesc.h.
const char* TypeDesc::c_str | ( | ) | const |
Return the name, for printing and whatnot. For example, "float", "int[5]", "normal"
|
inlinenoexcept |
Return the size, in bytes, of one element of this type (that is, ignoring whether it's an array).
Definition at line 230 of file typedesc.h.
|
inlinenoexcept |
Return the type of one element, i.e., strip out the array-ness.
Definition at line 224 of file typedesc.h.
|
inlinenoexcept |
Member version of equivalent.
Definition at line 296 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.
Get a type descriptor for given name. Returns an empty shared pointer if no type with the given name is found.
|
inline |
Return the basetype for the type.
Definition at line 74 of file TypeDesc.h.
int TypeDesc::getChannelIndex | ( | char | channel | ) | const |
Returns the channel index for the supplied channel name. Will return -1 on failure to find a matching index.
|
inline |
Return the name of the type.
Definition at line 71 of file TypeDesc.h.
|
inline |
Return the semantic for the type.
Definition at line 81 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 87 of file TypeDesc.h.
|
inlinenoexcept |
Does this TypeDesc describe an array?
Definition at line 196 of file typedesc.h.
|
inlinenoexcept |
Is this an array of aggregates that represents a 2D bounding box?
Definition at line 318 of file typedesc.h.
|
inlinenoexcept |
Is this an array of aggregates that represents a 3D bounding box?
Definition at line 324 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 203 of file typedesc.h.
|
inlinenoexcept |
Shortcut: is it UNKNOWN?
Definition at line 248 of file typedesc.h.
|
inlinenoexcept |
Does this TypeDesc describe an array, but whose length is not specified?
Definition at line 200 of file typedesc.h.
|
inlinenoexcept |
Is this a 2-vector aggregate (of the given type, float by default)?
Definition at line 303 of file typedesc.h.
|
inlinenoexcept |
Is this a 3-vector aggregate (of the given type, float by default)?
Definition at line 308 of file typedesc.h.
|
inlinenoexcept |
Is this a 4-vector aggregate (of the given type, float by default)?
Definition at line 313 of file typedesc.h.
|
inline |
Return true if the type is an aggregate type.
Definition at line 98 of file TypeDesc.h.
|
inline |
Return true if the type is an array type.
Definition at line 101 of file TypeDesc.h.
|
inline |
Return true if the type represents a closure.
Definition at line 113 of file TypeDesc.h.
|
inline |
Returns true if the type is editable by users. Editable types are allowed to be published as shader uniforms and hence must be presentable in a user interface.
Definition at line 92 of file TypeDesc.h.
|
inline |
Return true if the type is an aggregate of 2 floats.
Definition at line 104 of file TypeDesc.h.
|
inline |
Return true if the type is an aggregate of 3 floats.
Definition at line 107 of file TypeDesc.h.
|
inline |
Return true if the type is an aggregate of 4 floats.
Definition at line 110 of file TypeDesc.h.
|
inline |
Return true if the type is a scalar type.
Definition at line 95 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 182 of file typedesc.h.
|
inlinenoexcept |
if (typedesc) is the same as asking whether it's not UNKNOWN.
Definition at line 251 of file typedesc.h.
bool TypeDesc::operator!= | ( | const TypeDesc & | rhs | ) | const |
Inequality operator overload.
|
inlinenoexcept |
Compare two TypeDesc values for inequality.
Definition at line 268 of file typedesc.h.
|
noexcept |
Test for lexicographic 'less', comes in handy for lots of STL containers and algorithms.
bool TypeDesc::operator== | ( | const TypeDesc & | rhs | ) | const |
Equality operator overload.
|
inlinenoexcept |
Compare two TypeDesc values for equality.
Definition at line 261 of file typedesc.h.
|
static |
Register a type descriptor for a MaterialX data type. Throws an exception if a type with the same name is already registered.
|
inline |
Return just the underlying C scalar type, i.e., strip out the array-ness and the aggregateness.
Definition at line 234 of file typedesc.h.
|
inlinenoexcept |
Return the size, in bytes, of this type.
Definition at line 207 of file typedesc.h.
|
inlinenoexcept |
Demote the type to a non-array
Definition at line 331 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 290 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 281 of file typedesc.h.
|
friend |
Definition at line 284 of file typedesc.h.
|
friend |
Definition at line 176 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 272 of file typedesc.h.
|
friend |
Definition at line 275 of file typedesc.h.
unsigned char TypeDesc::aggregate |
What kind of AGGREGATE is it?
Definition at line 125 of file typedesc.h.
int TypeDesc::arraylen |
Array length, 0 = not array, -1 = unsized.
Definition at line 128 of file typedesc.h.
unsigned char TypeDesc::basetype |
C data type at the heart of our type.
Definition at line 124 of file typedesc.h.
unsigned char TypeDesc::reserved |
Reserved for future expansion.
Definition at line 127 of file typedesc.h.
|
static |
Definition at line 350 of file typedesc.h.
|
static |
Definition at line 349 of file typedesc.h.
|
static |
Definition at line 362 of file typedesc.h.
|
static |
Definition at line 353 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 357 of file typedesc.h.
|
static |
Definition at line 358 of file typedesc.h.
|
static |
Definition at line 359 of file typedesc.h.
|
static |
Definition at line 356 of file typedesc.h.
|
static |
Definition at line 354 of file typedesc.h.
|
static |
Definition at line 363 of file typedesc.h.
|
static |
Definition at line 351 of file typedesc.h.
|
static |
Definition at line 360 of file typedesc.h.
|
static |
Definition at line 355 of file typedesc.h.
unsigned char TypeDesc::vecsemantics |
Hint: What does the aggregate represent?
Definition at line 126 of file typedesc.h.