11#include "comms/details/tag.h"
13#include "comms/field/basic/CommonFuncs.h"
28template <
typename TBase>
29class SequenceFixedSizeBase :
public TBase
31 using BaseImpl = TBase;
34 using ValueType =
typename BaseImpl::ValueType;
35 using ElementType =
typename BaseImpl::ElementType;
37 explicit SequenceFixedSizeBase(std::size_t maxSize)
38 : m_fixedSize(maxSize)
42 SequenceFixedSizeBase(std::size_t maxSize,
const ValueType& val)
48 SequenceFixedSizeBase(std::size_t maxSize, ValueType&& val)
49 : BaseImpl(
std::move(val)),
54 SequenceFixedSizeBase(
const SequenceFixedSizeBase&) =
default;
55 SequenceFixedSizeBase(SequenceFixedSizeBase&&) =
default;
56 SequenceFixedSizeBase& operator=(
const SequenceFixedSizeBase&) =
default;
57 SequenceFixedSizeBase& operator=(SequenceFixedSizeBase&&) =
default;
59 std::size_t length()
const
61 auto currSize = BaseImpl::getValue().size();
62 if (currSize == m_fixedSize) {
63 return BaseImpl::length();
66 if (currSize < m_fixedSize) {
67 auto remSize = m_fixedSize - currSize;
68 auto dummyElem = ElementType();
69 return BaseImpl::length() + (remSize * BaseImpl::elementLength(dummyElem));
73 typename comms::util::LazyShallowConditional<
74 std::is_integral<ElementType>::value && (
sizeof(ElementType) ==
sizeof(std::uint8_t))
80 return recalcLen(Tag());
83 template <
typename TIter>
86 return BaseImpl::readN(m_fixedSize, iter, len);
89 template <
typename TIter>
90 void readNoStatus(TIter& iter)
92 return BaseImpl::readNoStatusN(m_fixedSize, iter);
95 template <
typename TIter>
98 auto writeCount = std::min(BaseImpl::getValue().size(), m_fixedSize);
99 auto es = BaseImpl::writeN(writeCount, iter, len);
104 auto remCount = m_fixedSize - writeCount;
109 auto dummyElem = ElementType();
110 while (0 < remCount) {
111 es = BaseImpl::writeElement(dummyElem, iter, len);
122 template <
typename TIter>
123 void writeNoStatus(TIter& iter)
const
125 auto writeCount = std::min(BaseImpl::getValue().size(), m_fixedSize);
126 BaseImpl::writeNoStatusN(writeCount, iter);
128 auto remCount = m_fixedSize - writeCount;
133 auto dummyElem = ElementType();
134 while (0 < remCount) {
135 BaseImpl::writeElementNoStatus(dummyElem, iter);
142 return BaseImpl::valid() && (BaseImpl::getValue().size() <= m_fixedSize);
147 if (!BaseImpl::refresh()) {
152 typename comms::util::LazyShallowConditional<
153 comms::util::detect::hasResizeFunc<ElementType>()
159 return doRefresh(Tag());
163 template <
typename... TParams>
164 using HasRawDataTag = comms::details::tag::Tag1<>;
166 template <
typename... TParams>
167 using HasFieldsTag = comms::details::tag::Tag2<>;
169 template <
typename... TParams>
170 using HasFixedLengthElemsTag = comms::details::tag::Tag3<>;
172 template <
typename... TParams>
173 using HasVarLengthElemsTag = comms::details::tag::Tag4<>;
175 template <
typename... TParams>
176 using HasResizeTag = comms::details::tag::Tag5<>;
178 template <
typename... TParams>
179 using NoResizeTag = comms::details::tag::Tag6<>;
181 template <
typename... TParams>
182 std::size_t recalcLen(HasFieldsTag<TParams...>)
const
185 typename comms::util::LazyShallowConditional<
186 ElementType::minLength() == ElementType::maxLength()
188 HasFixedLengthElemsTag,
191 return recalcLen(Tag());
194 template <
typename... TParams>
195 std::size_t recalcLen(HasRawDataTag<TParams...>)
const
200 template <
typename... TParams>
201 std::size_t recalcLen(HasFixedLengthElemsTag<TParams...>)
const
203 return m_fixedSize * ElementType::minLength();
206 template <
typename... TParams>
207 std::size_t recalcLen(HasVarLengthElemsTag<TParams...>)
const
209 std::size_t result = 0U;
210 auto count = m_fixedSize;
211 for (
auto& elem : BaseImpl::getValue()) {
216 result += BaseImpl::elementLength(elem);
222 template <
typename... TParams>
223 bool doRefresh(HasResizeTag<TParams...>)
225 if (BaseImpl::getValue().size() == m_fixedSize) {
229 BaseImpl::value().resize(m_fixedSize);
233 template <
typename... TParams>
234 static constexpr bool doRefresh(NoResizeTag<TParams...>)
239 std::size_t m_fixedSize = 0;
242template <std::
size_t TSize,
typename TBase>
245 using BaseImpl = SequenceFixedSizeBase<TBase>;
248 using ValueType =
typename BaseImpl::ValueType;
249 using ElementType =
typename BaseImpl::ElementType;
257 : BaseImpl(TSize, val)
262 : BaseImpl(TSize,
std::move(val))
271 static constexpr std::size_t minLength()
273 return BaseImpl::minLength() + BaseImpl::minElementLength() * TSize;
276 static constexpr std::size_t maxLength()
278 return BaseImpl::minLength() + BaseImpl::maxElementLength() * TSize;
This file contains classes required for generic custom assertion functionality.
This file contain definition of error statuses used by comms module.
comms::option::def::SequenceFixedSize< TSize > SequenceFixedSize
Same as comms::option::def::SequenceFixedSize.
Definition options.h:1594
Main namespace for all classes / functions of COMMS library.
ErrorStatus
Error statuses reported by the Communication module.
Definition ErrorStatus.h:17
@ Success
Used to indicate successful outcome of the operation.
Replacement to some types from standard type_traits.
Various compile-time detection functions of whether specific member functions and/or types exist.