DIPlib Documentation - ©1995-2009 Quantitative Imaging Group, Delft University of Technology.

# tpi.h

Type iterator

## SYNOPSIS

`#include "dip_tpi.h"`

## FUNCTION

Type iterator. For each data type specified by the define `DIP_TPI_ALLOW`, `dip_tpi.h` will include the file specified by the define `DIP_TPI_FILE`. If `DIP_TPI_ALLOW` is not defined the file will be included for all data types. `DIP_TPI_TYPES` must be defined as a logical OR of identifier flags and identifier group flags, as given in DIPlib's data types and the table below. During each "iteration" the main symbols defined by `dip_tpi.h` are `DIP_TPI`, `DIP_TPI_DATA_TYPE`, `DIP_TPI_IDENTIFIER` and `DIP_TPI_EXTENSION`. The following table shows how these are defined for each data type:

`DIP_TPI` | `DIP_TPI_DATA_TYPE` | `DIP_TPI_IDENTIFIER` | `DIP_TPI_EXTENSION`
`dip_bin8` | `DIP_DT_BIN8` | `DIP_DTID_BIN8` | `_b8`
`dip_bin16` | `DIP_DT_BIN16` | `DIP_DTID_BIN16` | `_b16`
`dip_bin32` | `DIP_DT_BIN32` | `DIP_DTID_BIN32` | `_b32`
`dip_uint8` | `DIP_DT_UINT8` | `DIP_DTID_UINT8` | `_u8`
`dip_uint16` | `DIP_DT_UINT16` | `DIP_DTID_UINT16` | `_u16`
`dip_uint32` | `DIP_DT_UINT32` | `DIP_DTID_UINT32` | `_u32`
`dip_sint8` | `DIP_DT_SINT8` | `DIP_DTID_SINT8` | `_s8`
`dip_sint16` | `DIP_DT_SINT16` | `DIP_DTID_SINT16` | `_s16`
`dip_sint32` | `DIP_DT_SINT32` | `DIP_DTID_SINT32` | `_s32`
`dip_sfloat` | `DIP_DT_SFLOAT` | `DIP_DTID_SFLOAT` | `_sfl`
`dip_dfloat` | `DIP_DT_DFLOAT` | `DIP_DTID_DFLOAT` | `_dfl`
`dip_scomplex` | `DIP_DT_SCOMPLEX` | `DIP_DTID_SCOMPLEX` | `_scx`
`dip_dcomplex` | `DIP_DT_DCOMPLEX` | `DIP_DTID_DCOMPLEX` | `_dcx`

Using this include file it is possible to compile source code for different data types. We recommend that instead of splitting your code into two files, one for generic code and one for type specific code, that you use `dip_tpi.h` to let the source file include itself. This also prevents dependency problems with makefiles. A source file that includes itself through `dip_tpi.h` should have the following format:

    contents of example.c:
    #ifndef DIP_TPI

    #include "diplib.h"

    #define DIP_TPI_FILE "example.c"
    #include "dip_tpi.h"

    /* This is where the generic code should be */

    #else

    /* This is where the type specific code should be */

    #endif

In addition to the main defines as described above, there are a number of macro's that are defined by `dip_tpi.h`:

`DIP_TPI_FUNC` ( function name ) | attaches the current type suffix to the function name.
`DIP_TPI_DEFINE` ( function name ) | equivalent to: `dip_Error DIP_TPI_FUNC( function name )` useful for function definitions.
`DIP_TPI_DECLARE` ( function name ) | equivalent to: `dip_Error DIP_TPI_FUNC( function name )` useful for function declarations. Don't forget the trailing ";".
`DIP_TPI_NAME` ( function name ) | attaches the current type suffix to the function name and puts double quotes around the result, thus creating a string.

There are also a couple of defines that are only available for some of the data types:

When DIP_TPI is |
`dip_sfloat` | `DIP_TPI_CAST_R2C` is defined as `dip_scomplex`
`dip_dfloat` | `DIP_TPI_CAST_R2C` is defined as `dip_dcomplex`
`dip_scomplex` | `DIP_TPI_CAST_C2R` is defined as `dip_sfloat`
`dip_dcomplex` | `DIP_TPI_CAST_C2R` is defined as `dip_dfloat`

Other type iterators may be created by making a copy of the `dip_tpi.h` file and replacing `DIP_TPI` throughout the file by a different name for the new type iterator.

## ARGUMENTS

Name | Description
`DIP_TPI_ALLOW` | logical OR of data type identifier and identifier group flags to indicate for which data types the file should be included
`DIP_TPI_FILE` | Name of the file to be included by `dip_tpi.h`

## SEE ALSO

DIPlib's data types

`DataTypeGetInfo`, `ovl.h`

DIPlib on-line documentation | Function reference | Global function index