Inventor/helpers/SbDataTypeMacros.h File Reference

#include <Inventor/SbDataType.h>
#include <Inventor/STL/cassert>

Go to the source code of this file.

Defines

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

Define Documentation

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

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

Parameters:
Function is a function template
Params is a list of parameters enclosed by parens to pass to Function
Type is a SbDataType
#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:
Function is a function template
Params is a list of parameters enclosed by parens to pass to Function
Dest is filled with the return value of Function
Type is a SbDataType

Open Inventor by FEI reference manual, generated on 19 Aug 2019
Copyright © FEI S.A.S. All rights reserved.
http://www.openinventor.com/