13#ifndef ML_STD_TYPE_INFOS_H
14#define ML_STD_TYPE_INFOS_H
38template <
typename VTYP>
99 static const char *v[] =
113 static const char *v[] =
130 static const char *v[] =
143 static const char *v[] =
158 static const char *v[] =
170 static const char *v[] =
183 static const char *v[] =
199 static const char *v[] =
210 static const char *v[] =
247 MLuint numLocalGoodCastTos=0;
248 const char **goodLocalCastTos=
nullptr;
249 _getGoodCastTos(
static_cast<VTYP
>(0), numLocalGoodCastTos, goodLocalCastTos);
315 typeName(
static_cast<VTYP*
>(
nullptr)),
367 for (
size_t i=0;i<size;i++)
370 source +=
sizeof(VTYP)*sourceStride;
371 dest +=
sizeof(VTYP)*destStride;
384 memset(arrayPtr, value, n*
sizeof(VTYP) );
387 for (
size_t i = 0; i < n; i++) {
428 for (
size_t i = 0; i<size; i++) {
429 *destPtr++ =
castToType((*srcPtr++) * factor + offsetValue);
439 for (
size_t i=0; i<size; i++) {
440 if (*arrayPtr++ != constValue) {
return false; }
450 const auto *begin =
reinterpret_cast<const VTYP *
>(p);
451 auto min_max = std::minmax_element(begin, begin + s);
452 min =
static_cast<double>(*min_max.first);
453 max =
static_cast<double>(*min_max.second);
static void MLTYPE_multWithOtherType(const MLTypeInfos *otherInfos, const MLTypeData *otherData, const MLTypeData *myData, MLTypeData *r)
Implements multiplication with another type. Result is written into parameter three.
static void MLTYPE_castToOtherType(const MLTypeData *myData, const MLTypeInfos *otherInfos, MLTypeData *otherData)
Returns the parameter cast to double. Usually implemented by default with function casting component-...
MLDataType _rangeAndPrecisionEquiv(MLuint32)
static VTYP castToType(MLdouble v)
static void MLTYPE_arrayGetMinMax(const MLTypeData *p, size_t s, MLdouble &min, MLdouble &max)
static bool MLTYPE_arrayEqualsValue(const MLTypeData *value, const MLTypeData *buffer, size_t size)
MLDataType _rangeAndPrecisionEquiv(MLuint64)
void _getGoodCastTos(MLfloat, MLuint &num, const char **&typeNames)
void _getGoodCastTos(MLuint32, MLuint &num, const char **&typeNames)
void _getGoodCastTos(MLuint64, MLuint &num, const char **&typeNames)
static const char * typeName(MLint8 *)
static const char * typeName(MLint16 *)
static void MLTYPE_plusInt(const MLTypeData *p, MLint q, MLTypeData *r)
Implements integer addition to parameter one. Result is written into parameter three.
MLDataType _rangeAndPrecisionEquiv(MLdouble)
MLDataType _rangeAndPrecisionEquiv(MLuint16)
static void MLTYPE_multWithInt(const MLTypeData *p, MLint q, MLTypeData *r)
Implements multiplication with integer. Result is written into parameter three.
MLDataType _rangeAndPrecisionEquiv(MLint32)
static bool MLTYPE_isEqualToType(const MLTypeData *p, const MLTypeData *q)
Returns true if both parameters are equal; otherwise, it returns false.
static const char * typeName(MLuint8 *)
static const char _typeInfoString[_ML_STD_SLEN]
Permanent instance of the type's description.
static void MLTYPE_multWithType(const MLTypeData *p, const MLTypeData *q, MLTypeData *r)
Implements multiplication with its own type. Result is written into parameter three.
static void MLTYPE_multWithDouble(const MLTypeData *p, MLdouble q, MLTypeData *r)
Implements multiplication with double. Result is written into parameter three.
static void MLTYPE_setToMinimum(MLTypeData *p)
Sets value to minimum value. Must be implemented.
static void MLTYPE_copy(const MLTypeData *source, MLTypeData *dest)
Copies first parameter to second one.
static const char * typeName(MLint32 *)
static void MLTYPE_setComponent(MLTypeData *p, size_t, MLdouble v)
Sets n-th component from double value. Must be implemented.
void _getGoodCastTos(MLint32, MLuint &num, const char **&typeNames)
static const VTYP _typeMax
Permanent instance of the maximum value.
static MLTypeInfos * _myInfos
Permanent instance of a pointer to the typeInfos used by this class.
static bool MLTYPE_isEqualToTypeWithEpsilon(const MLTypeData *p, const MLTypeData *q, MLdouble eps)
Returns true if both parameters are equal within a static epsilon; otherwise, it returns false.
static const char * typeName(MLint64 *)
static VTYP & value_cast(MLTypeData *v)
Avoid using reinterpret_casts.
void _getGoodCastTos(MLuint8, MLuint &num, const char **&typeNames)
static const char * typeName(MLdouble *)
static void MLTYPE_arrayRescale(const MLTypeData *source, MLdouble factor, const MLTypeData *offset, MLTypeData *dest, size_t size)
static const VTYP _typeMin
Permanent instance of the minimum value.
static void MLTYPE_setStringValue(const char *s, MLTypeData *r)
Converts the string s to a value and writes result into r. Use MLTypeComponentsFromString() if possib...
static char * MLTYPE_getStringValue(const MLTypeData *p)
Returns the value as string to be freed by MLFree(). Use MLTypeComponentsToString() if possible.
MLDataType _rangeAndPrecisionEquiv(MLfloat)
static const char * typeName(MLuint16 *)
MLDataType _rangeAndPrecisionEquiv(MLuint8)
static MLdouble MLTYPE_getComponent(const MLTypeData *p, size_t)
Returns n-th component as double value. Must be implemented.
void _getGoodCastTos(MLdouble, MLuint &num, const char **&typeNames)
static bool MLTYPE_castToBool(const MLTypeData *p)
Returns the parameter cast to bool. Typically, it returns false if it is identically to the default e...
static void MLTYPE_setToDefault(MLTypeData *p)
Sets value to default value. Must be implemented.
static void MLTYPE_interpolate(const MLTypeData *p, const MLTypeData *q, MLdouble r, MLTypeData *t)
static void MLTYPE_castFromOtherType(const MLTypeInfos *otherInfos, const MLTypeData *otherData, MLTypeData *myData)
Casts the first parameters to data type and writes it into the second parameter.
static MLint32 _numInstances
static void MLTYPE_negate(const MLTypeData *p, MLTypeData *q)
Negates the value. See also the specialized negations for unsigned types that leave the value unchang...
void _getGoodCastTos(MLint64, MLuint &num, const char **&typeNames)
static MLint MLTYPE_castToInt(const MLTypeData *p)
Returns the parameter cast to integer. Often the integer cast of the first component.
static void MLTYPE_castFromDouble(MLdouble p, MLTypeData *q)
Casts the first parameters to data type and writes it into the second parameter.
static void MLTYPE_plusType(const MLTypeData *p, const MLTypeData *q, MLTypeData *r)
Implements parameter two addition to parameter one. Result is written into parameter three.
void _getGoodCastTos(MLuint16, MLuint &num, const char **&typeNames)
static const char * typeName(MLfloat *)
static void MLTYPE_arrayCopy(const MLTypeData *source, MLTypeData *dest, size_t size)
Copies s elements from the first parameter to the second one.
static void MLTYPE_castFromInt(MLint p, MLTypeData *q)
Casts the first parameters to data type and writes it into the second parameter.
static const VTYP _typeDefault
Permanent instance of the default value.
static void MLTYPE_plusDouble(const MLTypeData *p, MLdouble q, MLTypeData *r)
Implements double addition to parameter one. Result is written into parameter three.
static const char * typeName(MLuint64 *)
static const char * typeName(MLuint32 *)
static void MLTYPE_arrayFill(const MLTypeData *fillValue, MLTypeData *dest, size_t n)
Copies the first parameter to the second one as often as given in the third parameter.
MLDataType _rangeAndPrecisionEquiv(MLint64)
void _getGoodCastTos(MLint16, MLuint &num, const char **&typeNames)
static const VTYP & value_cast(const MLTypeData *v)
static void MLTYPE_normalize(const MLTypeData *, MLTypeData *q)
Normalizes the type.
static void MLTYPE_setToMaximum(MLTypeData *p)
Sets value to minimum value. Must be implemented.
static void MLTYPE_arrayCopyWithStrides(const MLTypeData *source, MLssize_t sourceStride, MLTypeData *dest, MLssize_t destStride, size_t size)
Same as MLTYPE_arrayCopy, but allows to specify stride values for source and destination.
void _getGoodCastTos(MLint8, MLuint &num, const char **&typeNames)
static MLdouble MLTYPE_castToDouble(const MLTypeData *p)
Returns the parameter cast to double. Often the integer cast of the first component.
MLDataType _rangeAndPrecisionEquiv(MLint8)
MLDataType _rangeAndPrecisionEquiv(MLint16)
bool MLValuesDifferWOM(MLint8 a, MLint8 b)
bool MLValuesAreEqualWOM(MLint8 a, MLint8 b)
@ MLuint8Type
Enumerator for the unsigned 8-bit ML integer type.
@ MLuint32Type
Enumerator for the unsigned 32-bit ML integer type.
@ MLfloatType
Enumerator for the signed 32-bit ML floating point type.
@ MLuint16Type
Enumerator for the unsigned 16-bit ML integer type.
@ MLint64Type
Enumerator for the signed 64-bit ML integer type.
@ MLint16Type
Enumerator for the signed 16-bit ML integer type.
@ MLint32Type
Enumerator for the signed 32-bit ML integer type.
@ MLdoubleType
Enumerator for the signed 64-bit ML floating point type.
@ MLint8Type
Enumerator for the signed 8-bit ML integer type.
@ MLuint64Type
Enumerator for the unsigned 64-bit ML integer type.
#define ML_PROGRAMMING_ERROR
#define ML_PRINT_FATAL_ERROR(FUNC_NAME, REASON, HANDLING)
MLEXPORT MLint32 MLTypeComponentsFromString(const MLTypeInfos *infos, const char *stringData, const MLTypeData *defaultValue, MLTypeData *data)
MLEXPORT void MLTypeMultWithOtherType(const MLTypeInfos *myInfos, const MLTypeData *myData, const MLTypeInfos *otherInfos, const MLTypeData *otherData, MLTypeData *targetData)
MLEXPORT void MLTypeCastToOtherType(const MLTypeInfos *otherInfos, const MLTypeData *otherData, const MLTypeInfos *myInfos, MLTypeData *myData)
MLEXPORT char * MLTypeComponentsToString(const MLTypeInfos *infos, const MLTypeData *data)
MLEXPORT MLint32 MLTypeInfosInit(MLTypeInfos *infos, size_t typeSize, const char *name, MLdouble dblMin, MLdouble dblMax, const MLTypeData *typeMinPtr, const MLTypeData *typeMaxPtr, const MLTypeData *typeDefaultPtr, const char *typeStructInfo, MLint32 isScalarType, MLTypeGroup typeGroup, MLDataType rangeAndPrecisionEquiv, void **componentAddresses, size_t numGoodCastTos, const char **goodCastTos)
#define ML_HARAKIRI
This logs the fatal error with file and line number.
#define MLEXPORT
Code it as import symbol if compiled elsewhere.
UINT64 MLuint64
Introduce platform-independent 64-bit unsigned integer type.
#define ML_TYPE_ASSIGN_FUNCTION_POINTERS()
unsigned char MLTypeData
This is the pointer type used to point to the data of MLType data instances.
INT64 MLint64
Include 64-bit integer support for Windows or Unix.
SSIZE_T MLssize_t
The signed ML size type that is a signed 32-bit size_t on 32-bit platforms and 64-bit one on 64-bit p...
void ML_UTILS_EXPORT logTypeComponentsFromStringError(const char *function)
const MLint _ML_STD_SLEN
Length of strings for component descriptions and class names.
const char * name
Pointer to the data type name.
@ is8BitInteger
Flag that is true for ML[u]int8 types.