Generalized getAxisParam
This commit is contained in:
161
src/sinqAxis.cpp
161
src/sinqAxis.cpp
@ -30,22 +30,23 @@ struct sinqAxisImpl {
|
||||
epicsTimeStamp lastPollTime;
|
||||
};
|
||||
|
||||
template <typename T> struct TypeTag {};
|
||||
|
||||
// Generic fallback - if the compiler tries to compile this function, it fails.
|
||||
template <typename A, typename C, typename T>
|
||||
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<void>) {
|
||||
static_assert(sizeof(T) == 0, "Unsupported type for setAxisParamImpl");
|
||||
return asynError;
|
||||
}
|
||||
|
||||
template <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, int>::value, int> = 0>
|
||||
asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C>
|
||||
asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), int writeValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<int>) {
|
||||
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 <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, bool>::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<int>(writeValue),
|
||||
callerFunctionName, lineNumber);
|
||||
template <typename A, typename C>
|
||||
asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), bool writeValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<bool>) {
|
||||
return setAxisParamImpl(axis, controller, indexName, func,
|
||||
static_cast<int>(writeValue), callerFunctionName,
|
||||
lineNumber, TypeTag<int>{});
|
||||
}
|
||||
|
||||
template <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, double>::value, double> = 0>
|
||||
asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
|
||||
int (sinqController::*func)(), T writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C>
|
||||
asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (sinqController::*func)(), double writeValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<double>) {
|
||||
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 <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, char *>::value, char *> = 0>
|
||||
asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C>
|
||||
asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), char *writeValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<char *>) {
|
||||
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<std::is_same<T, const char *>::value, const char *> = 0>
|
||||
asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C>
|
||||
asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), const char *writeValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<const char *>) {
|
||||
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 <typename A, typename C, typename T>
|
||||
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<T>{});
|
||||
}
|
||||
|
||||
// Generic fallback - if the compiler tries to compile this function, it fails.
|
||||
template <typename A, typename C, typename T>
|
||||
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<void>) {
|
||||
static_assert(
|
||||
sizeof(T) == 0,
|
||||
"no specialization of getAxisParam exists for the given type");
|
||||
return asynError;
|
||||
}
|
||||
|
||||
template <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, int>::value, int> = 0>
|
||||
asynStatus getAxisParam<int>(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T *readValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C>
|
||||
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), int *readValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<int>) {
|
||||
int indexValue = (axis->pController()->*func)();
|
||||
asynStatus status = axis->pController()->getIntegerParam(
|
||||
axis->axisNo(), indexValue, readValue);
|
||||
@ -133,21 +143,20 @@ asynStatus getAxisParam<int>(A *axis, C *controller, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, bool>::value, bool> = 0>
|
||||
asynStatus getAxisParam<bool>(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 <typename A, typename C>
|
||||
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), bool *readValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<bool>) {
|
||||
return getAxisParamImpl(axis, indexName, func, (int *)readValue,
|
||||
callerFunctionName, lineNumber);
|
||||
}
|
||||
|
||||
template <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, double>::value, double> = 0>
|
||||
asynStatus getAxisParam<double>(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T *readValue,
|
||||
const char *callerFunctionName,
|
||||
int lineNumber) {
|
||||
template <typename A, typename C>
|
||||
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), double *readValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<double>) {
|
||||
int indexValue = (axis->pController()->*func)();
|
||||
asynStatus status = axis->pController()->getDoubleParam(
|
||||
axis->axisNo(), indexValue, readValue);
|
||||
@ -158,11 +167,11 @@ asynStatus getAxisParam<double>(A *axis, C *controller, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, char>::value, char> = 0>
|
||||
asynStatus getAxisParam<char>(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T *readValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C>
|
||||
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), char *readValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<char>) {
|
||||
|
||||
int maxChars = 200;
|
||||
|
||||
@ -176,22 +185,22 @@ asynStatus getAxisParam<char>(A *axis, C *controller, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, char>::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 <typename A, typename C, size_t N>
|
||||
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), char (&readValue)[N],
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<char>) {
|
||||
// Decay the array to char*
|
||||
return getAxisParam<char>(axis, controller, indexName, func,
|
||||
static_cast<char *>(readValue),
|
||||
callerFunctionName, lineNumber);
|
||||
return getAxisParamImpl(axis, controller, indexName, func,
|
||||
static_cast<char *>(readValue), callerFunctionName,
|
||||
lineNumber);
|
||||
}
|
||||
|
||||
template <typename A, typename C>
|
||||
asynStatus
|
||||
getAxisParam<std::string>(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<std::string>) {
|
||||
int indexValue = (axis->pController()->*func)();
|
||||
|
||||
// Convert the pointer to a reference, since getStringParam expects the
|
||||
@ -207,6 +216,14 @@ getAxisParam<std::string>(A *axis, C *controller, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <typename A, typename C, typename T>
|
||||
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<T>{});
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
||||
sinqAxis::sinqAxis(class sinqController *pC, int axisNo)
|
||||
|
@ -502,9 +502,9 @@ asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
|
||||
* @return asynStatus
|
||||
*/
|
||||
template <typename A, typename C, typename T>
|
||||
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
|
||||
|
Reference in New Issue
Block a user