HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
c-typedesc.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenImageIO project.
2 // SPDX-License-Identifier: BSD-3-Clause
3 // https://github.com/OpenImageIO/oiio
4 
5 
6 #pragma once
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 /// OIIO_BASETYPE is a simple enum describing the base data types that
13 /// correspond (mostly) to the C/C++ built-in types.
15  OIIO_BASETYPE_UNKNOWN, ///< unknown type
16  OIIO_BASETYPE_NONE, ///< void/no type
17  OIIO_BASETYPE_UINT8, ///< 8-bit unsigned int values ranging from 0..255,
18  ///< (C/C++ `unsigned char`).
20  OIIO_BASETYPE_INT8, ///< 8-bit int values ranging from -128..127,
21  ///< (C/C++ `char`).
23  OIIO_BASETYPE_UINT16, ///< 16-bit int values ranging from 0..65535,
24  ///< (C/C++ `unsigned short`).
26  OIIO_BASETYPE_INT16, ///< 16-bit int values ranging from -32768..32767,
27  ///< (C/C++ `short`).
29  OIIO_BASETYPE_UINT32, ///< 32-bit unsigned int values (C/C++ `unsigned int`).
31  OIIO_BASETYPE_INT32, ///< signed 32-bit int values (C/C++ `int`).
33  OIIO_BASETYPE_UINT64, ///< 64-bit unsigned int values (C/C++
34  ///< `unsigned long long` on most architectures).
36  OIIO_BASETYPE_INT64, ///< signed 64-bit int values (C/C++ `long long`
37  ///< on most architectures).
39  OIIO_BASETYPE_HALF, ///< 16-bit IEEE floating point values (OpenEXR `half`).
40  OIIO_BASETYPE_FLOAT, ///< 32-bit IEEE floating point values, (C/C++ `float`).
41  OIIO_BASETYPE_DOUBLE, ///< 64-bit IEEE floating point values, (C/C++ `double`).
42  OIIO_BASETYPE_STRING, ///< Character string.
43  OIIO_BASETYPE_PTR, ///< A pointer value.
45 };
46 
47 /// OIIO_AGGREGATE describes whether our TypeDesc is a simple scalar of one
48 /// of the OIIO_BASETYPE's, or one of several simple OIIO_AGGREGATEs.
49 ///
50 /// Note that OIIO_AGGREGATEs and arrays are different. A `TypeDesc(FLOAT,3)`
51 /// is an array of three floats, a `TypeDesc(FLOAT,VEC3)` is a single
52 /// 3-component vector comprised of floats, and `TypeDesc(FLOAT,3,VEC3)`
53 /// is an array of 3 vectors, each of which is comprised of 3 floats.
56  = 1, ///< A single scalar value (such as a raw `int` or
57  ///< `float` in C). This is the default.
58  OIIO_AGGREGATE_VEC2 = 2, ///< 2 values representing a 2D vector.
59  OIIO_AGGREGATE_VEC3 = 3, ///< 3 values representing a 3D vector.
60  OIIO_AGGREGATE_VEC4 = 4, ///< 4 values representing a 4D vector.
61  OIIO_AGGREGATE_MATRIX33 = 9, ///< 9 values representing a 3x3 matrix.
62  OIIO_AGGREGATE_MATRIX44 = 16 ///< 16 values representing a 4x4 matrix.
63 };
64 
65 /// OIIO_VECSEMANTICS gives hints about what the data represent (for example,
66 /// if a spatial vector quantity should transform as a point, direction
67 /// vector, or surface normal).
69  OIIO_VECSEMANTICS_NOXFORM = 0, ///< No semantic hints.
70  OIIO_VECSEMANTICS_NOSEMANTICS = 0, ///< No semantic hints.
72  OIIO_VECSEMANTICS_POINT, ///< Point: a spatial location
73  OIIO_VECSEMANTICS_VECTOR, ///< Vector: a spatial direction
74  OIIO_VECSEMANTICS_NORMAL, ///< Normal: a surface normal
75  OIIO_VECSEMANTICS_TIMECODE, ///< indicates an `int[2]` representing the standard
76  ///< 4-byte encoding of an SMPTE timecode.
77  OIIO_VECSEMANTICS_KEYCODE, ///< indicates an `int[7]` representing the standard
78  ///< 28-byte encoding of an SMPTE keycode.
79  OIIO_VECSEMANTICS_RATIONAL ///< A VEC2 representing a rational number `val[0] / val[1]`
80 };
81 
82 /////////////////////////////////////////////////////////////////////////////
83 /// A TypeDesc describes simple data types.
84 ///
85 /// It frequently comes up (in my experience, with renderers and image
86 /// handling programs) that you want a way to describe data that is passed
87 /// through APIs through blind pointers. These are some simple classes
88 /// that provide a simple type descriptor system. This is not meant to
89 /// be comprehensive -- for example, there is no provision for structs,
90 /// unions, pointers, const, or 'nested' type definitions. Just simple
91 /// integer and floating point, *common* OIIO_AGGREGATEs such as 3-points,
92 /// and reasonably-lengthed arrays thereof.
93 ///
94 /////////////////////////////////////////////////////////////////////////////
95 
96 typedef struct {
97  unsigned char basetype;
98  unsigned char aggregate;
99  unsigned char vecsemantics;
100  unsigned char reserved;
101  int arraylen;
102 } OIIO_TypeDesc;
103 
104 /// Construct from a string (e.g., "float[3]"). If no valid
105 /// type could be assembled, set basetype to OIIO_BASETYPE_UNKNOWN.
106 ///
107 /// Examples:
108 /// ```
109 /// TypeDesc_from_string("int") == OIIO_TypeInt // C++ int32_t
110 /// TypeDesc_from_string("float") == OIIO_TypeFloat // C++ float
111 /// TypeDesc_from_string("uint16") == OIIO_TYPEUInt16 // C++ uint16_t
112 /// TypeDesc_from_string("float[4]") == FIXME: unimplemented!
113 /// ```
114 ///
116 OIIO_TypeDesc_from_string(const char* typestring);
117 
146 
147 #ifdef __cplusplus
148 }
149 #endif
OIIOC_API OIIO_TypeDesc OIIO_TypeKeycode
2 values representing a 2D vector.
Definition: c-typedesc.h:58
3 values representing a 3D vector.
Definition: c-typedesc.h:59
Point: a spatial location.
Definition: c-typedesc.h:72
#define OIIOC_API
Definition: export.h:77
OIIOC_API OIIO_TypeDesc OIIO_TypeNormal
OIIOC_API OIIO_TypeDesc OIIO_TypeMatrix
OIIOC_API OIIO_TypeDesc OIIO_TypeVector
OIIOC_API OIIO_TypeDesc OIIO_TypeVector4
32-bit IEEE floating point values, (C/C++ float).
Definition: c-typedesc.h:40
void/no type
Definition: c-typedesc.h:16
unsigned char basetype
Definition: c-typedesc.h:97
OIIOC_API OIIO_TypeDesc OIIO_TypeMatrix44
unsigned char vecsemantics
Definition: c-typedesc.h:99
64-bit IEEE floating point values, (C/C++ double).
Definition: c-typedesc.h:41
OIIO_AGGREGATE
Definition: c-typedesc.h:54
16-bit IEEE floating point values (OpenEXR half).
Definition: c-typedesc.h:39
OIIOC_API OIIO_TypeDesc OIIO_TypeMatrix33
Vector: a spatial direction.
Definition: c-typedesc.h:73
No semantic hints.
Definition: c-typedesc.h:69
32-bit unsigned int values (C/C++ unsigned int).
Definition: c-typedesc.h:29
OIIOC_API OIIO_TypeDesc OIIO_TypeString
OIIOC_API OIIO_TypeDesc OIIO_TypePointer
unknown type
Definition: c-typedesc.h:15
OIIOC_API OIIO_TypeDesc OIIO_TypeRational
OIIOC_API OIIO_TypeDesc OIIO_TypeFloat
OIIOC_API OIIO_TypeDesc OIIO_TypeUInt16
No semantic hints.
Definition: c-typedesc.h:70
OIIOC_API OIIO_TypeDesc OIIO_TypeVector2
OIIOC_API OIIO_TypeDesc OIIO_TypeInt8
OIIO_VECSEMANTICS
Definition: c-typedesc.h:68
OIIOC_API OIIO_TypeDesc OIIO_TypeHalf
OIIOC_API OIIO_TypeDesc OIIO_TypeUnknown
Character string.
Definition: c-typedesc.h:42
signed 32-bit int values (C/C++ int).
Definition: c-typedesc.h:31
OIIOC_API OIIO_TypeDesc OIIO_TypeUInt32
OIIOC_API OIIO_TypeDesc OIIO_TypeColor
4 values representing a 4D vector.
Definition: c-typedesc.h:60
OIIOC_API OIIO_TypeDesc OIIO_TypeFloat2
unsigned char aggregate
Definition: c-typedesc.h:98
Normal: a surface normal.
Definition: c-typedesc.h:74
OIIOC_API OIIO_TypeDesc OIIO_TypePoint
A pointer value.
Definition: c-typedesc.h:43
OIIOC_API OIIO_TypeDesc OIIO_TypeFloat4
OIIOC_API OIIO_TypeDesc OIIO_TypeInt32
OIIOC_API OIIO_TypeDesc OIIO_TypeDesc_from_string(const char *typestring)
OIIOC_API OIIO_TypeDesc OIIO_TypeUInt
A VEC2 representing a rational number val[0] / val[1]
Definition: c-typedesc.h:79
16 values representing a 4x4 matrix.
Definition: c-typedesc.h:62
OIIOC_API OIIO_TypeDesc OIIO_TypeTimecode
unsigned char reserved
Definition: c-typedesc.h:100
9 values representing a 3x3 matrix.
Definition: c-typedesc.h:61
OIIOC_API OIIO_TypeDesc OIIO_TypeVector2i
OIIOC_API OIIO_TypeDesc OIIO_TypeInt16
OIIOC_API OIIO_TypeDesc OIIO_TypeInt
OIIO_BASETYPE
Definition: c-typedesc.h:14
OIIOC_API OIIO_TypeDesc OIIO_TypeUInt8