TypeDesc Struct Reference

#include <typedesc.h>

List of all members.

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,
  MATRIX44 = 16
}
enum  VECSEMANTICS {
  NOXFORM = 0, COLOR, POINT, VECTOR,
  NORMAL
}

Public Member Functions

 TypeDesc (BASETYPE btype=UNKNOWN, AGGREGATE agg=SCALAR, VECSEMANTICS xform=NOXFORM)
 TypeDesc (BASETYPE btype, int arraylength)
 TypeDesc (BASETYPE btype, AGGREGATE agg, int arraylength)
 TypeDesc (BASETYPE btype, AGGREGATE agg, VECSEMANTICS xform, int arraylength)
 TypeDesc (const char *typestring)
const char * c_str () const
size_t numelements () const
size_t size () const
TypeDesc elementtype () const
size_t elementsize () const
size_t basesize () const
int fromstring (const char *typestring, char *shortname=NULL)
bool operator== (const TypeDesc &t) const
bool operator!= (const TypeDesc &t) const
void unarray (void)

Public Attributes

unsigned char basetype
 C data type at the heart of our type.
unsigned char aggregate
 What kind of AGGREGATE is it?
unsigned char vecsemantics
 What does the vec represent?
unsigned char reserved
 Reserved for future expansion.
int arraylen
 Array length, 0 = not array, -1 = unsized.

Static Public Attributes

static const TypeDesc TypeFloat
static const TypeDesc TypeColor
static const TypeDesc TypeString
static const TypeDesc TypeInt
static const TypeDesc TypePoint
static const TypeDesc TypeVector
static const TypeDesc TypeNormal
static const TypeDesc TypeMatrix

Friends

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

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.


Member Enumeration Documentation

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

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

VECSEMANTICS describes, for non-SCALAR aggregates, whether our type is like a color (raw values) or if it has coordinate transformation rules similar to a point, vector (direction), or surface normal.


Constructor & Destructor Documentation

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

Construct from a BASETYPE and optional aggregateness and transformation rules.

TypeDesc::TypeDesc ( BASETYPE  btype,
int  arraylength 
) [inline]

Construct an array of a non-aggregate BASETYPE.

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.

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

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

TypeDesc::TypeDesc ( const char *  typestring  ) 

Construct from a string (e.g., "float[3]"). If no valid type could be assembled, set base to UNKNOWN.


Member Function Documentation

size_t TypeDesc::basesize (  )  const

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

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

TypeDesc TypeDesc::elementtype (  )  const [inline]

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

int TypeDesc::fromstring ( const char *  typestring,
char *  shortname = NULL 
)

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. If shortname is not NULL, store the word(s) in the string after the type (presumably the variable name) in shortname.

size_t TypeDesc::numelements (  )  const [inline]

Return the number of elements: 1 if not an array, or the array length.

bool TypeDesc::operator!= ( const TypeDesc t  )  const [inline]

Compare two TypeDesc values for inequality.

bool TypeDesc::operator== ( const TypeDesc t  )  const [inline]

Compare two TypeDesc values for equality.

size_t TypeDesc::size (  )  const [inline]

Return the size, in bytes, of this type.

void TypeDesc::unarray ( void   )  [inline]

Demote the type to a non-array


Friends And Related Function Documentation

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

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


Member Data Documentation

unsigned char TypeDesc::aggregate

What kind of AGGREGATE is it?

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

unsigned char TypeDesc::basetype

C data type at the heart of our type.

unsigned char TypeDesc::reserved

Reserved for future expansion.

unsigned char TypeDesc::vecsemantics

What does the vec represent?


The documentation for this struct was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Tue Oct 27 06:30:40 2009 for OpenImageIO by  doxygen 1.6.1