diff --git a/src/sinqAxis.cpp b/src/sinqAxis.cpp index b7c7a58..e12fa84 100644 --- a/src/sinqAxis.cpp +++ b/src/sinqAxis.cpp @@ -30,22 +30,23 @@ struct sinqAxisImpl { epicsTimeStamp lastPollTime; }; +template struct TypeTag {}; + // Generic fallback - if the compiler tries to compile this function, it fails. template -asynStatus setAxisParam(A *axis, C *controller, const char *indexName, - int (C::*func)(), T writeValue, - const char *callerFunctionName, int lineNumber) { - static_assert( - sizeof(T) == 0, - "no specialization of setAxisParam exists for the given type"); +asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName, + int (C::*func)(), T writeValue, + const char *callerFunctionName, int lineNumber, + TypeTag) { + static_assert(sizeof(T) == 0, "Unsupported type for setAxisParamImpl"); return asynError; } -template ::value, int> = 0> -asynStatus setAxisParam(A *axis, C *controller, const char *indexName, - int (C::*func)(), T writeValue, - const char *callerFunctionName, int lineNumber) { +template +asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName, + int (C::*func)(), int writeValue, + const char *callerFunctionName, int lineNumber, + TypeTag) { int indexValue = (axis->pController()->*func)(); asynStatus status = axis->setIntegerParam(indexValue, writeValue); if (status != asynSuccess) { @@ -55,20 +56,21 @@ asynStatus setAxisParam(A *axis, C *controller, const char *indexName, return asynSuccess; } -template ::value, bool> = 0> -asynStatus setAxisParam(A *axis, C *controller, const char *indexName, - int (C::*func)(), T writeValue, - const char *callerFunctionName, int lineNumber) { - return setAxisParam(axis, indexName, func, static_cast(writeValue), - callerFunctionName, lineNumber); +template +asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName, + int (C::*func)(), bool writeValue, + const char *callerFunctionName, int lineNumber, + TypeTag) { + return setAxisParamImpl(axis, controller, indexName, func, + static_cast(writeValue), callerFunctionName, + lineNumber, TypeTag{}); } -template ::value, double> = 0> -asynStatus setAxisParam(A *axis, C *controller, const char *indexName, - int (sinqController::*func)(), T writeValue, - const char *callerFunctionName, int lineNumber) { +template +asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName, + int (sinqController::*func)(), double writeValue, + const char *callerFunctionName, int lineNumber, + TypeTag) { int indexValue = (axis->pController()->*func)(); asynStatus status = axis->setDoubleParam(indexValue, writeValue); if (status != asynSuccess) { @@ -78,11 +80,11 @@ asynStatus setAxisParam(A *axis, C *controller, const char *indexName, return asynSuccess; } -template ::value, char *> = 0> -asynStatus setAxisParam(A *axis, C *controller, const char *indexName, - int (C::*func)(), T writeValue, - const char *callerFunctionName, int lineNumber) { +template +asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName, + int (C::*func)(), char *writeValue, + const char *callerFunctionName, int lineNumber, + TypeTag) { int indexValue = (axis->pController()->*func)(); asynStatus status = axis->setStringParam(indexValue, writeValue); if (status != asynSuccess) { @@ -92,12 +94,11 @@ asynStatus setAxisParam(A *axis, C *controller, const char *indexName, return asynSuccess; } -template < - typename A, typename C, typename T, - std::enable_if_t::value, const char *> = 0> -asynStatus setAxisParam(A *axis, C *controller, const char *indexName, - int (C::*func)(), T writeValue, - const char *callerFunctionName, int lineNumber) { +template +asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName, + int (C::*func)(), const char *writeValue, + const char *callerFunctionName, int lineNumber, + TypeTag) { int indexValue = (axis->pController()->*func)(); asynStatus status = axis->setStringParam(indexValue, writeValue); if (status != asynSuccess) { @@ -107,22 +108,31 @@ asynStatus setAxisParam(A *axis, C *controller, const char *indexName, return asynSuccess; } +template +asynStatus setAxisParam(A *axis, C *controller, const char *indexName, + int (C::*func)(), T writeValue, + const char *callerFunctionName, int lineNumber) { + return setAxisParamImpl(axis, controller, indexName, func, writeValue, + callerFunctionName, lineNumber, TypeTag{}); +} + // Generic fallback - if the compiler tries to compile this function, it fails. template -asynStatus getAxisParam(A *axis, C *controller, const char *indexName, - int (C::*func)(), T *readValue, - const char *callerFunctionName, int lineNumber) { +asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName, + int (C::*func)(), T *readValue, + const char *callerFunctionName, int lineNumber, + TypeTag) { static_assert( sizeof(T) == 0, "no specialization of getAxisParam exists for the given type"); return asynError; } -template ::value, int> = 0> -asynStatus getAxisParam(A *axis, C *controller, const char *indexName, - int (C::*func)(), T *readValue, - const char *callerFunctionName, int lineNumber) { +template +asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName, + int (C::*func)(), int *readValue, + const char *callerFunctionName, int lineNumber, + TypeTag) { int indexValue = (axis->pController()->*func)(); asynStatus status = axis->pController()->getIntegerParam( axis->axisNo(), indexValue, readValue); @@ -133,21 +143,20 @@ asynStatus getAxisParam(A *axis, C *controller, const char *indexName, return asynSuccess; } -template ::value, bool> = 0> -asynStatus getAxisParam(A *axis, C *controller, const char *indexName, - int (C::*func)(), T *readValue, - const char *callerFunctionName, int lineNumber) { - return getAxisParam(axis, indexName, func, (int *)readValue, - callerFunctionName, lineNumber); +template +asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName, + int (C::*func)(), bool *readValue, + const char *callerFunctionName, int lineNumber, + TypeTag) { + return getAxisParamImpl(axis, indexName, func, (int *)readValue, + callerFunctionName, lineNumber); } -template ::value, double> = 0> -asynStatus getAxisParam(A *axis, C *controller, const char *indexName, - int (C::*func)(), T *readValue, - const char *callerFunctionName, - int lineNumber) { +template +asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName, + int (C::*func)(), double *readValue, + const char *callerFunctionName, int lineNumber, + TypeTag) { int indexValue = (axis->pController()->*func)(); asynStatus status = axis->pController()->getDoubleParam( axis->axisNo(), indexValue, readValue); @@ -158,11 +167,11 @@ asynStatus getAxisParam(A *axis, C *controller, const char *indexName, return asynSuccess; } -template ::value, char> = 0> -asynStatus getAxisParam(A *axis, C *controller, const char *indexName, - int (C::*func)(), T *readValue, - const char *callerFunctionName, int lineNumber) { +template +asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName, + int (C::*func)(), char *readValue, + const char *callerFunctionName, int lineNumber, + TypeTag) { int maxChars = 200; @@ -176,22 +185,22 @@ asynStatus getAxisParam(A *axis, C *controller, const char *indexName, return asynSuccess; } -template ::value, char> = 0, size_t N> -asynStatus getAxisParam(A *axis, C *controller, const char *indexName, - int (C::*func)(), T (&readValue)[N], - const char *callerFunctionName, int lineNumber) { +template +asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName, + int (C::*func)(), char (&readValue)[N], + const char *callerFunctionName, int lineNumber, + TypeTag) { // Decay the array to char* - return getAxisParam(axis, controller, indexName, func, - static_cast(readValue), - callerFunctionName, lineNumber); + return getAxisParamImpl(axis, controller, indexName, func, + static_cast(readValue), callerFunctionName, + lineNumber); } template -asynStatus -getAxisParam(A *axis, C *controller, const char *indexName, - int (C::*func)(), std::string *readValue, - const char *callerFunctionName, int lineNumber) { +asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName, + int (C::*func)(), std::string *readValue, + const char *callerFunctionName, int lineNumber, + TypeTag) { int indexValue = (axis->pController()->*func)(); // Convert the pointer to a reference, since getStringParam expects the @@ -207,6 +216,14 @@ getAxisParam(A *axis, C *controller, const char *indexName, return asynSuccess; } +template +asynStatus getAxisParam(A *axis, C *controller, const char *indexName, + int (C::*func)(), std::string *readValue, + const char *callerFunctionName, int lineNumber) { + return getAxisParamImpl(axis, controller, indexName, func, readValue, + callerFunctionName, lineNumber, TypeTag{}); +} + // ============================================================================= sinqAxis::sinqAxis(class sinqController *pC, int axisNo) diff --git a/src/sinqAxis.h b/src/sinqAxis.h index 17f140d..618c0e8 100644 --- a/src/sinqAxis.h +++ b/src/sinqAxis.h @@ -502,9 +502,9 @@ asynStatus setAxisParam(A *axis, C *controller, const char *indexName, * @return asynStatus */ template -asynStatus getAxisParam(A *axis, const char *indexName, int (C::*func)(), - T *readValue, const char *callerFunctionName, - int lineNumber); +asynStatus getAxisParam(A *axis, C *controller, const char *indexName, + int (C::*func)(), T *readValue, + const char *callerFunctionName, int lineNumber); /** * @brief Macro to get an paramLib parameter and error checking the return value