#pragma once /**************************************************************************************** * ABSTRACT DEVICE COMPONENTS LIBRARY * ****************************************************************************************/ #include namespace adc { enum class adc_device_error_code_t : int { ERROR_OK, ERROR_RO_ATTR, ERROR_WO_ATTR, ERROR_ATTR_RANGE }; } // namespace adc namespace adc { template ATTR_ID_T = std::string_view, std::formattable CMD_ID_T = std::string_view> class adc_device_t { public: typedef std::error_code error_t; template using op_result_t = std::expected; protected: template struct attr_t { ATTR_ID_T id; std::function()> getter; std::function setter; }; struct attr_proxy_t { template VT get(ATTR_ID_T id) { } }; std::unordered_map> _commands{}; snplib::HeterogenMap _attrs{}; public: adc_device_t() {} template void addCommand(CMD_ID_T id, ET&& exec_func) { _commands.emplace(std::move(id), std::forward(exec_func)); } template void addAttr(ATTR_ID_T id, GT&& getter, ST&& setter) { // deduce attribute value type using v_t = std::invoke_result_t; static_assert(std::invocable, "Invalid setter type!"); _attrs.push(std::move(id), attr_t{.getter = std::forward(getter), .setter = std::forward(setter)}); } }; } // namespace adc