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, UCHAR, UINT8 =UCHAR,
  CHAR, INT8 =CHAR, USHORT, UINT16 =USHORT,
  SHORT, INT16 =SHORT, UINT, UINT32 =UINT,
  INT, INT32 =INT, ULONGLONG, UINT64 =ULONGLONG,
  LONGLONG, INT64 =LONGLONG, 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 xform=NOXFORM)
 
constexpr TypeDesc (BASETYPE btype, int arraylength)
 
constexpr TypeDesc (BASETYPE btype, AGGREGATE agg, int arraylength)
 
constexpr TypeDesc (BASETYPE btype, AGGREGATE agg, VECSEMANTICS xform, int arraylength)
 
 TypeDesc (string_view typestring)
 
constexpr TypeDesc (const TypeDesc &t)
 Copy constructor. More...
 
const char * c_str () const
 
OIIO_CONSTEXPR14 size_t numelements () const
 
OIIO_CONSTEXPR14 size_t basevalues () const
 
constexpr bool is_array () const
 Does this TypeDesc describe an array? More...
 
constexpr bool is_unsized_array () const
 
constexpr bool is_sized_array () const
 Does this TypeDesc describe an array, whose length is specified? More...
 
size_t size () const
 
OIIO_CONSTEXPR14 TypeDesc elementtype () const
 
size_t elementsize () const
 
size_t basesize () const
 
bool is_floating_point () const
 
bool is_signed () const
 True if it's a signed type that allows for negative values. More...
 
constexpr bool is_unknown () const
 Shortcut: is it UNKNOWN? More...
 
constexpr operator bool () const
 if (typespec) is the same as asking whether it's not UNKNOWN. More...
 
size_t fromstring (string_view typestring)
 
constexpr bool operator== (const TypeDesc &t) const
 
constexpr bool operator!= (const TypeDesc &t) const
 
constexpr bool equivalent (const TypeDesc &b) const
 Member version of equivalent. More...
 
constexpr bool is_vec3 (BASETYPE b=FLOAT) const
 Is this a 3-vector aggregate (of the given type, float by default)? More...
 
constexpr bool is_vec4 (BASETYPE b=FLOAT) const
 Is this a 4-vector aggregate (of the given type, float by default)? More...
 
void unarray (void)
 
bool operator< (const TypeDesc &x) const
 

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
 What does the vec 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, TypeDesc t)
 
constexpr bool operator== (const TypeDesc &t, BASETYPE b)
 
constexpr bool operator== (BASETYPE b, const TypeDesc &t)
 
constexpr bool operator!= (const TypeDesc &t, BASETYPE b)
 
constexpr bool operator!= (BASETYPE b, const TypeDesc &t)
 
constexpr bool equivalent (const TypeDesc &a, const TypeDesc &b)
 

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 73 of file typedesc.h.

Member Enumeration Documentation

AGGREGATE describes whether our type is a simple scalar of one of the BASETYPE's, or one of several simple aggregates.

Enumerator
SCALAR 
VEC2 
VEC3 
VEC4 
MATRIX33 
MATRIX44 

Definition at line 84 of file typedesc.h.

BASETYPE is a simple enum for the C/C++ built-in types.

Enumerator
UNKNOWN 
NONE 
UCHAR 
UINT8 
CHAR 
INT8 
USHORT 
UINT16 
SHORT 
INT16 
UINT 
UINT32 
INT 
INT32 
ULONGLONG 
UINT64 
LONGLONG 
INT64 
HALF 
FLOAT 
DOUBLE 
STRING 
PTR 
LASTBASE 

Definition at line 76 of file typedesc.h.

VECSEMANTICS gives hints about what the data represent (for example, if a spatial vector, whether it should transform as a point, direction vector, or surface normal).

Enumerator
NOXFORM 
NOSEMANTICS 
COLOR 
POINT 
VECTOR 
NORMAL 
TIMECODE 
KEYCODE 
RATIONAL 

Definition at line 95 of file typedesc.h.

Constructor & Destructor Documentation

constexpr TypeDesc::TypeDesc ( BASETYPE  btype = UNKNOWN,
AGGREGATE  agg = SCALAR,
VECSEMANTICS  xform = NOXFORM 
)
inline

Construct from a BASETYPE and optional aggregateness and transformation rules.

Definition at line 115 of file typedesc.h.

constexpr TypeDesc::TypeDesc ( BASETYPE  btype,
int  arraylength 
)
inline

Construct an array of a non-aggregate BASETYPE.

Definition at line 125 of file typedesc.h.

constexpr TypeDesc::TypeDesc ( BASETYPE  btype,
AGGREGATE  agg,
int  arraylength 
)
inline

Construct an array from BASETYPE, AGGREGATE, and array length, with unspecified (or moot) vector transformation semantics.

Definition at line 133 of file typedesc.h.

constexpr TypeDesc::TypeDesc ( BASETYPE  btype,
AGGREGATE  agg,
VECSEMANTICS  xform,
int  arraylength 
)
inline

Construct an array from BASETYPE, AGGREGATE, VECSEMANTICS, and array length.

Definition at line 142 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.

constexpr TypeDesc::TypeDesc ( const TypeDesc t)
inline

Copy constructor.

Definition at line 155 of file typedesc.h.

Member Function Documentation

size_t TypeDesc::basesize ( ) const

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

OIIO_CONSTEXPR14 size_t TypeDesc::basevalues ( ) const
inline

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 180 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
inline

Return the size, in bytes, of one element of this type (that is, ignoring whether it's an array).

Definition at line 219 of file typedesc.h.

OIIO_CONSTEXPR14 TypeDesc TypeDesc::elementtype ( ) const
inline

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

Definition at line 213 of file typedesc.h.

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

Member version of equivalent.

Definition at line 285 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
inline

Does this TypeDesc describe an array?

Definition at line 185 of file typedesc.h.

bool TypeDesc::is_floating_point ( ) const

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

bool TypeDesc::is_signed ( ) const

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

constexpr bool TypeDesc::is_sized_array ( ) const
inline

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

Definition at line 192 of file typedesc.h.

constexpr bool TypeDesc::is_unknown ( ) const
inline

Shortcut: is it UNKNOWN?

Definition at line 237 of file typedesc.h.

constexpr bool TypeDesc::is_unsized_array ( ) const
inline

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

Definition at line 189 of file typedesc.h.

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

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

Definition at line 292 of file typedesc.h.

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

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

Definition at line 297 of file typedesc.h.

OIIO_CONSTEXPR14 size_t TypeDesc::numelements ( ) const
inline

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 171 of file typedesc.h.

constexpr TypeDesc::operator bool ( ) const
inline

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

Definition at line 240 of file typedesc.h.

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

Compare two TypeDesc values for inequality.

Definition at line 257 of file typedesc.h.

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

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

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

Compare two TypeDesc values for equality.

Definition at line 250 of file typedesc.h.

size_t TypeDesc::size ( void  ) const
inline

Return the size, in bytes, of this type.

Definition at line 196 of file typedesc.h.

void TypeDesc::unarray ( void  )
inline

Demote the type to a non-array

Definition at line 303 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 279 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 270 of file typedesc.h.

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

Definition at line 273 of file typedesc.h.

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

Definition at line 165 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 261 of file typedesc.h.

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

Definition at line 264 of file typedesc.h.

Member Data Documentation

unsigned char TypeDesc::aggregate

What kind of AGGREGATE is it?

Definition at line 108 of file typedesc.h.

int TypeDesc::arraylen

Array length, 0 = not array, -1 = unsized.

Definition at line 111 of file typedesc.h.

unsigned char TypeDesc::basetype

C data type at the heart of our type.

Definition at line 107 of file typedesc.h.

unsigned char TypeDesc::reserved

Reserved for future expansion.

Definition at line 110 of file typedesc.h.

const TypeDesc TypeDesc::TypeColor
static

Definition at line 316 of file typedesc.h.

const TypeDesc TypeDesc::TypeFloat
static

Definition at line 315 of file typedesc.h.

const TypeDesc TypeDesc::TypeFloat4
static

Definition at line 328 of file typedesc.h.

const TypeDesc TypeDesc::TypeHalf
static

Definition at line 319 of file typedesc.h.

const TypeDesc TypeDesc::TypeInt
static

Definition at line 318 of file typedesc.h.

const TypeDesc TypeDesc::TypeKeyCode
static

Definition at line 327 of file typedesc.h.

const TypeDesc TypeDesc::TypeMatrix
static

Definition at line 323 of file typedesc.h.

const TypeDesc TypeDesc::TypeMatrix33
static

Definition at line 324 of file typedesc.h.

const TypeDesc TypeDesc::TypeMatrix44
static

Definition at line 325 of file typedesc.h.

const TypeDesc TypeDesc::TypeNormal
static

Definition at line 322 of file typedesc.h.

const TypeDesc TypeDesc::TypePoint
static

Definition at line 320 of file typedesc.h.

const TypeDesc TypeDesc::TypeRational
static

Definition at line 329 of file typedesc.h.

const TypeDesc TypeDesc::TypeString
static

Definition at line 317 of file typedesc.h.

const TypeDesc TypeDesc::TypeTimeCode
static

Definition at line 326 of file typedesc.h.

const TypeDesc TypeDesc::TypeVector
static

Definition at line 321 of file typedesc.h.

unsigned char TypeDesc::vecsemantics

What does the vec represent?

Definition at line 109 of file typedesc.h.


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