Open Inventor Release 2024.1.0
 
Loading...
Searching...
No Matches
SbDataTypeMacros.h File Reference
#include <Inventor/SbDataType.h>
#include <Inventor/STL/cassert>

Go to the source code of this file.

Macros

#define SB_DATATYPE_CALL(Function, Params, Type)
 This macro takes a function template with one argument and instanciate it according to the data type given.
 
#define SB_DATATYPE_CALL_ASSIGN(Function, Params, Dest, Type)
 This macro takes a function template with one argument returning one value, and instanciate it according to the data type given.
 

Macro Definition Documentation

◆ SB_DATATYPE_CALL

#define SB_DATATYPE_CALL (   Function,
  Params,
  Type 
)

This macro takes a function template with one argument and instanciate it according to the data type given.

A typical usage, is the case where you have a void* pointer and its type and you want to apply a function on elements of the pointer. By defining a function template like this :

template typename<T> void myFunc(void* data, size_t x)
{
T* myBuffer = static_cast<T>(data);
for ( size_t i = 0; i < x; i++ )
myBuffer[i] = (T)rand();
}

And then calling it like this:

SB_DATATYPE_CALL(myFunc, (myData, 10), type)
#define SB_DATATYPE_CALL(Function, Params, Type)
This macro takes a function template with one argument and instanciate it according to the data type ...

You avoid the use of a switch. Furthermore, because myFunc is a template and not a macro, it's still debuggable without problems.

Parameters
Functionis a function template
Paramsis a list of parameters enclosed by parens to pass to Function
Typeis a SbDataType

Definition at line 56 of file SbDataTypeMacros.h.

◆ SB_DATATYPE_CALL_ASSIGN

#define SB_DATATYPE_CALL_ASSIGN (   Function,
  Params,
  Dest,
  Type 
)

This macro takes a function template with one argument returning one value, and instanciate it according to the data type given.

See SB_DATATYPE_CALL for an usage example.

Parameters
Functionis a function template
Paramsis a list of parameters enclosed by parens to pass to Function
Destis filled with the return value of Function
Typeis a SbDataType

Definition at line 104 of file SbDataTypeMacros.h.