changes according to new naming scheme of the snippets-library

new naming scheme (delete "adclib_" prefixes)
This commit is contained in:
2026-09-18 12:11:42 +03:00
parent eb4fa72d4b
commit 271826ee4a
6 changed files with 130 additions and 134 deletions

View File

@@ -106,53 +106,51 @@ inline std::error_code make_error_code(AdcDeviceErrorCode ec)
template <typename T>
concept adclib_command_exec_t = snplib::snplib_callable_c<T> && (snplib::snplib_func_traits_t<T>::arity == 0) &&
std::same_as<adc_error_t, typename snplib::snplib_func_traits_t<T>::ret_t>;
concept device_command_exec_t = snplib::callable_c<T> && (snplib::func_traits_t<T>::arity == 0) &&
std::same_as<adc_error_t, typename snplib::func_traits_t<T>::ret_t>;
template <typename T>
concept adclib_attr_getter_c = std::same_as<T, std::nullptr_t> || requires(T t) {
{ t() } -> adc_result_c;
concept device_attr_getter_c = std::same_as<T, std::nullptr_t> || requires(T t) {
{ t() } -> ret_result_c;
};
template <typename T>
concept adclib_attr_setter_c =
std::same_as<T, std::nullptr_t> || (snplib::snplib_callable_c<T> && (snplib::snplib_func_traits_t<T>::arity >= 1) &&
std::same_as<adc_error_t, typename snplib::snplib_func_traits_t<T>::ret_t>);
concept device_attr_setter_c =
std::same_as<T, std::nullptr_t> || (snplib::callable_c<T> && (snplib::func_traits_t<T>::arity >= 1) &&
std::same_as<adc_error_t, typename snplib::func_traits_t<T>::ret_t>);
// deduce value type from getter and setter
template <adclib_attr_getter_c GT, adclib_attr_setter_c ST>
using adclib_attr_value_deduced_t = std::conditional_t<
template <device_attr_getter_c GT, device_attr_setter_c ST>
using device_attr_value_deduced_t = std::conditional_t<
std::is_null_pointer_v<GT>,
std::conditional_t<std::is_null_pointer_v<ST>, void, std::remove_cvref_t<snplib::snplib_func_arg1_t<ST>>>,
std::conditional_t<std::is_null_pointer_v<ST>, void, std::remove_cvref_t<snplib::func_arg1_t<ST>>>,
typename std::invoke_result_t<GT>::value_type>;
template <adclib_attr_getter_c GT, adclib_attr_setter_c ST>
struct adclib_is_deduced_void_t {
static constexpr bool value = std::is_void_v<adclib_attr_value_deduced_t<GT, ST>>;
template <device_attr_getter_c GT, device_attr_setter_c ST>
struct is_deduced_void_t {
static constexpr bool value = std::is_void_v<device_attr_value_deduced_t<GT, ST>>;
};
// conversional function signature:
// "from": adc_result_t<UT> func(const VT&)
// "to": adc_result_t<VT> func(const UT&)
template <typename T, typename VT>
concept adclib_attr_conv_from_func_c =
concept device_attr_conv_from_func_c =
std::same_as<T, std::nullptr_t> ||
(std::invocable<T, const VT&> && !std::is_void_v<std::invoke_result_t<T, const VT&>>);
template <typename T, typename VT>
concept adclib_attr_conv_to_func_c = std::same_as<T, std::nullptr_t> ||
(snplib::snplib_callable_c<T> && (snplib::snplib_func_traits_t<T>::arity == 1) &&
std::same_as<adc_result_t<VT>, typename snplib::snplib_func_traits_t<T>::ret_t>);
concept device_attr_conv_to_func_c =
std::same_as<T, std::nullptr_t> || (snplib::callable_c<T> && (snplib::func_traits_t<T>::arity == 1) &&
std::same_as<ret_result_t<VT>, typename snplib::func_traits_t<T>::ret_t>);
template <typename VT, adclib_attr_conv_from_func_c<VT> CONV_FROM_T, adclib_attr_conv_to_func_c<VT> CONV_TO_T>
using adclib_attr_user_deduced_t =
std::conditional_t<std::is_null_pointer_v<CONV_FROM_T>,
std::conditional_t<std::is_null_pointer_v<CONV_TO_T>,
void,
std::remove_cvref_t<snplib::snplib_func_arg1_t<CONV_TO_T>>>,
typename snplib::snplib_func_traits_t<CONV_FROM_T>::ret_t::value_type>;
template <typename VT, device_attr_conv_from_func_c<VT> CONV_FROM_T, device_attr_conv_to_func_c<VT> CONV_TO_T>
using device_attr_user_deduced_t = std::conditional_t<
std::is_null_pointer_v<CONV_FROM_T>,
std::conditional_t<std::is_null_pointer_v<CONV_TO_T>, void, std::remove_cvref_t<snplib::func_arg1_t<CONV_TO_T>>>,
typename snplib::func_traits_t<CONV_FROM_T>::ret_t::value_type>;
@@ -163,7 +161,7 @@ class AdcGenericDevice
{
protected:
template <typename VT>
using attr_getter_t = std::function<adc_result_t<VT>()>;
using attr_getter_t = std::function<ret_result_t<VT>()>;
template <typename VT>
using attr_setter_t = std::function<adc_error_t(VT const&)>;
@@ -176,7 +174,7 @@ protected:
attr_t(AdcGenericDevice& dev, ATTR_ID_T id) : _dev(dev), _id(std::move(id)) {}
template <typename VT>
operator adc_result_t<VT>() const
operator ret_result_t<VT>() const
{
auto getter = _dev._attrGetter.template get<attr_getter_t<VT>>(_id);
if (getter) {
@@ -231,10 +229,10 @@ protected:
// default convert functions for char-range types
template <typename VR, typename UR>
requires((snplib::snplib_char_range_c<VR> || snplib::snplib_pointer_to_char_c<VR>) &&
(snplib::snplib_char_range_c<UR> || snplib::snplib_pointer_to_char_c<UR>))
static inline std::function<adc_result_t<UR>(VR const&)> default_char_range_conv_from = [](VR const& val)
-> adc_result_t<UR> {
requires((snplib::char_range_c<VR> || snplib::pointer_to_char_c<VR>) &&
(snplib::char_range_c<UR> || snplib::pointer_to_char_c<UR>))
static inline std::function<ret_result_t<UR>(VR const&)> default_char_range_conv_from = [](VR const& val)
-> ret_result_t<UR> {
if constexpr (std::same_as<VR, UR>) {
return val;
} else if constexpr (std::constructible_from<UR, VR>) {
@@ -255,13 +253,13 @@ protected:
template <typename VR, typename UR>
static inline std::function<adc_result_t<VR>(UR const&)> default_char_range_conv_to =
static inline std::function<ret_result_t<VR>(UR const&)> default_char_range_conv_to =
default_char_range_conv_from<UR, VR>;
// default convert functions for std::filesystem::path type
template <typename UT>
static inline std::function<adc_result_t<UT>(std::filesystem::path const&)> default_fspath_conv_from =
[](std::filesystem::path const& val) -> adc_result_t<UT> {
static inline std::function<ret_result_t<UT>(std::filesystem::path const&)> default_fspath_conv_from =
[](std::filesystem::path const& val) -> ret_result_t<UT> {
if constexpr (std::same_as<std::filesystem::path, UT>) {
return val;
} else if constexpr (std::constructible_from<UT, std::filesystem::path>) {
@@ -271,7 +269,7 @@ protected:
std::same_as<const std::filesystem::path::value_type*,
UT>)) { // char*/wchar_t*
return val.c_str();
} else if constexpr (snplib::snplib_char_range_c<UT>) {
} else if constexpr (snplib::char_range_c<UT>) {
using iter_t = std::filesystem::path::value_type*;
auto sz = val.native().size();
if constexpr (std::constructible_from<UT, iter_t, iter_t>) {
@@ -287,13 +285,13 @@ protected:
};
template <typename UT>
static inline std::function<adc_result_t<std::filesystem::path>(UT const&)> default_fspath_conv_to =
[](UT const& uval) -> adc_result_t<std::filesystem::path> {
static inline std::function<ret_result_t<std::filesystem::path>(UT const&)> default_fspath_conv_to =
[](UT const& uval) -> ret_result_t<std::filesystem::path> {
if constexpr (std::same_as<std::filesystem::path, UT>) {
return uval;
} else if constexpr (std::constructible_from<std::filesystem::path, UT>) {
return std::filesystem::path(uval);
} else if constexpr (snplib::snplib_char_range_c<UT>) {
} else if constexpr (snplib::char_range_c<UT>) {
return std::filesystem::path(uval.begin(), uval.end());
} else {
static_assert(false, "UNSUPPORTED TYPE!");
@@ -356,13 +354,13 @@ public:
return _devId;
}
// template <snplib::snplib_callable_c ET>
// template <snplib::callable_c ET>
// void addCommand(CMD_ID_T id, ET&& exec_func)
// {
// _commands.emplace(std::move(id), std::forward<ET>(exec_func));
// }
template <adclib_command_exec_t ET>
template <device_command_exec_t ET>
void addCommand(CMD_ID_T id, ET&& exec_func)
{
_commands.emplace(std::move(id), std::forward<ET>(exec_func));
@@ -371,7 +369,7 @@ public:
template <typename GT, typename ST>
void addAttr(ATTR_ID_T id, GT&& getter, ST&& setter)
{
using v_t = adclib_attr_value_deduced_t<GT, ST>;
using v_t = device_attr_value_deduced_t<GT, ST>;
static_assert(!std::is_void_v<v_t>, "Getter and setter cannot be nullptr_t at the same time!");
if constexpr (!std::is_null_pointer_v<GT> && !std::is_null_pointer_v<ST>) {
@@ -386,7 +384,7 @@ public:
requires(sizeof...(UTs) > 0)
void addAttr(ATTR_ID_T id, GT&& getter, ST&& setter, std::tuple<UTs...>)
{
using v_t = adclib_attr_value_deduced_t<GT, ST>;
using v_t = device_attr_value_deduced_t<GT, ST>;
static_assert(!std::is_void_v<v_t>, "Getter and setter cannot be nullptr_t at the same time!");
if constexpr (!std::is_null_pointer_v<GT> && !std::is_null_pointer_v<ST>) {
@@ -411,7 +409,7 @@ public:
//
// conversional functions are the same as defined in the snplib::hmap class
// (it must convert attribute values instead of getters or setters itself!)
template <adclib_attr_getter_c GT, adclib_attr_setter_c ST, typename... FuncTs>
template <device_attr_getter_c GT, device_attr_setter_c ST, typename... FuncTs>
requires(sizeof...(FuncTs) > 1)
void addAttr(ATTR_ID_T id, GT&& getter, ST&& setter, FuncTs&&... cnv_pairs)
{
@@ -419,7 +417,7 @@ public:
static_assert(NFUNCS % 2 == 0, "Number of conversional functions must be an even!");
using v_t = adclib_attr_value_deduced_t<GT, ST>;
using v_t = device_attr_value_deduced_t<GT, ST>;
static_assert(!std::is_void_v<v_t>, "Getter and setter cannot be nullptr_t at the same time!");
@@ -433,10 +431,10 @@ public:
using from_fn_t = std::decay_t<std::tuple_element_t<I, tp_t>>;
using to_fn_t = std::decay_t<std::tuple_element_t<I + 1, tp_t>>;
using u_t = adclib_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
using u_t = device_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
return [tp = std::move(tp)](attr_getter_t<v_t> const& gt) -> adc_result_t<attr_getter_t<u_t>> {
return [tp = std::move(tp), &gt]() -> adc_result_t<u_t> {
return [tp = std::move(tp)](attr_getter_t<v_t> const& gt) -> ret_result_t<attr_getter_t<u_t>> {
return [tp = std::move(tp), &gt]() -> ret_result_t<u_t> {
auto v = gt();
if (v) {
// convert from inner type to user's ("convert-from" function)
@@ -455,9 +453,9 @@ public:
using from_fn_t = std::decay_t<std::tuple_element_t<I, tp_t>>;
using to_fn_t = std::decay_t<std::tuple_element_t<I + 1, tp_t>>;
using u_t = adclib_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
using u_t = device_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
return [tp = std::move(tp)](attr_setter_t<v_t> const& st) -> adc_result_t<attr_setter_t<u_t>> {
return [tp = std::move(tp)](attr_setter_t<v_t> const& st) -> ret_result_t<attr_setter_t<u_t>> {
return [tp = std::move(tp), &st](u_t const& uval) -> adc_error_t {
// convert from user type to inner ("convert-to" function)!
auto val = std::forward<std::tuple_element_t<I + 1, tp_t>>(std::get<I + 1>(tp))(uval);
@@ -476,10 +474,10 @@ public:
using from_fn_t = std::decay_t<std::tuple_element_t<I, tp_t>>;
using to_fn_t = std::decay_t<std::tuple_element_t<I + 1, tp_t>>;
using u_t = adclib_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
using u_t = device_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
return [tp = std::move(tp)](attr_getter_t<u_t> const& gt) -> adc_result_t<attr_getter_t<v_t>> {
return [tp = std::move(tp), &gt]() -> adc_result_t<v_t> {
return [tp = std::move(tp)](attr_getter_t<u_t> const& gt) -> ret_result_t<attr_getter_t<v_t>> {
return [tp = std::move(tp), &gt]() -> ret_result_t<v_t> {
auto uv = gt();
if (uv) {
// convert to inner type from user's ("convert-to" function)
@@ -498,9 +496,9 @@ public:
using from_fn_t = std::decay_t<std::tuple_element_t<I, tp_t>>;
using to_fn_t = std::decay_t<std::tuple_element_t<I + 1, tp_t>>;
using u_t = adclib_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
using u_t = device_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
return [tp = std::move(tp)](attr_setter_t<u_t> const& st) -> adc_result_t<attr_setter_t<v_t>> {
return [tp = std::move(tp)](attr_setter_t<u_t> const& st) -> ret_result_t<attr_setter_t<v_t>> {
return [tp = std::move(tp), &st](v_t const& val) -> adc_error_t {
// convert to user type from inner ("convert-from" function)!
auto uval = std::forward<std::tuple_element_t<I, tp_t>>(std::get<I>(tp))(val);
@@ -535,17 +533,17 @@ public:
setter_cap = std::forward<ST>(setter), this]<size_t... Is>(std::index_sequence<Is...>) mutable {
auto tp = std::forward_as_tuple(std::forward<FuncTs>(cnv_pairs_cap)...);
auto gt_cnv_from_func = []<size_t I, snplib::snplib_tuple_c TpT>(TpT const& tpl) {
auto gt_cnv_from_func = []<size_t I, snplib::tuple_c TpT>(TpT const& tpl) {
using from_fn_t = std::decay_t<std::tuple_element_t<I, TpT>>;
using to_fn_t = std::decay_t<std::tuple_element_t<I + 1, TpT>>;
using u_t = adclib_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
using u_t = device_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
// using u_t = std::invoke_result_t<from_fn_t>::value_type;
// static_assert(requires(v_t v, u_t u) { u = v; }, "Invalid deduced user type!");
return [&tpl](attr_getter_t<v_t> const& gt) -> adc_result_t<attr_getter_t<u_t>> {
return [&tpl, &gt]() -> adc_result_t<u_t> {
return [&tpl](attr_getter_t<v_t> const& gt) -> ret_result_t<attr_getter_t<u_t>> {
return [&tpl, &gt]() -> ret_result_t<u_t> {
auto v = gt();
if (v) {
// convert from inner type to user's ("convert-from" function)
@@ -558,16 +556,16 @@ public:
};
};
auto st_cnv_from_func = []<size_t I, snplib::snplib_tuple_c TpT>(TpT const& tpl) {
auto st_cnv_from_func = []<size_t I, snplib::tuple_c TpT>(TpT const& tpl) {
using from_fn_t = std::decay_t<std::tuple_element_t<I, TpT>>;
using to_fn_t = std::decay_t<std::tuple_element_t<I + 1, TpT>>;
using u_t = adclib_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
using u_t = device_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
// using u_t = std::invoke_result_t<from_fn_t>::value_type;
// static_assert(requires(v_t v, u_t u) { u = v; }, "Invalid deduced user type!");
return [&tpl](attr_setter_t<v_t> const& st) -> adc_result_t<attr_setter_t<u_t>> {
return [&tpl](attr_setter_t<v_t> const& st) -> ret_result_t<attr_setter_t<u_t>> {
return [&tpl, &st](u_t const& uval) -> adc_error_t {
// convert from user type to inner ("convert-to" function)!
auto val = std::forward<std::tuple_element_t<I + 1, TpT>>(std::get<I + 1>(tpl))(uval);
@@ -580,18 +578,18 @@ public:
};
};
auto gt_cnv_to_func = []<size_t I, snplib::snplib_tuple_c TpT>(TpT const& tpl) {
auto gt_cnv_to_func = []<size_t I, snplib::tuple_c TpT>(TpT const& tpl) {
using from_fn_t = std::decay_t<std::tuple_element_t<I, TpT>>;
using to_fn_t = std::decay_t<std::tuple_element_t<I + 1, TpT>>;
using u_t = adclib_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
using u_t = device_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
// using u_t = std::invoke_result_t<from_fn_t>::value_type;
// static_assert(requires(v_t v, u_t u) { v = u; }, "Invalid deduced user type!");
return [&tpl](attr_getter_t<u_t> const& gt) -> adc_result_t<attr_getter_t<v_t>> {
return [&tpl, &gt]() -> adc_result_t<v_t> {
return [&tpl](attr_getter_t<u_t> const& gt) -> ret_result_t<attr_getter_t<v_t>> {
return [&tpl, &gt]() -> ret_result_t<v_t> {
auto uv = gt();
if (uv) {
// convert to inner type from user's ("convert-to" function)
@@ -604,17 +602,17 @@ public:
};
};
auto st_cnv_to_func = []<size_t I, snplib::snplib_tuple_c TpT>(TpT const& tpl) {
auto st_cnv_to_func = []<size_t I, snplib::tuple_c TpT>(TpT const& tpl) {
using from_fn_t = std::decay_t<std::tuple_element_t<I, TpT>>;
using to_fn_t = std::decay_t<std::tuple_element_t<I + 1, TpT>>;
using u_t = adclib_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
using u_t = device_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
// using u_t = std::invoke_result_t<from_fn_t>::value_type;
// static_assert(requires(v_t v, u_t u) { v = u; }, "Invalid deduced user type!");
return [&tpl](attr_setter_t<u_t> const& st) -> adc_result_t<attr_setter_t<v_t>> {
return [&tpl](attr_setter_t<u_t> const& st) -> ret_result_t<attr_setter_t<v_t>> {
return [&tpl, &st](v_t const& val) -> adc_error_t {
// convert to user type from inner ("convert-from" function)!
auto uval = std::forward<std::tuple_element_t<I, TpT>>(std::get<I>(tpl))(val);
@@ -645,7 +643,7 @@ public:
// add attribute of one of arithmetic type
template <typename GT, typename ST>
requires std::is_arithmetic_v<adclib_attr_value_deduced_t<GT, ST>>
requires std::is_arithmetic_v<device_attr_value_deduced_t<GT, ST>>
void addArithAttr(ATTR_ID_T id, GT&& getter, ST&& setter)
{
// addAttr(std::move(id), std::forward<GT>(getter), std::forward<ST>(setter),
@@ -655,10 +653,10 @@ public:
// add attribute of char-range type
template <typename GT, typename ST>
requires snplib::snplib_char_range_c<adclib_attr_value_deduced_t<GT, ST>>
requires snplib::char_range_c<device_attr_value_deduced_t<GT, ST>>
void addCharRangeAttr(ATTR_ID_T id, GT&& getter, ST&& setter)
{
using v_t = adclib_attr_value_deduced_t<GT, ST>;
using v_t = device_attr_value_deduced_t<GT, ST>;
static_assert(!std::is_void_v<v_t>, "Getter and setter cannot be nullptr_t at the same time!");
if constexpr (!std::is_null_pointer_v<GT> && !std::is_null_pointer_v<ST>) {
@@ -681,10 +679,10 @@ public:
// add attribute of std::filesystem::path type
template <typename GT, typename ST>
requires std::same_as<adclib_attr_value_deduced_t<GT, ST>, std::filesystem::path>
requires std::same_as<device_attr_value_deduced_t<GT, ST>, std::filesystem::path>
void addFSPathAttr(ATTR_ID_T id, GT&& getter, ST&& setter)
{
using v_t = adclib_attr_value_deduced_t<GT, ST>;
using v_t = device_attr_value_deduced_t<GT, ST>;
static_assert(!std::is_void_v<v_t>, "Getter and setter cannot be nullptr_t at the same time!");
if constexpr (!std::is_null_pointer_v<GT> && !std::is_null_pointer_v<ST>) {
@@ -722,7 +720,7 @@ public:
// function-like access to attributes
template <typename VT>
adc_result_t<VT> attr(ATTR_ID_T id)
ret_result_t<VT> attr(ATTR_ID_T id)
{
return attr_t{*this, std::move(id)};
}