29#include "FieldWrapper.h"
34namespace field_wrapper
37template <
typename TUnderlyingType>
38class NumericValueWrapper :
public FieldWrapper
40 static_assert(std::is_integral<TUnderlyingType>::value || std::is_floating_point<TUnderlyingType>::value,
41 "Underlying type is expected to be integral or floating point.");
42 typedef FieldWrapper Base;
44 typedef TUnderlyingType UnderlyingType;
45 typedef Base::SerialisedSeq SerialisedSeq;
47 NumericValueWrapper() {}
49 virtual ~NumericValueWrapper() noexcept = default;
51 UnderlyingType getValue()
const
53 return getValueImpl();
56 void setValue(UnderlyingType value)
61 std::size_t minLength()
const
63 return minLengthImpl();
66 std::size_t maxLength()
const
68 return maxLengthImpl();
73 return static_cast<int>(minLength()) * 2;
78 return static_cast<int>(maxLength()) * 2;
82 virtual UnderlyingType getValueImpl()
const = 0;
83 virtual void setValueImpl(UnderlyingType value) = 0;
84 virtual std::size_t minLengthImpl()
const = 0;
85 virtual std::size_t maxLengthImpl()
const = 0;
88template <
typename TBase,
typename TField>
89class NumericValueWrapperT :
public FieldWrapperT<TBase, TField>
91 using Base = FieldWrapperT<TBase, TField>;
94 using UnderlyingType =
typename Base::UnderlyingType;
95 using SerialisedSeq =
typename Base::SerialisedSeq;
99 using ValueType =
typename Field::ValueType;
101 static_assert(
sizeof(ValueType) <=
sizeof(UnderlyingType),
"This wrapper cannot handle provided field.");
108 explicit NumericValueWrapperT(Field& fieldRef)
111 static_assert(std::is_base_of<NumericValueWrapper<UnderlyingType>, NumericValueWrapperT<TBase, TField> >::value,
112 "Must inherit from NumericValueWrapper");
115 NumericValueWrapperT(
const NumericValueWrapperT&) =
default;
116 NumericValueWrapperT(NumericValueWrapperT&&) =
default;
117 virtual ~NumericValueWrapperT() noexcept = default;
119 NumericValueWrapperT& operator=(const NumericValueWrapperT&) = delete;
123 virtual UnderlyingType getValueImpl()
const override
125 return static_cast<UnderlyingType
>(Base::field().getValue());
128 virtual void setValueImpl(UnderlyingType value)
override
130 Base::field().setValue(value);
133 virtual std::size_t minLengthImpl()
const override
135 return Base::field().minLength();
138 virtual std::size_t maxLengthImpl()
const override
140 return Base::field().maxLength();