...
This commit is contained in:
parent
222691d2e9
commit
3b1a318ee7
@ -122,7 +122,7 @@ public:
|
||||
|
||||
AdcGenericDevice& addCommand(CommandT&& cmd)
|
||||
{
|
||||
_deviceCommands.insert(std::move(cmd));
|
||||
_deviceCommands.insert({cmd.ident(), std::move(cmd)});
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -131,9 +131,10 @@ public:
|
||||
template <typename... CtorArgTs>
|
||||
AdcGenericDevice& addCommand(CtorArgTs&&... ctor_args)
|
||||
{
|
||||
_deviceCommands.emplace(std::forward<CtorArgTs>(ctor_args)...);
|
||||
// _deviceCommands.emplace(std::forward<CtorArgTs>(ctor_args)...);
|
||||
return addCommand({std::forward<CtorArgTs>(ctor_args)...});
|
||||
|
||||
return *this;
|
||||
// return *this;
|
||||
}
|
||||
|
||||
AdcGenericDevice& delCommand(const cmd_ident_t& cmd_ident)
|
||||
@ -146,7 +147,7 @@ public:
|
||||
|
||||
AdcGenericDevice& addAttribute(AttributeT&& attr)
|
||||
{
|
||||
_deviceAttributes.insert(std::move(attr));
|
||||
_deviceAttributes.insert({attr.ident(), std::move(attr)});
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -154,9 +155,11 @@ public:
|
||||
template <typename... CtorArgTs>
|
||||
AdcGenericDevice& addAttribute(CtorArgTs&&... ctor_args)
|
||||
{
|
||||
_deviceAttributes.emplace(std::forward<CtorArgTs>(ctor_args)...);
|
||||
// _deviceAttributes.emplace(std::forward<CtorArgTs>(ctor_args)...);
|
||||
|
||||
return *this;
|
||||
return addAttribute({std::forward<CtorArgTs>(ctor_args)...});
|
||||
|
||||
// return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -294,6 +294,15 @@ public:
|
||||
|
||||
_serializerFunc<SerializedT>.emplace(other, _serializerFunc<SerializedT>[this]);
|
||||
_deserializerFunc<SerializedT>.emplace(other, _deserializerFunc<SerializedT>[this]);
|
||||
|
||||
// define copy-function for newly constructed object
|
||||
other->_copyFunc = [other](AdcDeviceAttribute* o_next) {
|
||||
_getterFunc<ValueT>.emplace(o_next, _getterFunc<ValueT>[other]);
|
||||
_setterFunc<ValueT>.emplace(o_next, _setterFunc<ValueT>[other]);
|
||||
|
||||
_serializerFunc<SerializedT>.emplace(o_next, _serializerFunc<SerializedT>[other]);
|
||||
_deserializerFunc<SerializedT>.emplace(o_next, _deserializerFunc<SerializedT>[other]);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -304,6 +313,15 @@ public:
|
||||
|
||||
_serializerFunc<SerializedT>.emplace(other, std::move(_serializerFunc<SerializedT>[this]));
|
||||
_deserializerFunc<SerializedT>.emplace(other, std::move(_deserializerFunc<SerializedT>[this]));
|
||||
|
||||
// define move-function for newly constructed object
|
||||
other->_moveFunc = [other](AdcDeviceAttribute* o_next) {
|
||||
_getterFunc<ValueT>.emplace(o_next, std::move(_getterFunc<ValueT>[other]));
|
||||
_setterFunc<ValueT>.emplace(o_next, std::move(_setterFunc<ValueT>[other]));
|
||||
|
||||
_serializerFunc<SerializedT>.emplace(o_next, std::move(_serializerFunc<SerializedT>[other]));
|
||||
_deserializerFunc<SerializedT>.emplace(o_next, std::move(_deserializerFunc<SerializedT>[other]));
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@ -398,30 +416,34 @@ public:
|
||||
|
||||
AdcDeviceAttribute(const AdcDeviceAttribute& other)
|
||||
{
|
||||
_clearFunc();
|
||||
// _clearFunc();
|
||||
|
||||
if (&other != this) {
|
||||
other._copyFunc(this);
|
||||
}
|
||||
|
||||
_clearFunc = other._clearFunc;
|
||||
_copyFunc = other._copyFunc;
|
||||
_moveFunc = other._moveFunc;
|
||||
// _clearFunc = other._clearFunc;
|
||||
// _copyFunc = other._copyFunc;
|
||||
// _moveFunc = other._moveFunc;
|
||||
}
|
||||
|
||||
AdcDeviceAttribute(AdcDeviceAttribute&& other)
|
||||
{
|
||||
_clearFunc();
|
||||
|
||||
if (&other != this) {
|
||||
other._moveFunc(this);
|
||||
}
|
||||
|
||||
_clearFunc = std::move(other._clearFunc);
|
||||
_copyFunc = std::move(other._copyFunc);
|
||||
_moveFunc = std::move(other._moveFunc);
|
||||
// other._clearFunc();
|
||||
|
||||
// _clearFunc = std::move(other._clearFunc);
|
||||
// _copyFunc = std::move(other._copyFunc);
|
||||
// _moveFunc = std::move(other._moveFunc);
|
||||
}
|
||||
|
||||
|
||||
virtual ~AdcDeviceAttribute()
|
||||
{
|
||||
_clearFunc();
|
||||
// _clearFunc();
|
||||
}
|
||||
|
||||
|
||||
@ -559,13 +581,13 @@ public:
|
||||
AdcDeviceAttribute& operator=(const AdcDeviceAttribute& other)
|
||||
{
|
||||
if (&other != this) {
|
||||
_clearFunc();
|
||||
// _clearFunc();
|
||||
|
||||
other._copyFunc(this);
|
||||
|
||||
_clearFunc = other._clearFunc;
|
||||
_copyFunc = other._copyFunc;
|
||||
_moveFunc = other._moveFunc;
|
||||
// _clearFunc = other._clearFunc;
|
||||
// _copyFunc = other._copyFunc;
|
||||
// _moveFunc = other._moveFunc;
|
||||
}
|
||||
|
||||
return *this;
|
||||
@ -575,13 +597,13 @@ public:
|
||||
AdcDeviceAttribute& operator=(AdcDeviceAttribute&& other)
|
||||
{
|
||||
if (&other != this) {
|
||||
_clearFunc();
|
||||
// _clearFunc();
|
||||
|
||||
other._moveFunc(this);
|
||||
|
||||
_clearFunc = std::move(other._clearFunc);
|
||||
_copyFunc = std::move(other._copyFunc);
|
||||
_moveFunc = std::move(other._moveFunc);
|
||||
// _clearFunc = std::move(other._clearFunc);
|
||||
// _copyFunc = std::move(other._copyFunc);
|
||||
// _moveFunc = std::move(other._moveFunc);
|
||||
}
|
||||
|
||||
return *this;
|
||||
|
||||
@ -20,11 +20,6 @@ public:
|
||||
template <adc::traits::adc_char_range R>
|
||||
Device1(R&& id) : base_t(id)
|
||||
{
|
||||
if constexpr (std::is_array_v<std::decay_t<R>>) {
|
||||
this->_ident = std::forward<R>(id);
|
||||
} else {
|
||||
std::ranges::copy(std::forward<R>(id), std::back_inserter(this->_ident));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -38,11 +33,6 @@ public:
|
||||
template <adc::traits::adc_char_range R>
|
||||
Device2(R&& id) : base_t(id)
|
||||
{
|
||||
if constexpr (std::is_array_v<std::decay_t<R>>) {
|
||||
this->_ident = std::forward<R>(id);
|
||||
} else {
|
||||
std::ranges::copy(std::forward<R>(id), std::back_inserter(this->_ident));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -68,17 +58,17 @@ int main(int argc, char* argv[])
|
||||
Device2 dev2("DEVICE#2");
|
||||
|
||||
// device#1
|
||||
dev1.addCommand({"DEV1::COM1", []() { std::cout << "EXEC DEV1::COM1\n"; }});
|
||||
dev1.addCommand("DEV1::COM1", []() { std::cout << "EXEC DEV1::COM1\n"; });
|
||||
dev1.addAttribute(
|
||||
{"DEV1::ATTR1", [&dev1_val1]() { return dev1_val1; }, [&dev1_val1](const int& v) { dev1_val1 = v; }});
|
||||
"DEV1::ATTR1", [&dev1_val1]() { return dev1_val1; }, [&dev1_val1](const int& v) { dev1_val1 = v; });
|
||||
|
||||
dev1.addAttribute({"DEV1::ATTR2", gt, st});
|
||||
dev1.addAttribute("DEV1::ATTR2", gt, st);
|
||||
|
||||
// device#2
|
||||
// read-only attr
|
||||
dev2.addAttribute({0x1, [&dev1_val1]() { return dev1_val1; }});
|
||||
dev2.addAttribute(0x1ul, [&dev1_val1]() { return dev1_val1; });
|
||||
// write-only
|
||||
dev2.addAttribute({0xff, [&dev1_val1](const int& v) { dev1_val1 = v; }});
|
||||
dev2.addAttribute(0xfful, [&dev1_val1](const int& v) { dev1_val1 = v; });
|
||||
|
||||
|
||||
/* COMMANDLINE OPTS */
|
||||
@ -92,7 +82,7 @@ int main(int argc, char* argv[])
|
||||
"endpoints server will be listening for. For 'local' endpoint the '@' symbol at the beginning of the path "
|
||||
"means "
|
||||
"abstract namespace socket.",
|
||||
cxxopts::value<std::vector<std::string>>()->default_value("local://stream/@ADC_ASIO_TEST_SERVER"));
|
||||
cxxopts::value<std::vector<std::string>>()->default_value("local://stream/ADC_ASIO_TEST_SERVER"));
|
||||
|
||||
|
||||
options.positional_help("[endpoint0] [enpoint1] ... [endpointN]");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user