commit 7d7ad25cfbc060dcede158f49139db4966652f43 Author: Timur A. Fatkhullin Date: Sat Jun 20 21:53:15 2026 +0300 start ... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ca8b61e --- /dev/null +++ b/.gitignore @@ -0,0 +1,84 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash +**/.qmlls.ini + +# qtcreator generated files +*.pro.user* +*.qbs.user* +CMakeLists.txt.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + +# Directories with generated files +.moc/ +.obj/ +.pch/ +.rcc/ +.uic/ +/build*/ +/.qtcreator/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..de20950 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.16) + +project(ADCLIB LANGUAGES CXX DESCRIPTION "Abstract Device Components Library") + +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# ------- dependencies ------- + +include(FetchContent) + +FetchContent_Declare( + snplib + GIT_REPOSITORY https://timur@git.sao.ru/timur/snipplib.git + GIT_TAG main + GIT_SHALLOW 1 + GIT_PROGRESS 1 + SOURCE_DIR ${CMAKE_BINARY_DIR}/snipplib +) + +FetchContent_MakeAvailable(snplib) + + +set(ADCLIB_HEADERS include/adclib/adclib_device.h) +add_library(${PROJECT_NAME} INTERFACE ${ADCLIB_HEADERS}) + +include(GNUInstallDirs) +install(TARGETS ADCLIB + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) diff --git a/include/adclib/adclib_device.h b/include/adclib/adclib_device.h new file mode 100644 index 0000000..f1fd018 --- /dev/null +++ b/include/adclib/adclib_device.h @@ -0,0 +1,70 @@ +#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