start ...
This commit is contained in:
84
.gitignore
vendored
Normal file
84
.gitignore
vendored
Normal file
@@ -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/
|
||||
31
CMakeLists.txt
Normal file
31
CMakeLists.txt
Normal file
@@ -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}
|
||||
)
|
||||
70
include/adclib/adclib_device.h
Normal file
70
include/adclib/adclib_device.h
Normal file
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
/****************************************************************************************
|
||||
* ABSTRACT DEVICE COMPONENTS LIBRARY *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <snipplib/containers/snplib_hmap.h>
|
||||
|
||||
|
||||
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 <std::formattable<char> ATTR_ID_T = std::string_view, std::formattable<char> CMD_ID_T = std::string_view>
|
||||
class adc_device_t
|
||||
{
|
||||
public:
|
||||
typedef std::error_code error_t;
|
||||
|
||||
template <typename VT>
|
||||
using op_result_t = std::expected<VT, error_t>;
|
||||
|
||||
protected:
|
||||
template <typename VT>
|
||||
struct attr_t {
|
||||
ATTR_ID_T id;
|
||||
std::function<op_result_t<VT>()> getter;
|
||||
std::function<void(VT const&)> setter;
|
||||
};
|
||||
|
||||
|
||||
struct attr_proxy_t {
|
||||
template <typename VT>
|
||||
VT get(ATTR_ID_T id)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
std::unordered_map<CMD_ID_T, std::function<void()>> _commands{};
|
||||
snplib::HeterogenMap<ATTR_ID_T> _attrs{};
|
||||
|
||||
public:
|
||||
adc_device_t() {}
|
||||
|
||||
template <snplib::snplib_callable_c ET>
|
||||
void addCommand(CMD_ID_T id, ET&& exec_func)
|
||||
{
|
||||
_commands.emplace(std::move(id), std::forward<ET>(exec_func));
|
||||
}
|
||||
|
||||
template <typename GT, typename ST>
|
||||
void addAttr(ATTR_ID_T id, GT&& getter, ST&& setter)
|
||||
{
|
||||
// deduce attribute value type
|
||||
using v_t = std::invoke_result_t<GT>;
|
||||
|
||||
static_assert(std::invocable<ST, v_t const&>, "Invalid setter type!");
|
||||
|
||||
_attrs.push(std::move(id), attr_t<v_t>{.getter = std::forward<GT>(getter), .setter = std::forward<ST>(setter)});
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adc
|
||||
Reference in New Issue
Block a user