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

@@ -9,7 +9,7 @@ using namespace adc;
template <typename ID_T, typename VT>
void add_attr_mark(ID_T id, VT const& val, std::string_view acc = "RW")
{
auto tp = snplib::snplib_get_type_name<VT>();
auto tp = snplib::type_name_as_string<VT>();
std::println("add {}-attr with ID='{}' of type '{}'", acc, id, tp);
}
@@ -17,7 +17,7 @@ void add_attr_mark(ID_T id, VT const& val, std::string_view acc = "RW")
template <typename DEV_T, typename VT>
void set_attr(DEV_T& dev, typename DEV_T::attr_id_t id, VT const& val)
{
auto tp = snplib::snplib_get_type_name<VT>();
auto tp = snplib::type_name_as_string<VT>();
std::print("set '{}'-attr value to {} of type '{}':\t", id, val, tp);
@@ -30,11 +30,11 @@ void set_attr(DEV_T& dev, typename DEV_T::attr_id_t id, VT const& val)
}
template <typename DEV_T, typename VT>
void get_attr(DEV_T& dev, typename DEV_T::attr_id_t id, adc_result_t<VT>& val)
void get_attr(DEV_T& dev, typename DEV_T::attr_id_t id, ret_result_t<VT>& val)
{
std::string tp;
[&tp]<typename T>(T v) { tp = snplib::snplib_get_type_name<T>(); }(val.value());
[&tp]<typename T>(T v) { tp = snplib::type_name_as_string<T>(); }(val.value());
std::print("get '{}'-attr value as one of type '{}':\t", id, tp);
@@ -59,7 +59,7 @@ int main()
std::println("add arith RW-attr with id='{}' (val={})", id1, i);
dev.addArithAttr(
id1, [&i]() -> adc_result_t<int> { return i; },
id1, [&i]() -> ret_result_t<int> { return i; },
[&i](int const& ii) -> adc_error_t {
i = ii;
return AdcDeviceErrorCode::ERROR_OK;
@@ -74,7 +74,7 @@ int main()
// std::tuple<double, int, long>{});
std::println("add RO-attr with id='{}' (val={})", id2, d);
dev.addAttr(id2, [&d]() -> adc_result_t<double> { return d; }, nullptr);
dev.addAttr(id2, [&d]() -> ret_result_t<double> { return d; }, nullptr);
// std::println("add RW-attr with id='{}' (val={})", id3, s);
// dev.addAttr(
@@ -95,7 +95,7 @@ int main()
std::println("add RW-attr with id='{}' (val={})", id3, s);
dev.addCharRangeAttr(
id3, [&s]() -> adc_result_t<std::string> { return s; },
id3, [&s]() -> ret_result_t<std::string> { return s; },
[&s](std::string const& sv) -> adc_error_t {
s = sv;
return {};
@@ -104,14 +104,14 @@ int main()
// std::println("add RW-attr with id='{}' (val={})", id4, pt.native());
add_attr_mark(id4, pt);
dev.addFSPathAttr(
id4, [&pt]() -> adc_result_t<std::filesystem::path> { return pt; },
id4, [&pt]() -> ret_result_t<std::filesystem::path> { return pt; },
[&pt](std::filesystem::path const& p) -> adc_error_t {
pt = p;
return {};
});
std::print("get '{}'-attr value as native int:\t", id1);
adc_result_t<int> ri = dev[id1];
ret_result_t<int> ri = dev[id1];
if (ri) {
std::println("dev[{}] = {}", id1, ri.value());
} else {
@@ -128,7 +128,7 @@ int main()
}
std::print("get '{}'-attr value as double:\t", id1);
adc_result_t<double> rd = dev[id1];
ret_result_t<double> rd = dev[id1];
if (rd) {
std::println("dev[{}] = {}", id1, rd.value());
} else {
@@ -160,7 +160,7 @@ int main()
std::println("\n");
std::print("get '{}'-attr value as native string:\t", id3);
adc_result_t<std::string> rs = dev[id3];
ret_result_t<std::string> rs = dev[id3];
if (rs) {
std::println("dev[{}] = {}", id3, rs.value());
} else {

View File

@@ -8,7 +8,7 @@ int main()
std::println("is ACK: {}", msg.isACK());
msg.createSET("ATTR1", snplib::snplib_serialization_params_t{}, 10, std::vector<char>{'V', 'A', 'L'});
msg.createSET("ATTR1", snplib::serialization_params_t{}, 10, std::vector<char>{'V', 'A', 'L'});
std::println("KEY: <{}>", msg.key());

View File

@@ -12,11 +12,11 @@ namespace adc
typedef std::error_code adc_error_t;
template <typename VT>
using adc_result_t = std::expected<VT, adc_error_t>;
using ret_result_t = std::expected<VT, adc_error_t>;
template <typename T>
concept adc_result_c = requires {
[]<typename VT>(std::type_identity<adc_result_t<VT>>) {}(std::type_identity<std::remove_cvref_t<T>>());
concept ret_result_c = requires {
[]<typename VT>(std::type_identity<ret_result_t<VT>>) {}(std::type_identity<std::remove_cvref_t<T>>());
};
} // namespace adc

View File

@@ -103,29 +103,29 @@ 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) {
concept device_attr_getter_c = std::same_as<T, std::nullptr_t> || requires(T t) {
{ t() } -> adc_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<
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>
template <adclib_attr_getter_c GT, device_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>>;
};
@@ -134,22 +134,20 @@ struct adclib_is_deduced_void_t {
// "from": adc_result_t<UT> func(const adc_result_t<VT>&)
// "to": adc_result_t<VT> func(const adc_result_t<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 adc_result_t<VT>&> && !std::is_void_v<std::invoke_result_t<T, const adc_result_t<VT>&>>);
(std::invocable<T, const ret_result_t<VT>&> && !std::is_void_v<std::invoke_result_t<T, const ret_result_t<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>;
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>;
@@ -161,7 +159,7 @@ class AdcGenericDevice
protected:
template <typename VT>
struct attr_t {
std::function<adc_result_t<VT>()> getter{};
std::function<ret_result_t<VT>()> getter{};
std::function<adc_error_t(VT const&)> setter{};
// template <typename UT>
@@ -195,7 +193,7 @@ protected:
requires requires(VT v, UT u) { v = u; }
operator attr_t<UT>() const
{
return attr_t<UT>{.getter = [this]() -> adc_result_t<UT> {
return attr_t<UT>{.getter = [this]() -> ret_result_t<UT> {
auto val = getter();
if (val) {
return static_cast<UT>(val.value());
@@ -206,8 +204,8 @@ protected:
.setter = [this](UT const& u) { return setter(static_cast<VT>(u)); }};
}
adc_error_t serialize(snplib::snplib_output_char_range_c auto& output,
snplib::snplib_serialization_params_c auto const& params)
adc_error_t serialize(snplib::output_char_range_c auto& output,
snplib::serialization_params_c auto const& params)
{
if (!getter) {
return AdcDeviceErrorCode::ERROR_WO_ATTR;
@@ -215,9 +213,9 @@ protected:
auto val = getter();
if (val) {
auto ret = snplib::snplib_serializer_t<VT>{}(output, val.value(), params);
auto ret = snplib::serializer_t<VT>{}(output, val.value(), params);
if (ret) {
return snplib::snplib_deduced_error(ret, AdcDeviceErrorCode::ERROR_SERIALIZATION);
return snplib::deduced_ret_error(ret, AdcDeviceErrorCode::ERROR_SERIALIZATION);
}
return AdcDeviceErrorCode::ERROR_OK;
@@ -226,17 +224,17 @@ protected:
return val.error();
}
adc_error_t deserialize(snplib::snplib_input_char_range_c auto const& input,
snplib::snplib_serialization_params_c auto const& params)
adc_error_t deserialize(snplib::input_char_range_c auto const& input,
snplib::serialization_params_c auto const& params)
{
if (!setter) {
return AdcDeviceErrorCode::ERROR_RO_ATTR;
}
VT value; // WARNING: must be default-constructible!!!
auto ret = snplib::snplib_deserializer_t<VT>{}(input, value, params);
auto ret = snplib::deserializer_t<VT>{}(input, value, params);
if (ret) {
return snplib::snplib_deduced_error(ret, AdcDeviceErrorCode::ERROR_DESERIALIZATION);
return snplib::deduced_ret_error(ret, AdcDeviceErrorCode::ERROR_DESERIALIZATION);
}
return setter(value);
@@ -248,7 +246,7 @@ protected:
attr_proxy_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 attr = _dev._attrs.template get<attr_t<VT>>(_id);
if (attr) {
@@ -329,13 +327,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));
@@ -355,7 +353,7 @@ public:
std::tuple<attr_t<VTs>...>{});
}
template <adclib_attr_getter_c GT, adclib_attr_setter_c ST, typename... FuncTs>
template <adclib_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)
{
@@ -380,7 +378,7 @@ public:
// 1, decltype(tp)>>...>,
// "Getter and setter cannot be nullptr_t at the same time!");
auto from_cnv_func = []<size_t I, snplib::snplib_tuple_c TpT>(TpT const& func_tp) {
auto from_cnv_func = []<size_t I, snplib::tuple_c TpT>(TpT const& func_tp) {
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>>;
@@ -388,7 +386,7 @@ public:
return [&func_tp](attr_t<v_t> const& attr) mutable -> attr_t<u_t> {
return attr_t<u_t>{
.getter = [&attr, &func_tp]() mutable -> adc_result_t<u_t> {
.getter = [&attr, &func_tp]() mutable -> ret_result_t<u_t> {
return std::forward<std::tuple_element_t<I, TpT>>(std::get<I>(func_tp))(attr.getter());
},
.setter = [&attr, &func_tp](u_t const& uv) mutable -> adc_error_t {
@@ -402,7 +400,7 @@ public:
}};
};
};
// auto from_cnv_func = []<size_t I, snplib::snplib_tuple_c TpT>(TpT&& func_tp) {
// auto from_cnv_func = []<size_t I, snplib::tuple_c TpT>(TpT&& func_tp) {
// using tp_t = std::remove_cvref_t<TpT>;
// using from_fn_t = std::decay_t<std::tuple_element_t<I, tp_t>>;
@@ -434,7 +432,7 @@ public:
// };
// };
auto to_cnv_func = [id, this]<size_t I, snplib::snplib_tuple_c TpT>(TpT const& func_tp) {
auto to_cnv_func = [id, this]<size_t I, snplib::tuple_c TpT>(TpT const& func_tp) {
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>>;
@@ -481,7 +479,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_proxy_t{*this, std::move(id)};
}

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)};
}

View File

@@ -32,10 +32,10 @@ static constexpr std::array ADCLIB_NETMSG_VALID_KEYWORDS{ADCLIB_NETMSG_KEYWORD_A
ADCLIB_NETMSG_KEYWORD_CMD};
template <snplib::snplib_char_range_c CharRangeT = std::vector<char>>
class AdcNetworkMessage final : protected snplib::snplib_keyvalue_expr_t<CharRangeT>
template <snplib::char_range_c CharRangeT = std::vector<char>>
class AdcNetworkMessage final : protected snplib::keyvalue_expr_t<CharRangeT>
{
typedef snplib::snplib_keyvalue_expr_t<CharRangeT> base_t;
typedef snplib::keyvalue_expr_t<CharRangeT> base_t;
public:
using typename base_t::error_t;
@@ -72,7 +72,7 @@ public:
return std::ranges::equal(this->_key, ADCLIB_NETMSG_KEYWORD_GET);
}
error_t fromCharRange(snplib::snplib_input_char_range_c auto&& bytes)
error_t fromCharRange(snplib::input_char_range_c auto&& bytes)
requires(!std::same_as<CharRangeT, std::remove_cvref_t<decltype(bytes)>>)
{
// auto err = fromCharRange(
@@ -118,7 +118,7 @@ public:
return this->setKeyValue(ADCLIB_NETMSG_KEYWORD_ERR, err.value());
}
template <snplib::snplib_serializable_c ATTR_NAME_T, typename... ArgTs>
template <snplib::serializable_c ATTR_NAME_T, typename... ArgTs>
requires(sizeof...(ArgTs) > 0)
error_t createSET(ATTR_NAME_T&& attr_name, ArgTs&&... args)
{
@@ -139,7 +139,7 @@ public:
return err;
}
template <snplib::snplib_serializable_c ATTR_NAME_T, typename... ArgTs>
template <snplib::serializable_c ATTR_NAME_T, typename... ArgTs>
error_t createGET(ATTR_NAME_T&& attr_name, ArgTs&&... args)
{
this->_isValid = false;
@@ -161,7 +161,7 @@ public:
return err;
}
template <snplib::snplib_serializable_c CMD_NAME_T>
template <snplib::serializable_c CMD_NAME_T>
error_t createCMD(CMD_NAME_T&& cmd_name)
{
this->_isValid = false;