...
This commit is contained in:
parent
ba60fadb79
commit
070922e5d5
@ -47,7 +47,7 @@ namespace adc
|
|||||||
struct AdcValueHolderErrorCategory : public std::error_category {
|
struct AdcValueHolderErrorCategory : public std::error_category {
|
||||||
AdcValueHolderErrorCategory() : std::error_category() {}
|
AdcValueHolderErrorCategory() : std::error_category() {}
|
||||||
|
|
||||||
const char* name() const noexcept { return "ADC_VALUEHOLDER_CATEGORY"; }
|
const char* name() const noexcept { return "ADC_VALUE_HOLDER_CATEGORY"; }
|
||||||
|
|
||||||
std::string message(int ec) const
|
std::string message(int ec) const
|
||||||
{
|
{
|
||||||
@ -273,7 +273,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
template <typename UT>
|
template <typename UT>
|
||||||
operator UT()
|
operator UT() const
|
||||||
{
|
{
|
||||||
// using v_t = std::remove_reference_t<UT>;
|
// using v_t = std::remove_reference_t<UT>;
|
||||||
// using val_t = std::conditional_t<std::is_array_v<v_t>, std::add_pointer_t<std::remove_extent_t<v_t>>, v_t>;
|
// using val_t = std::conditional_t<std::is_array_v<v_t>, std::add_pointer_t<std::remove_extent_t<v_t>>, v_t>;
|
||||||
@ -422,6 +422,8 @@ public:
|
|||||||
AdcValueHolder::setupTrivialConvertFunc<VALT, std::decay_t<decltype(tpl)>>();
|
AdcValueHolder::setupTrivialConvertFunc<VALT, std::decay_t<decltype(tpl)>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AdcSerializingValueHolder(const AdcSerializingValueHolder&) = default;
|
||||||
|
AdcSerializingValueHolder(AdcSerializingValueHolder&&) = default;
|
||||||
|
|
||||||
virtual ~AdcSerializingValueHolder() = default;
|
virtual ~AdcSerializingValueHolder() = default;
|
||||||
|
|
||||||
@ -474,7 +476,24 @@ public:
|
|||||||
|
|
||||||
void deserialize(const SerializedT& sval) { _deserializerWrapper(sval); }
|
void deserialize(const SerializedT& sval) { _deserializerWrapper(sval); }
|
||||||
|
|
||||||
using AdcValueHolder::operator=;
|
AdcSerializingValueHolder& operator=(const AdcSerializingValueHolder&) = default;
|
||||||
|
AdcSerializingValueHolder& operator=(AdcSerializingValueHolder&&) = default;
|
||||||
|
|
||||||
|
template <typename UT>
|
||||||
|
AdcSerializingValueHolder& operator=(UT&& value)
|
||||||
|
{
|
||||||
|
AdcValueHolder::operator=(std::forward<UT>(value));
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// using AdcValueHolder::operator=;
|
||||||
|
|
||||||
|
// template <typename UT>
|
||||||
|
// operator UT()
|
||||||
|
// {
|
||||||
|
// return AdcValueHolder::operator UT();
|
||||||
|
// }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -13,10 +13,68 @@
|
|||||||
namespace adc
|
namespace adc
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename IdentT, typename SerializedT = std::string>
|
// error codes
|
||||||
class AdcDeviceAttribute : public AdcSerializingValueHolder<SerializedT>
|
enum class AdcDeviceAttributeErrorCode : int { ERROR_OK, ERROR_READ_ONLY, ERROR_WRITE_ONLY };
|
||||||
|
|
||||||
|
} // namespace adc
|
||||||
|
|
||||||
|
|
||||||
|
namespace std
|
||||||
{
|
{
|
||||||
using base_t = AdcSerializingValueHolder<SerializedT>;
|
|
||||||
|
template <>
|
||||||
|
class is_error_code_enum<adc::AdcDeviceAttributeErrorCode> : public true_type
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace std
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace adc
|
||||||
|
{
|
||||||
|
|
||||||
|
// error category
|
||||||
|
struct AdcDeviceAttributeErrorCategory : public std::error_category {
|
||||||
|
AdcDeviceAttributeErrorCategory() : std::error_category() {}
|
||||||
|
|
||||||
|
const char* name() const noexcept { return "ADC_DEVICE_ATTRIBUTE_CATEGORY"; }
|
||||||
|
|
||||||
|
std::string message(int ec) const
|
||||||
|
{
|
||||||
|
AdcDeviceAttributeErrorCode err = static_cast<AdcDeviceAttributeErrorCode>(ec);
|
||||||
|
|
||||||
|
switch (err) {
|
||||||
|
case AdcDeviceAttributeErrorCode::ERROR_OK:
|
||||||
|
return "OK";
|
||||||
|
case AdcDeviceAttributeErrorCode::ERROR_READ_ONLY:
|
||||||
|
return "device attribute is read-only";
|
||||||
|
case AdcDeviceAttributeErrorCode::ERROR_WRITE_ONLY:
|
||||||
|
return "device attribute is write-only";
|
||||||
|
default:
|
||||||
|
return "UNKNOWN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const AdcDeviceAttributeErrorCategory& get()
|
||||||
|
{
|
||||||
|
static const AdcDeviceAttributeErrorCategory constInst;
|
||||||
|
return constInst;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline std::error_code make_error_code(AdcDeviceAttributeErrorCode ec)
|
||||||
|
{
|
||||||
|
return std::error_code(static_cast<int>(ec), AdcDeviceAttributeErrorCategory::get());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <typename IdentT, typename SerializedT = std::string>
|
||||||
|
class AdcDeviceAttribute : protected AdcSerializingValueHolder<SerializedT>
|
||||||
|
{
|
||||||
|
typedef AdcSerializingValueHolder<SerializedT> base_t;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using ret_value_t = base_t::template ret_value_t<T>;
|
using ret_value_t = base_t::template ret_value_t<T>;
|
||||||
@ -142,6 +200,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AdcDeviceAttribute(const AdcDeviceAttribute&) = default;
|
||||||
|
AdcDeviceAttribute(AdcDeviceAttribute&&) = default;
|
||||||
|
|
||||||
|
|
||||||
virtual ~AdcDeviceAttribute() = default;
|
virtual ~AdcDeviceAttribute() = default;
|
||||||
|
|
||||||
@ -149,7 +210,31 @@ public:
|
|||||||
|
|
||||||
AccessType accessType() const { return _accessType; }
|
AccessType accessType() const { return _accessType; }
|
||||||
|
|
||||||
using base_t::operator=;
|
template <typename UT>
|
||||||
|
operator UT() const
|
||||||
|
{
|
||||||
|
if (_accessType == WriteOnly) {
|
||||||
|
throw std::system_error(AdcDeviceAttributeErrorCode::ERROR_WRITE_ONLY);
|
||||||
|
}
|
||||||
|
|
||||||
|
return base_t::operator UT();
|
||||||
|
}
|
||||||
|
|
||||||
|
AdcDeviceAttribute& operator=(const AdcDeviceAttribute&) = default;
|
||||||
|
AdcDeviceAttribute& operator=(AdcDeviceAttribute&&) = default;
|
||||||
|
|
||||||
|
template <typename UT>
|
||||||
|
AdcDeviceAttribute& operator=(UT&& value)
|
||||||
|
{
|
||||||
|
if (_accessType == ReadOnly) {
|
||||||
|
throw std::system_error(AdcDeviceAttributeErrorCode::ERROR_READ_ONLY);
|
||||||
|
}
|
||||||
|
|
||||||
|
base_t::operator=(std::forward<UT>(value));
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
IdentT _ident;
|
IdentT _ident;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user