HDK
|
#include <typedesc.h>
Public Types | |
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 } |
Public Member Functions | |
constexpr | TypeDesc (BASETYPE btype=UNKNOWN, AGGREGATE agg=SCALAR, VECSEMANTICS semantics=NOSEMANTICS, int arraylen=0) noexcept |
constexpr | TypeDesc (BASETYPE btype, int arraylen) noexcept |
Construct an array of a non-aggregate BASETYPE. More... | |
constexpr | TypeDesc (BASETYPE btype, AGGREGATE agg, int arraylen) noexcept |
TypeDesc (string_view typestring) | |
constexpr | TypeDesc (const TypeDesc &t) noexcept |
Copy constructor. More... | |
const char * | c_str () const |
OIIO_CONSTEXPR14 size_t | numelements () const noexcept |
OIIO_CONSTEXPR14 size_t | basevalues () const noexcept |
constexpr bool | is_array () const noexcept |
Does this TypeDesc describe an array? More... | |
constexpr bool | is_unsized_array () const noexcept |
constexpr bool | is_sized_array () const noexcept |
Does this TypeDesc describe an array, whose length is specified? More... | |
size_t | size () const noexcept |
OIIO_CONSTEXPR14 TypeDesc | elementtype () const noexcept |
size_t | elementsize () const noexcept |
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... | |
constexpr bool | is_unknown () const noexcept |
Shortcut: is it UNKNOWN? More... | |
constexpr | operator bool () const noexcept |
if (typedesc) is the same as asking whether it's not UNKNOWN. More... | |
size_t | fromstring (string_view typestring) |
constexpr bool | operator== (const TypeDesc &t) const noexcept |
constexpr bool | operator!= (const TypeDesc &t) const noexcept |
constexpr bool | equivalent (const TypeDesc &b) const noexcept |
Member version of equivalent. More... | |
constexpr bool | is_vec2 (BASETYPE b=FLOAT) const noexcept |
Is this a 2-vector aggregate (of the given type, float by default)? More... | |
constexpr bool | is_vec3 (BASETYPE b=FLOAT) const noexcept |
Is this a 3-vector aggregate (of the given type, float by default)? More... | |
constexpr bool | is_vec4 (BASETYPE b=FLOAT) const noexcept |
Is this a 4-vector aggregate (of the given type, float by default)? More... | |
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 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) |
constexpr bool | operator== (const TypeDesc &t, BASETYPE b) noexcept |
constexpr bool | operator== (BASETYPE b, const TypeDesc &t) noexcept |
constexpr bool | operator!= (const TypeDesc &t, BASETYPE b) noexcept |
constexpr bool | operator!= (BASETYPE b, const TypeDesc &t) noexcept |
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.
Definition at line 53 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 |
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.
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 131 of file typedesc.h.
Construct an array of a non-aggregate BASETYPE.
Definition at line 141 of file typedesc.h.
Construct an array from BASETYPE, AGGREGATE, and array length, with unspecified (or moot) semantic hints.
Definition at line 146 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) ```
Copy constructor.
Definition at line 165 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 190 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 229 of file typedesc.h.
|
inlinenoexcept |
Return the type of one element, i.e., strip out the array-ness.
Definition at line 223 of file typedesc.h.
Member version of equivalent.
Definition at line 295 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.
|
inlinenoexcept |
Does this TypeDesc describe an array?
Definition at line 195 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 202 of file typedesc.h.
|
inlinenoexcept |
Shortcut: is it UNKNOWN?
Definition at line 247 of file typedesc.h.
|
inlinenoexcept |
Does this TypeDesc describe an array, but whose length is not specified?
Definition at line 199 of file typedesc.h.
Is this a 2-vector aggregate (of the given type, float by default)?
Definition at line 302 of file typedesc.h.
Is this a 3-vector aggregate (of the given type, float by default)?
Definition at line 307 of file typedesc.h.
Is this a 4-vector aggregate (of the given type, float by default)?
Definition at line 312 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 181 of file typedesc.h.
|
inlinenoexcept |
if (typedesc) is the same as asking whether it's not UNKNOWN.
Definition at line 250 of file typedesc.h.
|
inlinenoexcept |
Compare two TypeDesc values for inequality.
Definition at line 267 of file typedesc.h.
Test for lexicographic 'less', comes in handy for lots of STL containers and algorithms.
Compare two TypeDesc values for equality.
Definition at line 260 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 233 of file typedesc.h.
|
inlinenoexcept |
Return the size, in bytes, of this type.
Definition at line 206 of file typedesc.h.
Demote the type to a non-array
Definition at line 318 of file typedesc.h.
TypeDesc's are equivalent if they are equal, or if their only inequality is differing vector semantics.
Definition at line 289 of file typedesc.h.
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 280 of file typedesc.h.
Definition at line 283 of file typedesc.h.
Definition at line 175 of file typedesc.h.
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 271 of file typedesc.h.
Definition at line 274 of file typedesc.h.
unsigned char TypeDesc::aggregate |
What kind of AGGREGATE is it?
Definition at line 124 of file typedesc.h.
int TypeDesc::arraylen |
Array length, 0 = not array, -1 = unsized.
Definition at line 127 of file typedesc.h.
unsigned char TypeDesc::basetype |
C data type at the heart of our type.
Definition at line 123 of file typedesc.h.
unsigned char TypeDesc::reserved |
Reserved for future expansion.
Definition at line 126 of file typedesc.h.
Definition at line 336 of file typedesc.h.
Definition at line 335 of file typedesc.h.
Definition at line 348 of file typedesc.h.
Definition at line 339 of file typedesc.h.
Definition at line 338 of file typedesc.h.
Definition at line 347 of file typedesc.h.
Definition at line 343 of file typedesc.h.
Definition at line 344 of file typedesc.h.
Definition at line 345 of file typedesc.h.
Definition at line 342 of file typedesc.h.
Definition at line 340 of file typedesc.h.
Definition at line 349 of file typedesc.h.
Definition at line 337 of file typedesc.h.
Definition at line 346 of file typedesc.h.
Definition at line 341 of file typedesc.h.
unsigned char TypeDesc::vecsemantics |
Hint: What does the aggregate represent?
Definition at line 125 of file typedesc.h.