I have a container of variables that are created from template class and types are detected in runtime (stored in type as string).
But.. Let's for example say that I want to interpolate the variables, and those variables are of different datatypes as said above.
I want to run more than one function to not use the same compare-code all over again:
1 2 3 4 5 6 7 8 9 10 11 12
|
void ClassA::CompareDTAndDoSomething(TimeTag time, long value, long valueTo)
{
if (type == "char *") AddInterpol<CHAR>(time, (CHAR)value, (CHAR)valueTo); else
if (type == "unsigned char *") AddInterpol<UCHAR>(time, (UCHAR)value, (UCHAR)valueTo); else
if (type == "short *") AddInterpol<SHORT>(time, (SHORT)value, (SHORT)valueTo); else
if (type == "unsigned short *") AddInterpol<USHORT>(time, (USHORT)value, (USHORT)valueTo); else
if (type == "int *") AddInterpol<INT>(time, (INT)value, (INT)valueTo); else
if (type == "unsigned int *") AddInterpol<UINT>(time, (UINT)value, (UINT)valueTo); else
if (type == "long *") AddInterpol<LONG>(time, (LONG)value, (LONG)valueTo); else
if (type == "unsigned long *") AddInterpol<ULONG>(time, (ULONG)value, (ULONG)valueTo); else
if (type == "float *") AddInterpol<FLOAT>(time, (FLOAT)value, (FLOAT)valueTo);
}
|
I have this function: CompareDTAndDoSomething(...);
Sometimes I want to pass more arguments and more than one function.
so I want to use a function pointer with template instead, but thats when I run intro problems.
for example I want if possible to do something like this:
1 2
|
if (type == "char *") funcPtr<CHAR>(time, (CHAR)value, (CHAR)valueTo); else
if (type == "unsigned char *") funcPtr<UCHAR>(time, (UCHAR)value, (UCHAR)valueTo); else
|
....etc..
then the ClassA::Compare-member function need some other argument too, or variable argument list:
1 2 3 4 5
|
void ClassA::CompareDTAndDoSomething(FuncPtr<T> function, ...)
{
if (type == "char *") funcPtr<CHAR>(time, (CHAR)value, (CHAR)valueTo); else
....etc..
}
|
so instead of having void ClassA::CompareDTAndSomething2(newFunction)
and all the if sentences again and another function, i just want to reuse the same member-function as pass function pointers to it:
1 2 3
|
CompareDTAndDoSomething(AddInterpol, arg1, arg2, arg3, ..etc);
CompareDTAndDoSomething(SetInterpol, arg1, arg2);
CompareDTAndDoSomething(SomethingElseFunc, arg1);
|
AddInterpol and SetInterpol should not have all the compares of types, thats what CompareDTAndDoSomething function should do.
AddInterpol and SetInterpol are template functions however. but its important that CompareDTAndDoSomething is not a template class.
Any ideas how to pass template-functions into arguments of a member-function like this?
To prevent multiple lines of if-compares of the datatypes above?
Hope this wasnt to messy to understand what Im asking about.
Thanks