module #include "diplib/overload.h"
Overloading Help with instantiating function templates and class templates for different pixel data types.
Contents
- Reference
These preprocessor macros insert a block of code that
calls or retrieves a function pointer to the right instance of a
template, according to a dip::DataType
argument (or create an object of
a template class). For example, the code
DIP_OVL_CALL_ALL( myFunc, ( param1, param2 ), datatype );
causes a call to myFunc( param1, param2 )
, where myFunc
is
a function template. The template will be specialized to
whichever value the variable datatype
has at run time. The
compiler generates instances of your template for all possible
values of datatype
. If you want to restrict the allowed data
types, use a macro ending in other than _ALL
. For example, the
macro DIP_OVL_CALL_REAL
only allows integer and floating point
data types (not binary nor complex types).
Note that the function parameters are the same for all instances
of the template function; the template parameter is not used in the
function’s parameter list. This is the only way that generic code
(i.e. code that works with pixels of any data type) can work.
You can think of param1
above being of type void*
or dip::Image
,
for example.
DIP_OVL_NEW_ALL
and friends work similarly, but create a new object
of a template class with operator new
. For such an assignment to work,
the template class must have a base class that is not a template, and
the object must be referred to through a pointer to its base class. The
result of new
is cast to the declaration type of the variable being
assigned to, so that one can assign e.g. into a std::unique_ptr
.
There are four groups of macros defined in diplib/overload.h
:
DIP_OVL_CALL_xxx
calls a function, discarding any return value.DIP_OVL_CALL_ASSIGN_xxx
calls a function, assigning the return value in a variable.DIP_OVL_ASSIGN_xxx
assigns a function pointer to a variable, without calling the function.DIP_OVL_NEW_xxx
allocates an object of a templated class, assigns to pointer to a variable.
Each of the four groups of macros exist in the following flavors:
Macro name xxx |
Corresponding dip::DataType::Classes value |
---|---|
BIN |
dip::DataType::Class_Binary |
UINT |
dip::DataType::Class_UInt |
SINT |
dip::DataType::Class_SInt |
INTEGER |
dip::DataType::Class_Integer |
INT_OR_BIN |
dip::DataType::Class_IntOrBin |
FLOAT |
dip::DataType::Class_Float |
COMPLEX |
dip::DataType::Class_Complex |
FLEX |
dip::DataType::Class_Flex |
FLEXBIN |
dip::DataType::Class_FlexBin |
UNSIGNED |
dip::DataType::Class_Unsigned |
SIGNED |
dip::DataType::Class_Signed |
REAL |
dip::DataType::Class_Real |
SIGNEDREAL |
dip::DataType::Class_SignedReal |
NONBINARY |
dip::DataType::Class_NonBinary |
NONCOMPLEX |
dip::DataType::Class_NonComplex |
ALL |
dip::DataType::Class_All |
Macros
- #define DIP_OVL_CALL_BINARY
- Calls the overloaded function for the binary type.
- #define DIP_OVL_CALL_UINT
- Calls the overloaded function for all unsigned integer types.
- #define DIP_OVL_CALL_SINT
- Calls the overloaded function for all signed integer types.
- #define DIP_OVL_CALL_FLOAT
- Calls the overloaded function for all float types.
- #define DIP_OVL_CALL_COMPLEX
- Calls the overloaded function for all complex types.
- #define DIP_OVL_CALL_INTEGER
- Calls the overloaded function for all integer types.
- #define DIP_OVL_CALL_INT_OR_BIN
- Calls the overloaded function for all integer and binary types.
- #define DIP_OVL_CALL_UNSIGNED
- Calls the overloaded function for all unsigned types.
- #define DIP_OVL_CALL_SIGNED
- Calls the overloaded function for all signed (integer + float + complex) types.
- #define DIP_OVL_CALL_REAL
- Calls the overloaded function for all real (integer + float) types.
- #define DIP_OVL_CALL_SIGNEDREAL
- Calls the overloaded function for all signed real (integer + float) types.
- #define DIP_OVL_CALL_NONCOMPLEX
- Calls the overloaded function for all non-complex types.
- #define DIP_OVL_CALL_FLEX
- Calls the overloaded function for all floating-point and complex types.
- #define DIP_OVL_CALL_FLEXBIN
- Calls the overloaded function for all floating-point, complex and binary types.
- #define DIP_OVL_CALL_NONBINARY
- Calls the overloaded function for all types but binary.
- #define DIP_OVL_CALL_ALL
- Calls the overloaded function for all types.
- #define DIP_OVL_CALL_ASSIGN_BINARY
- Calls the overloaded function for the binary type, and assigns the output value to variable
x
. - #define DIP_OVL_CALL_ASSIGN_UINT
- Calls the overloaded function for all unsigned integer types, and assigns the output value to variable
x
. - #define DIP_OVL_CALL_ASSIGN_SINT
- Calls the overloaded function for all signed integer types, and assigns the output value to variable
x
. - #define DIP_OVL_CALL_ASSIGN_FLOAT
- Calls the overloaded function for all float types, and assigns the output value to variable
x
. - #define DIP_OVL_CALL_ASSIGN_COMPLEX
- Calls the overloaded function for all complex types, and assigns the output value to variable
x
. - #define DIP_OVL_CALL_ASSIGN_INTEGER
- Calls the overloaded function for all integer types, and assigns the output value to variable
x
. - #define DIP_OVL_CALL_ASSIGN_INT_OR_BIN
- Calls the overloaded function for all integer and binary types, and assigns the output value to variable
x
. - #define DIP_OVL_CALL_ASSIGN_UNSIGNED
- Calls the overloaded function function for all unsigned types, and assigns the output value to variable
x
. - #define DIP_OVL_CALL_ASSIGN_SIGNED
- Calls the overloaded function for all signed (integer + float + complex) types, and assigns the output value to variable
x
. - #define DIP_OVL_CALL_ASSIGN_REAL
- Calls the overloaded function for all real (integer + float) types, and assigns the output value to variable
x
. - #define DIP_OVL_CALL_ASSIGN_SIGNEDREAL
- Calls the overloaded function for all signed real (integer + float) types, and assigns the output value to variable
x
. - #define DIP_OVL_CALL_ASSIGN_NONCOMPLEX
- Calls the overloaded function for all non-complex types, and assigns the output value to variable
x
. - #define DIP_OVL_CALL_ASSIGN_FLEX
- Calls the overloaded function for all floating-point and complex types, and assigns the output value to variable
x
. - #define DIP_OVL_CALL_ASSIGN_FLEXBIN
- Calls the overloaded function for all floating-point, complex and binary types, and assigns the output value to variable
x
. - #define DIP_OVL_CALL_ASSIGN_NONBINARY
- Calls the overloaded function for all types but binary, and assigns the output value to variable
x
. - #define DIP_OVL_CALL_ASSIGN_ALL
- Calls the overloaded function for all types, and assigns the output value to variable
x
. - #define DIP_OVL_ASSIGN_BINARY
- Assigns a pointer to the overloaded function for the binary type to the variable
f
. - #define DIP_OVL_ASSIGN_UINT
- Assigns a pointer to the overloaded function for all unsigned integer types to the variable
f
. - #define DIP_OVL_ASSIGN_SINT
- Assigns a pointer to the overloaded function for all signed integer types to the variable
f
. - #define DIP_OVL_ASSIGN_FLOAT
- Assigns a pointer to the overloaded function for all float types to the variable
f
. - #define DIP_OVL_ASSIGN_COMPLEX
- Assigns a pointer to the overloaded function for all complex types to the variable
f
. - #define DIP_OVL_ASSIGN_INTEGER
- Assigns a pointer to the overloaded function for all integer types to the variable
f
. - #define DIP_OVL_ASSIGN_INT_OR_BIN
- Assigns a pointer to the overloaded function for all integer and binary types to the variable
f
. - #define DIP_OVL_ASSIGN_UNSIGNED
- Assigns a pointer to the overloaded function for all unsigned types to the variable
f
. - #define DIP_OVL_ASSIGN_SIGNED
- Assigns a pointer to the overloaded function for all signed (integer + float + complex) types to the variable
f
. - #define DIP_OVL_ASSIGN_REAL
- Assigns a pointer to the overloaded function for all real (integer + float) types to the variable
f
. - #define DIP_OVL_ASSIGN_SIGNEDREAL
- Assigns a pointer to the overloaded function for all signed real (integer + float) types to the variable
f
. - #define DIP_OVL_ASSIGN_NONCOMPLEX
- Assigns a pointer to the overloaded function for all non-complex types to the variable
f
. - #define DIP_OVL_ASSIGN_FLEX
- Assigns a pointer to the overloaded function for all floating-point and complex types to the variable
f
. - #define DIP_OVL_ASSIGN_FLEXBIN
- Assigns a pointer to the overloaded function for all floating-point, complex and binary types to the variable
f
. - #define DIP_OVL_ASSIGN_NONBINARY
- Assigns a pointer to the overloaded function for all types but binary to the variable
f
. - #define DIP_OVL_ASSIGN_ALL
- Assigns a pointer to the overloaded function for all types to the variable
f
. - #define DIP_OVL_NEW_BINARY
- Assigns a pointer to the overloaded class for the binary type to the variable
x
. - #define DIP_OVL_NEW_UINT
- Assigns a pointer to the overloaded class for all unsigned integer types to the variable
x
. - #define DIP_OVL_NEW_SINT
- Assigns a pointer to the overloaded class for all signed integer types to the variable
x
. - #define DIP_OVL_NEW_FLOAT
- Assigns a pointer to the overloaded class for all float types to the variable
x
. - #define DIP_OVL_NEW_COMPLEX
- Assigns a pointer to the overloaded class for all complex types to the variable
x
. - #define DIP_OVL_NEW_INTEGER
- Assigns a pointer to the overloaded class for all integer types to the variable
x
. - #define DIP_OVL_NEW_INT_OR_BIN
- Assigns a pointer to the overloaded class for all integer and binary types to the variable
x
. - #define DIP_OVL_NEW_UNSIGNED
- Assigns a pointer to the overloaded class for all unsigned types to the variable
x
. - #define DIP_OVL_NEW_SIGNED
- Assigns a pointer to the overloaded class for all signed (integer + float + complex) types to the variable
x
. - #define DIP_OVL_NEW_REAL
- Assigns a pointer to the overloaded class for all real (integer + float) types to the variable
x
. - #define DIP_OVL_NEW_SIGNEDREAL
- Assigns a pointer to the overloaded class for all signed real (integer + float) types to the variable
x
. - #define DIP_OVL_NEW_NONCOMPLEX
- Assigns a pointer to the overloaded class for all non-complex types to the variable
x
. - #define DIP_OVL_NEW_FLEX
- Assigns a pointer to the overloaded class for all floating-point and complex types to the variable
x
. - #define DIP_OVL_NEW_FLEXBIN
- Assigns a pointer to the overloaded class for all floating-point, complex and binary types to the variable
x
. - #define DIP_OVL_NEW_NONBINARY
- Assigns a pointer to the overloaded class for all types but binary to the variable
x
. - #define DIP_OVL_NEW_ALL
- Assigns a pointer to the overloaded class for all types to the variable
x
.