14#include "comms/details/tag.h"
16#include "comms/field/basic/CommonFuncs.h"
35template <
typename TBase>
36class SequenceFixedSizeBase :
public TBase
38 using BaseImpl = TBase;
41 using ValueType =
typename BaseImpl::ValueType;
42 using ElementType =
typename BaseImpl::ElementType;
44 explicit SequenceFixedSizeBase(std::size_t maxSize)
45 : m_fixedSize(maxSize)
49 SequenceFixedSizeBase(std::size_t maxSize,
const ValueType& val)
55 SequenceFixedSizeBase(std::size_t maxSize, ValueType&& val)
56 : BaseImpl(
std::move(val)),
61 SequenceFixedSizeBase(
const SequenceFixedSizeBase&) =
default;
62 SequenceFixedSizeBase(SequenceFixedSizeBase&&) =
default;
63 SequenceFixedSizeBase& operator=(
const SequenceFixedSizeBase&) =
default;
64 SequenceFixedSizeBase& operator=(SequenceFixedSizeBase&&) =
default;
66 std::size_t length()
const
68 auto currSize = BaseImpl::getValue().size();
69 if (currSize == m_fixedSize) {
70 return BaseImpl::length();
73 if (currSize < m_fixedSize) {
74 auto remSize = m_fixedSize - currSize;
75 auto dummyElem = ElementType();
76 return BaseImpl::length() + (remSize * BaseImpl::elementLength(dummyElem));
80 typename comms::util::LazyShallowConditional<
81 std::is_integral<ElementType>::value && (
sizeof(ElementType) ==
sizeof(std::uint8_t))
87 return recalcLen(Tag());
90 template <
typename TIter>
93 return BaseImpl::readN(m_fixedSize, iter, len);
96 template <
typename TIter>
97 void readNoStatus(TIter& iter)
99 return BaseImpl::readNoStatusN(m_fixedSize, iter);
102 template <
typename TIter>
105 auto writeCount = std::min(BaseImpl::getValue().size(), m_fixedSize);
106 auto es = BaseImpl::writeN(writeCount, iter, len);
111 auto remCount = m_fixedSize - writeCount;
116 auto dummyElem = ElementType();
117 while (0 < remCount) {
118 es = BaseImpl::writeElement(dummyElem, iter, len);
129 template <
typename TIter>
130 void writeNoStatus(TIter& iter)
const
132 auto writeCount = std::min(BaseImpl::getValue().size(), m_fixedSize);
133 BaseImpl::writeNoStatusN(writeCount, iter);
135 auto remCount = m_fixedSize - writeCount;
140 auto dummyElem = ElementType();
141 while (0 < remCount) {
142 BaseImpl::writeElementNoStatus(dummyElem, iter);
149 return BaseImpl::valid() && (BaseImpl::getValue().size() <= m_fixedSize);
154 if (!BaseImpl::refresh()) {
159 typename comms::util::LazyShallowConditional<
160 comms::util::detect::hasResizeFunc<ElementType>()
166 return doRefresh(Tag());
170 template <
typename... TParams>
171 using HasRawDataTag = comms::details::tag::Tag1<>;
173 template <
typename... TParams>
174 using HasFieldsTag = comms::details::tag::Tag2<>;
176 template <
typename... TParams>
177 using HasFixedLengthElemsTag = comms::details::tag::Tag3<>;
179 template <
typename... TParams>
180 using HasVarLengthElemsTag = comms::details::tag::Tag4<>;
182 template <
typename... TParams>
183 using HasResizeTag = comms::details::tag::Tag5<>;
185 template <
typename... TParams>
186 using NoResizeTag = comms::details::tag::Tag6<>;
188 template <
typename... TParams>
189 std::size_t recalcLen(HasFieldsTag<TParams...>)
const
192 typename comms::util::LazyShallowConditional<
193 ElementType::minLength() == ElementType::maxLength()
195 HasFixedLengthElemsTag,
198 return recalcLen(Tag());
201 template <
typename... TParams>
202 std::size_t recalcLen(HasRawDataTag<TParams...>)
const
207 template <
typename... TParams>
208 std::size_t recalcLen(HasFixedLengthElemsTag<TParams...>)
const
210 return m_fixedSize * ElementType::minLength();
213 template <
typename... TParams>
214 std::size_t recalcLen(HasVarLengthElemsTag<TParams...>)
const
216 std::size_t result = 0U;
217 auto count = m_fixedSize;
218 for (
auto& elem : BaseImpl::getValue()) {
223 result += BaseImpl::elementLength(elem);
229 template <
typename... TParams>
230 bool doRefresh(HasResizeTag<TParams...>)
232 if (BaseImpl::getValue().size() == m_fixedSize) {
236 BaseImpl::value().resize(m_fixedSize);
240 template <
typename... TParams>
241 static constexpr bool doRefresh(NoResizeTag<TParams...>)
246 std::size_t m_fixedSize = 0;
249template <std::
size_t TSize,
typename TBase>
252 using BaseImpl = SequenceFixedSizeBase<TBase>;
255 using ValueType =
typename BaseImpl::ValueType;
256 using ElementType =
typename BaseImpl::ElementType;
264 : BaseImpl(TSize, val)
269 : BaseImpl(TSize,
std::move(val))
278 static constexpr std::size_t minLength()
280 return BaseImpl::minLength() + BaseImpl::minElementLength() * TSize;
283 static constexpr std::size_t maxLength()
285 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:1607
Main namespace for all classes / functions of COMMS library.
ErrorStatus
Error statuses reported by the Communication module.
Definition ErrorStatus.h:19
@ 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.