27#include <QtCore/QString>
29#include "comms/comms.h"
31#include "FieldWrapper.h"
36namespace field_wrapper
39class CC_API ArrayListRawDataWrapper :
public FieldWrapper
43 typedef std::unique_ptr<ArrayListRawDataWrapper> Ptr;
45 ArrayListRawDataWrapper();
46 virtual ~ArrayListRawDataWrapper() noexcept;
48 QString getValue() const;
50 void setValue(const QString& val);
58 bool getForcedShowAll() const;
59 void setForcedShowAll(
bool val = true);
60 bool isTruncated() const;
63 virtual QString getValueImpl() const = 0;
64 virtual
void setValueImpl(const QString& val) = 0;
65 virtual
int maxSizeImpl() const = 0;
66 virtual
int minSizeImpl() const = 0;
67 virtual Ptr cloneImpl() = 0;
69 void dispatchImpl(FieldWrapperHandler& handler);
71 static const std::
size_t TruncateLength = 128;
74 bool m_forcedShowAll = false;
77template <typename TField>
78class ArrayListRawDataWrapperT : public FieldWrapperT<ArrayListRawDataWrapper, TField>
80 using Base = FieldWrapperT<ArrayListRawDataWrapper, TField>;
84 using SerialisedSeq =
typename Base::SerialisedSeq;
85 typedef typename Base::Ptr Ptr;
87 explicit ArrayListRawDataWrapperT(Field& fieldRef)
92 ArrayListRawDataWrapperT(
const ArrayListRawDataWrapperT&) =
default;
93 ArrayListRawDataWrapperT(ArrayListRawDataWrapperT&&) =
default;
94 virtual ~ArrayListRawDataWrapperT() noexcept = default;
96 ArrayListRawDataWrapperT& operator=(const ArrayListRawDataWrapperT&) = delete;
100 virtual QString getValueImpl()
const override
103 auto& dataField = Base::field();
104 auto& data = dataField.value();
106 int maxLen =
static_cast<int>(Base::length() * 2);
107 if (Base::isTruncated()) {
108 maxLen =
static_cast<decltype(maxLen)
>(Base::TruncateLength * 2);
111 for (
auto byte : data) {
112 if (maxLen <= retStr.size()) {
116 retStr.append(QString(
"%1").arg(
static_cast<uint
>(
byte), 2, 16, QChar(
'0')));
121 virtual void setValueImpl(
const QString& val)
override
127 [&data, &byteStr]()
mutable
130 auto intVal = byteStr.toInt(&ok, 16);
135 data.push_back(
static_cast<typename SerialisedSeq::value_type
>(intVal));
139 for (
auto ch : val) {
140 if (((ch <
'0') || (
'9' < ch)) &&
141 ((ch.toLower() <
'a') || (
'f' < ch.toLower()))) {
147 if (2 <= byteStr.size()) {
152 if (!byteStr.isEmpty()) {
157 Base::setSerialisedValueImpl(data);
160 virtual SerialisedSeq getSerialisedValueImpl()
const override
162 auto serValue = Base::getSerialisedValueImpl();
163 if (Base::isTruncated()) {
164 serValue.resize(Base::TruncateLength);
170 virtual bool setSerialisedValueImpl([[maybe_unused]]
const SerialisedSeq& value)
override
172 [[maybe_unused]]
static constexpr bool Must_not_be_called =
false;
173 assert(Must_not_be_called);
177 virtual int maxSizeImpl()
const override
179 return maxSizeInternal(SizeExistanceTag());
182 virtual int minSizeImpl()
const override
184 return minSizeInternal(SizeExistanceTag());
187 virtual Ptr cloneImpl()
override
189 return Ptr(
new ArrayListRawDataWrapperT<TField>(Base::field()));
193 struct SizeFieldExistsTag {};
194 struct SerLengthFieldExistsTag {};
195 struct FixedSizeTag {};
196 struct NoLimitsTag {};
198 typedef typename std::conditional<
199 Field::hasSizeFieldPrefix(),
201 typename std::conditional<
202 Field::hasSerLengthFieldPrefix(),
203 SerLengthFieldExistsTag,
204 typename std::conditional<
205 Field::hasFixedSize(),
210 >::type SizeExistanceTag;
212 template <
typename TPrefixField>
213 static int maxSizeByPrefix()
215 if (
sizeof(
int) <= TPrefixField::maxLength()) {
216 return std::numeric_limits<int>::max();
220 TPrefixField::maxLength() * std::numeric_limits<std::uint8_t>::digits;
222 return static_cast<int>((1U << shift) - 1);
225 static int maxSizeInternal(SizeFieldExistsTag)
227 typedef typename Field::SizeFieldPrefix PrefixField;
228 return maxSizeByPrefix<PrefixField>();
231 static int maxSizeInternal(SerLengthFieldExistsTag)
233 typedef typename Field::SerLengthFieldPrefix PrefixField;
234 return maxSizeByPrefix<PrefixField>();
237 static int maxSizeInternal(FixedSizeTag)
239 return static_cast<int>(Field::fixedSize());
242 int maxSizeInternal(NoLimitsTag)
const
247 static_cast<std::size_t
>(std::numeric_limits<int>::max()),
248 Base::field().value().max_size()));
251 static int minSizeInternal(SizeFieldExistsTag)
256 static int minSizeInternal(SerLengthFieldExistsTag)
261 static int minSizeInternal(FixedSizeTag)
263 return static_cast<int>(Field::fixedSize());
266 int minSizeInternal(NoLimitsTag)
const
272using ArrayListRawDataWrapperPtr = ArrayListRawDataWrapper::Ptr;
274template <
typename TField>
275ArrayListRawDataWrapperPtr
276makeArrayListRawDataWrapper(TField& field)
279 ArrayListRawDataWrapperPtr(
280 new ArrayListRawDataWrapperT<TField>(field));