HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TypeDesc Struct Reference

#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
 

Detailed Description

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.

Member Enumeration Documentation

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.

Enumerator
SCALAR 

A single scalar value (such as a raw int or float in C). This is the default.

VEC2 

2 values representing a 2D vector.

VEC3 

3 values representing a 3D vector.

VEC4 

4 values representing a 4D vector.

MATRIX33 

9 values representing a 3x3 matrix.

MATRIX44 

16 values representing a 4x4 matrix.

Definition at line 96 of file typedesc.h.

BASETYPE is a simple enum describing the base data types that correspond (mostly) to the C/C++ built-in types.

Enumerator
UNKNOWN 

unknown type

NONE 

void/no type

UINT8 

8-bit unsigned int values ranging from 0..255, (C/C++ unsigned char).

UCHAR 
INT8 

8-bit int values ranging from -128..127, (C/C++ char).

CHAR 
UINT16 

16-bit int values ranging from 0..65535, (C/C++ unsigned short).

USHORT 
INT16 

16-bit int values ranging from -32768..32767, (C/C++ short).

SHORT 
UINT32 

32-bit unsigned int values (C/C++ unsigned int).

UINT 
INT32 

signed 32-bit int values (C/C++ int).

INT 
UINT64 

64-bit unsigned int values (C/C++ unsigned long long on most architectures).

ULONGLONG 
INT64 

signed 64-bit int values (C/C++ long long on most architectures).

LONGLONG 
HALF 

16-bit IEEE floating point values (OpenEXR half).

FLOAT 

32-bit IEEE floating point values, (C/C++ float).

DOUBLE 

64-bit IEEE floating point values, (C/C++ double).

STRING 

Character string.

PTR 

A pointer value.

LASTBASE 

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).

Enumerator
NOXFORM 

No semantic hints.

NOSEMANTICS 

No semantic hints.

COLOR 

Color.

POINT 

Point: a spatial location.

VECTOR 

Vector: a spatial direction.

NORMAL 

Normal: a surface normal.

TIMECODE 

indicates an int[2] representing the standard 4-byte encoding of an SMPTE timecode.

KEYCODE 

indicates an int[7] representing the standard 28-byte encoding of an SMPTE keycode.

RATIONAL 

A VEC2 representing a rational number val[0] / val[1]

Definition at line 109 of file typedesc.h.

Constructor & Destructor Documentation

constexpr TypeDesc::TypeDesc ( BASETYPE  btype = UNKNOWN,
AGGREGATE  agg = SCALAR,
VECSEMANTICS  semantics = NOSEMANTICS,
int  arraylen = 0 
)
inlinenoexcept

Construct from a BASETYPE and optional aggregateness, semantics, and arrayness.

Definition at line 131 of file typedesc.h.

constexpr TypeDesc::TypeDesc ( BASETYPE  btype,
int  arraylen 
)
inlinenoexcept

Construct an array of a non-aggregate BASETYPE.

Definition at line 141 of file typedesc.h.

constexpr TypeDesc::TypeDesc ( BASETYPE  btype,
AGGREGATE  agg,
int  arraylen 
)
inlinenoexcept

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) ```

constexpr TypeDesc::TypeDesc ( const TypeDesc t)
inlinenoexcept

Copy constructor.

Definition at line 165 of file typedesc.h.

Member Function Documentation

size_t TypeDesc::basesize ( ) const
noexcept

Return the base type size, i.e., stripped of both array-ness and aggregateness.

static BASETYPE TypeDesc::basetype_merge ( TypeDesc  a,
TypeDesc  b 
)
static

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.

OIIO_CONSTEXPR14 size_t TypeDesc::basevalues ( ) const
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"

size_t TypeDesc::elementsize ( ) const
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.

OIIO_CONSTEXPR14 TypeDesc TypeDesc::elementtype ( ) const
inlinenoexcept

Return the type of one element, i.e., strip out the array-ness.

Definition at line 223 of file typedesc.h.

constexpr bool TypeDesc::equivalent ( const TypeDesc b) const
inlinenoexcept

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.

constexpr bool TypeDesc::is_array ( ) const
inlinenoexcept

Does this TypeDesc describe an array?

Definition at line 195 of file typedesc.h.

bool TypeDesc::is_floating_point ( ) const
noexcept

True if it's a floating-point type (versus a fundamentally integral type or something else like a string).

bool TypeDesc::is_signed ( ) const
noexcept

True if it's a signed type that allows for negative values.

constexpr bool TypeDesc::is_sized_array ( ) const
inlinenoexcept

Does this TypeDesc describe an array, whose length is specified?

Definition at line 202 of file typedesc.h.

constexpr bool TypeDesc::is_unknown ( ) const
inlinenoexcept

Shortcut: is it UNKNOWN?

Definition at line 247 of file typedesc.h.

constexpr bool TypeDesc::is_unsized_array ( ) const
inlinenoexcept

Does this TypeDesc describe an array, but whose length is not specified?

Definition at line 199 of file typedesc.h.

constexpr bool TypeDesc::is_vec2 ( BASETYPE  b = FLOAT) const
inlinenoexcept

Is this a 2-vector aggregate (of the given type, float by default)?

Definition at line 302 of file typedesc.h.

constexpr bool TypeDesc::is_vec3 ( BASETYPE  b = FLOAT) const
inlinenoexcept

Is this a 3-vector aggregate (of the given type, float by default)?

Definition at line 307 of file typedesc.h.

constexpr bool TypeDesc::is_vec4 ( BASETYPE  b = FLOAT) const
inlinenoexcept

Is this a 4-vector aggregate (of the given type, float by default)?

Definition at line 312 of file typedesc.h.

OIIO_CONSTEXPR14 size_t TypeDesc::numelements ( ) const
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.

constexpr TypeDesc::operator bool ( ) const
inlinenoexcept

if (typedesc) is the same as asking whether it's not UNKNOWN.

Definition at line 250 of file typedesc.h.

constexpr bool TypeDesc::operator!= ( const TypeDesc t) const
inlinenoexcept

Compare two TypeDesc values for inequality.

Definition at line 267 of file typedesc.h.

bool TypeDesc::operator< ( const TypeDesc x) const
noexcept

Test for lexicographic 'less', comes in handy for lots of STL containers and algorithms.

constexpr bool TypeDesc::operator== ( const TypeDesc t) const
inlinenoexcept

Compare two TypeDesc values for equality.

Definition at line 260 of file typedesc.h.

constexpr TypeDesc TypeDesc::scalartype ( ) const
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.

size_t TypeDesc::size ( void  ) const
inlinenoexcept

Return the size, in bytes, of this type.

Definition at line 206 of file typedesc.h.

void TypeDesc::unarray ( void  )
inlinenoexcept

Demote the type to a non-array

Definition at line 318 of file typedesc.h.

Friends And Related Function Documentation

constexpr bool equivalent ( const TypeDesc a,
const TypeDesc b 
)
friend

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.

constexpr bool operator!= ( const TypeDesc t,
BASETYPE  b 
)
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 280 of file typedesc.h.

constexpr bool operator!= ( BASETYPE  b,
const TypeDesc t 
)
friend

Definition at line 283 of file typedesc.h.

std::ostream& operator<< ( std::ostream &  o,
const TypeDesc t 
)
friend

Definition at line 175 of file typedesc.h.

constexpr bool operator== ( const TypeDesc t,
BASETYPE  b 
)
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 271 of file typedesc.h.

constexpr bool operator== ( BASETYPE  b,
const TypeDesc t 
)
friend

Definition at line 274 of file typedesc.h.

Member Data Documentation

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.

const TypeDesc TypeDesc::TypeColor
static

Definition at line 336 of file typedesc.h.

const TypeDesc TypeDesc::TypeFloat
static

Definition at line 335 of file typedesc.h.

const TypeDesc TypeDesc::TypeFloat4
static

Definition at line 348 of file typedesc.h.

const TypeDesc TypeDesc::TypeHalf
static

Definition at line 339 of file typedesc.h.

const TypeDesc TypeDesc::TypeInt
static

Definition at line 338 of file typedesc.h.

const TypeDesc TypeDesc::TypeKeyCode
static

Definition at line 347 of file typedesc.h.

const TypeDesc TypeDesc::TypeMatrix
static

Definition at line 343 of file typedesc.h.

const TypeDesc TypeDesc::TypeMatrix33
static

Definition at line 344 of file typedesc.h.

const TypeDesc TypeDesc::TypeMatrix44
static

Definition at line 345 of file typedesc.h.

const TypeDesc TypeDesc::TypeNormal
static

Definition at line 342 of file typedesc.h.

const TypeDesc TypeDesc::TypePoint
static

Definition at line 340 of file typedesc.h.

const TypeDesc TypeDesc::TypeRational
static

Definition at line 349 of file typedesc.h.

const TypeDesc TypeDesc::TypeString
static

Definition at line 337 of file typedesc.h.

const TypeDesc TypeDesc::TypeTimeCode
static

Definition at line 346 of file typedesc.h.

const TypeDesc TypeDesc::TypeVector
static

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.


The documentation for this struct was generated from the following file: