14#include "comms/field/basic/CommonFuncs.h"
16#include "comms/details/tag.h"
27template <
typename TBase>
28class SequenceFixedSizeBase :
public TBase
30 using BaseImpl = TBase;
33 using ValueType =
typename BaseImpl::ValueType;
34 using ElementType =
typename BaseImpl::ElementType;
36 explicit SequenceFixedSizeBase(std::size_t maxSize)
41 SequenceFixedSizeBase(std::size_t maxSize,
const ValueType& val)
47 SequenceFixedSizeBase(std::size_t maxSize, ValueType&& val)
48 : BaseImpl(
std::move(val)),
53 SequenceFixedSizeBase(
const SequenceFixedSizeBase&) =
default;
54 SequenceFixedSizeBase(SequenceFixedSizeBase&&) =
default;
55 SequenceFixedSizeBase& operator=(
const SequenceFixedSizeBase&) =
default;
56 SequenceFixedSizeBase& operator=(SequenceFixedSizeBase&&) =
default;
58 std::size_t length()
const
60 auto currSize = BaseImpl::getValue().size();
61 if (currSize == fixedSize_) {
62 return BaseImpl::length();
65 if (currSize < fixedSize_) {
66 auto remSize = fixedSize_ - currSize;
67 auto dummyElem = ElementType();
68 return BaseImpl::length() + (remSize * BaseImpl::elementLength(dummyElem));
72 typename comms::util::LazyShallowConditional<
73 std::is_integral<ElementType>::value && (
sizeof(ElementType) ==
sizeof(std::uint8_t))
79 return recalcLen(Tag());
82 template <
typename TIter>
85 return BaseImpl::readN(fixedSize_, iter, len);
88 template <
typename TIter>
89 void readNoStatus(TIter& iter)
91 return BaseImpl::readNoStatusN(fixedSize_, iter);
94 template <
typename TIter>
97 auto writeCount = std::min(BaseImpl::getValue().size(), fixedSize_);
98 auto es = BaseImpl::writeN(writeCount, iter, len);
103 auto remCount = fixedSize_ - writeCount;
108 auto dummyElem = ElementType();
109 while (0 < remCount) {
110 es = BaseImpl::writeElement(dummyElem, iter, len);
121 template <
typename TIter>
122 void writeNoStatus(TIter& iter)
const
124 auto writeCount = std::min(BaseImpl::getValue().size(), fixedSize_);
125 BaseImpl::writeNoStatusN(writeCount, iter);
127 auto remCount = fixedSize_ - writeCount;
132 auto dummyElem = ElementType();
133 while (0 < remCount) {
134 BaseImpl::writeElementNoStatus(dummyElem, iter);
141 return BaseImpl::valid() && (BaseImpl::getValue().size() <= fixedSize_);
146 if (!BaseImpl::refresh()) {
151 typename comms::util::LazyShallowConditional<
152 comms::util::detect::hasResizeFunc<ElementType>()
158 return doRefresh(Tag());
162 template <
typename... TParams>
163 using HasRawDataTag = comms::details::tag::Tag1<>;
165 template <
typename... TParams>
166 using HasFieldsTag = comms::details::tag::Tag2<>;
168 template <
typename... TParams>
169 using HasFixedLengthElemsTag = comms::details::tag::Tag3<>;
171 template <
typename... TParams>
172 using HasVarLengthElemsTag = comms::details::tag::Tag4<>;
174 template <
typename... TParams>
175 using HasResizeTag = comms::details::tag::Tag5<>;
177 template <
typename... TParams>
178 using NoResizeTag = comms::details::tag::Tag6<>;
180 template <
typename... TParams>
181 std::size_t recalcLen(HasFieldsTag<TParams...>)
const
184 typename comms::util::LazyShallowConditional<
185 ElementType::minLength() == ElementType::maxLength()
187 HasFixedLengthElemsTag,
190 return recalcLen(Tag());
193 template <
typename... TParams>
194 std::size_t recalcLen(HasRawDataTag<TParams...>)
const
199 template <
typename... TParams>
200 std::size_t recalcLen(HasFixedLengthElemsTag<TParams...>)
const
202 return fixedSize_ * ElementType::minLength();
205 template <
typename... TParams>
206 std::size_t recalcLen(HasVarLengthElemsTag<TParams...>)
const
208 std::size_t result = 0U;
209 auto count = fixedSize_;
210 for (
auto& elem : BaseImpl::getValue()) {
215 result += BaseImpl::elementLength(elem);
221 template <
typename... TParams>
222 bool doRefresh(HasResizeTag<TParams...>)
224 if (BaseImpl::getValue().size() == fixedSize_) {
228 BaseImpl::value().resize(fixedSize_);
232 template <
typename... TParams>
233 static constexpr bool doRefresh(NoResizeTag<TParams...>)
238 std::size_t fixedSize_ = 0;
241template <std::
size_t TSize,
typename TBase>
244 using BaseImpl = SequenceFixedSizeBase<TBase>;
247 using ValueType =
typename BaseImpl::ValueType;
248 using ElementType =
typename BaseImpl::ElementType;
256 : BaseImpl(TSize, val)
261 : BaseImpl(TSize,
std::move(val))
270 static constexpr std::size_t minLength()
272 return BaseImpl::minLength() + BaseImpl::minElementLength() * TSize;
275 static constexpr std::size_t maxLength()
277 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:1544
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.