working tests/adc_asio_netserver_test.cpp
This commit is contained in:
@@ -206,10 +206,13 @@ protected:
|
||||
|
||||
std::function<void(const SerializedT&)> _deserializerFunc;
|
||||
|
||||
static inline std::vector<std::function<void(AdcDeviceAttribute*)>> _clearFunc{};
|
||||
// static inline std::vector<std::function<void(AdcDeviceAttribute*)>> _clearFunc{};
|
||||
std::vector<std::function<void(AdcDeviceAttribute*)>> _clearFunc{};
|
||||
|
||||
static inline std::vector<std::function<void(const AdcDeviceAttribute*, AdcDeviceAttribute*)>> _copyFunc{};
|
||||
static inline std::vector<std::function<void(AdcDeviceAttribute*, AdcDeviceAttribute*)>> _moveFunc{};
|
||||
// static inline std::vector<std::function<void(const AdcDeviceAttribute*, AdcDeviceAttribute*)>> _copyFunc{};
|
||||
// static inline std::vector<std::function<void(AdcDeviceAttribute*, AdcDeviceAttribute*)>> _moveFunc{};
|
||||
std::vector<std::function<void(const AdcDeviceAttribute*, AdcDeviceAttribute*)>> _copyFunc{};
|
||||
std::vector<std::function<void(AdcDeviceAttribute*, AdcDeviceAttribute*)>> _moveFunc{};
|
||||
|
||||
|
||||
public:
|
||||
@@ -251,11 +254,12 @@ public:
|
||||
}
|
||||
|
||||
if constexpr (!std::is_null_pointer_v<GT> && !std::is_null_pointer_v<SRT>) {
|
||||
_serializerFunc = [wrapper = traits::adc_pf_wrapper(std::forward<SRT>(serializer)), this]() {
|
||||
auto& getter_func = _getterFunc<ValueT>[this];
|
||||
_serializerFunc = [getter_func, wrapper = traits::adc_pf_wrapper(std::forward<SRT>(serializer)), this]() {
|
||||
auto& serializer = std::get<0>(wrapper);
|
||||
|
||||
|
||||
auto val = _getterFunc<ValueT>[this]();
|
||||
// auto val = _getterFunc<ValueT>[this]();
|
||||
auto val = getter_func();
|
||||
|
||||
return serializer(val);
|
||||
};
|
||||
@@ -263,13 +267,15 @@ public:
|
||||
|
||||
|
||||
if constexpr (!std::is_null_pointer_v<ST> && !std::is_null_pointer_v<DSRT>) {
|
||||
_deserializerFunc = [wrapper = traits::adc_pf_wrapper(std::forward<DSRT>(deserializer)),
|
||||
auto& setter_func = _setterFunc<ValueT>[this];
|
||||
_deserializerFunc = [setter_func, wrapper = traits::adc_pf_wrapper(std::forward<DSRT>(deserializer)),
|
||||
this](const SerializedT& sval) {
|
||||
auto& deserializer = std::get<0>(wrapper);
|
||||
|
||||
ValueT val = deserializer(sval);
|
||||
|
||||
AdcDeviceAttribute::_setterFunc<ValueT>[this](val);
|
||||
// _setterFunc<ValueT>[this](val);
|
||||
setter_func(val);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -379,10 +385,14 @@ public:
|
||||
AdcDeviceAttribute(const AdcDeviceAttribute& other)
|
||||
{
|
||||
if (&other != this) {
|
||||
for (auto& fn : _copyFunc) {
|
||||
// for (auto& fn : _copyFunc) {
|
||||
for (auto& fn : other._copyFunc) {
|
||||
fn(&other, this);
|
||||
}
|
||||
|
||||
_copyFunc = other._copyFunc;
|
||||
_moveFunc = other._moveFunc;
|
||||
_clearFunc = other._clearFunc;
|
||||
|
||||
_ident = other._ident;
|
||||
_accessType = other._accessType;
|
||||
@@ -394,10 +404,15 @@ public:
|
||||
AdcDeviceAttribute(AdcDeviceAttribute&& other)
|
||||
{
|
||||
if (&other != this) {
|
||||
for (auto& fn : _moveFunc) {
|
||||
// for (auto& fn : _moveFunc) {
|
||||
for (auto& fn : other._moveFunc) {
|
||||
fn(&other, this);
|
||||
}
|
||||
|
||||
_copyFunc = std::move(other._copyFunc);
|
||||
_moveFunc = std::move(other._moveFunc);
|
||||
_clearFunc = std::move(other._clearFunc);
|
||||
|
||||
_ident = std::move(other._ident);
|
||||
_accessType = std::move(other._accessType);
|
||||
_serializerFunc = std::move(other._serializerFunc);
|
||||
@@ -408,9 +423,9 @@ public:
|
||||
|
||||
virtual ~AdcDeviceAttribute()
|
||||
{
|
||||
// for (auto& fn : _clearFunc) {
|
||||
// fn(this);
|
||||
// };
|
||||
for (auto& fn : _clearFunc) {
|
||||
fn(this);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -447,7 +462,8 @@ public:
|
||||
auto& getter = _getterFunc<value_t>.at(this); // throw out_of_range if value_t is invalid
|
||||
|
||||
_getterFunc<user_t>[this] =
|
||||
[&getter, wrapper = traits::adc_pf_wrapper(std::forward<FromFuncT>(func_from_internal)), this]() {
|
||||
[getter, wrapper = traits::adc_pf_wrapper(std::forward<FromFuncT>(func_from_internal)), this]() {
|
||||
// auto val = _getterFunc<value_t>.at(this)(); // throw out_of_range if value_t is invalid
|
||||
auto val = getter();
|
||||
return std::get<0>(wrapper)(val); // convert from internal type
|
||||
};
|
||||
@@ -458,10 +474,13 @@ public:
|
||||
if (_accessType != AdcDeviceAttribute::ReadOnly) {
|
||||
auto& setter = _setterFunc<value_t>.at(this); // throw out_of_range if value_t is invalid
|
||||
|
||||
_setterFunc<user_t>[this] = [&setter,
|
||||
_setterFunc<user_t>[this] = [setter,
|
||||
wrapper = traits::adc_pf_wrapper(std::forward<ToFuncT>(func_to_internal)),
|
||||
this](const user_t& val) {
|
||||
value_t value = std::get<0>(wrapper)(val); // convert to internal type
|
||||
|
||||
// throw out_of_range if value_t is invalid
|
||||
// _setterFunc<value_t>.at(this)(value);
|
||||
setter(value);
|
||||
};
|
||||
} // ignore "to_internal" conversional function for read-only attribute
|
||||
@@ -534,6 +553,10 @@ public:
|
||||
fn(&other, this);
|
||||
}
|
||||
|
||||
_copyFunc = other._copyFunc;
|
||||
_moveFunc = other._moveFunc;
|
||||
_clearFunc = other._clearFunc;
|
||||
|
||||
_ident = other._ident;
|
||||
_accessType = other._accessType;
|
||||
_serializerFunc = other._serializerFunc;
|
||||
@@ -551,6 +574,9 @@ public:
|
||||
fn(&other, this);
|
||||
}
|
||||
|
||||
_copyFunc = std::move(other._copyFunc);
|
||||
_moveFunc = std::move(other._moveFunc);
|
||||
_clearFunc = std::move(other._clearFunc);
|
||||
|
||||
_ident = std::move(other._ident);
|
||||
_accessType = std::move(other._accessType);
|
||||
|
||||
Reference in New Issue
Block a user