From 603b3e77afcffbaa91ae42272a5b8687286f9c68 Mon Sep 17 00:00:00 2001 From: smathis Date: Mon, 16 Jun 2025 15:53:36 +0200 Subject: [PATCH] Revised version with adapted macros --- src/sinqAxis.h | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/sinqAxis.h b/src/sinqAxis.h index 618c0e8..889ce30 100644 --- a/src/sinqAxis.h +++ b/src/sinqAxis.h @@ -467,17 +467,18 @@ asynStatus setAxisParam(A *axis, C *controller, const char *indexName, * ``` * ============================================================================= */ -#define setAxisParamChecked(axis, indexGetterFunction, writeValue) \ - { \ - asynStatus setStatus = setAxisParam( \ - axis, axis->pController(), #indexGetterFunction, \ - &std::remove_pointer< \ - decltype(axis->pController())>::type::indexGetterFunction, \ - writeValue, __PRETTY_FUNCTION__, __LINE__); \ - if (setStatus != asynSuccess) { \ +#define setAxisParamChecked(axis, indexSetterFunction, writeValue) \ + do { \ + auto *ctrlPtr = (axis)->pController(); \ + using ControllerType = \ + typename std::remove_pointer::type; \ + asynStatus setStatus = \ + setAxisParam(axis, ctrlPtr, #indexSetterFunction, \ + &ControllerType::indexSetterFunction, writeValue, \ + __PRETTY_FUNCTION__, __LINE__); \ + if (setStatus != asynSuccess) \ return setStatus; \ - } \ - } + } while (0) // ============================================================================= // Helper functions and definitions for the macro getAxisParamChecked @@ -533,15 +534,16 @@ asynStatus getAxisParam(A *axis, C *controller, const char *indexName, * ============================================================================= */ #define getAxisParamChecked(axis, indexGetterFunction, readValue) \ - { \ - asynStatus getStatus = getAxisParam( \ - axis, axis->pController(), #indexGetterFunction, \ - &std::remove_pointer< \ - decltype(axis->pController())>::type::indexGetterFunction, \ - readValue, __PRETTY_FUNCTION__, __LINE__); \ - if (getStatus != asynSuccess) { \ + do { \ + auto *ctrlPtr = (axis)->pController(); \ + using ControllerType = \ + typename std::remove_pointer::type; \ + asynStatus getStatus = \ + getAxisParam(axis, ctrlPtr, #indexGetterFunction, \ + &ControllerType::indexGetterFunction, readValue, \ + __PRETTY_FUNCTION__, __LINE__); \ + if (getStatus != asynSuccess) \ return getStatus; \ - } \ - } + } while (0) #endif