diff --git a/examples/device_exam.cpp b/examples/device_exam.cpp index ea1bde9..f4d2f62 100644 --- a/examples/device_exam.cpp +++ b/examples/device_exam.cpp @@ -14,14 +14,20 @@ int main() AdcGenericDevice<> dev("DEV#1"); - std::println("add RW-attr with id='{}' (val={})", id1, i); - dev.addAttr( + std::println("add arith RW-attr with id='{}' (val={})", id1, i); + dev.addArithAttr( id1, [&i]() -> adc_result_t { return i; }, [&i](int ii) -> adc_error_t { i = ii; return AdcDeviceErrorCode::ERROR_OK; - }, - std::tuple{}); + }); + // dev.addAttr( + // id1, [&i]() -> adc_result_t { return i; }, + // [&i](int ii) -> adc_error_t { + // i = ii; + // return AdcDeviceErrorCode::ERROR_OK; + // }, + // std::tuple{}); std::println("add RO-attr with id='{}' (val={})", id2, d); dev.addAttr(id2, [&d]() -> adc_result_t { return d; }, nullptr); diff --git a/include/adclib/adclib_device.h b/include/adclib/adclib_device.h index b8530b8..61633bb 100644 --- a/include/adclib/adclib_device.h +++ b/include/adclib/adclib_device.h @@ -283,7 +283,7 @@ public: float, double, long double> - arithmetic_t{}; + arithmetic_types{}; typedef DEV_ID_T device_id_t; typedef ATTR_ID_T attr_id_t; @@ -326,6 +326,14 @@ public: std::tuple...>{}); } + // add attribute of one of arithmetic type + template + requires std::is_arithmetic_v> + void addArithAttr(ATTR_ID_T id, GT&& getter, ST&& setter) + { + addAttr(std::move(id), std::forward(getter), std::forward(setter), AdcGenericDevice::arithmetic_types); + } + adc_error_t operator()(CMD_ID_T id) { if (auto it = _commands.find(id); it != _commands.end()) {