15#include "comms/field/basic/CommonFuncs.h"
26template <
typename TBase>
27class SequenceElemLengthForcing :
public TBase
29 using BaseImpl = TBase;
31 using ValueType =
typename BaseImpl::ValueType;
32 using ElementType =
typename BaseImpl::ElementType;
34 SequenceElemLengthForcing() =
default;
36 explicit SequenceElemLengthForcing(
const ValueType& val)
41 explicit SequenceElemLengthForcing(ValueType&& val)
42 : BaseImpl(
std::move(val))
46 SequenceElemLengthForcing(
const SequenceElemLengthForcing&) =
default;
47 SequenceElemLengthForcing(SequenceElemLengthForcing&&) =
default;
48 SequenceElemLengthForcing& operator=(
const SequenceElemLengthForcing&) =
default;
49 SequenceElemLengthForcing& operator=(SequenceElemLengthForcing&&) =
default;
51 void forceReadElemLength(std::size_t val)
57 void clearReadElemLengthForcing()
62 std::size_t length()
const
64 if (forced_ != Cleared) {
65 return BaseImpl::getValue().size() * forced_;
68 return BaseImpl::length();
71 std::size_t elementLength(
const ElementType& elem)
const
73 if (forced_ != Cleared) {
76 return BaseImpl::elementLength(elem);
79 static constexpr std::size_t maxElementLength()
81 return basic::CommonFuncs::maxSupportedLength();
84 template <
typename TIter>
85 ErrorStatus readElement(ElementType& elem, TIter& iter, std::size_t& len)
const
87 using IterType =
typename std::decay<
decltype(iter)>::type;
88 using IterTag =
typename std::iterator_traits<IterType>::iterator_category;
89 static_assert(std::is_base_of<std::random_access_iterator_tag, IterTag>::value,
90 "Only random access iterator for reading is supported with comms::option::def::SequenceElemLengthForcingEnabled option");
92 if (forced_ == Cleared) {
93 return BaseImpl::readElement(elem, iter, len);
101 auto remLen = forced_;
102 std::advance(iter, forced_);
104 return BaseImpl::readElement(elem, iterTmp, remLen);
107 template <
typename TIter>
108 void readElementNoStatus(ElementType& elem, TIter& iter)
const
110 using IterType =
typename std::decay<
decltype(iter)>::type;
111 using IterTag =
typename std::iterator_traits<IterType>::iterator_category;
112 static_assert(std::is_base_of<std::random_access_iterator_tag, IterTag>::value,
113 "Only random access iterator for reading is supported with comms::option::def::SequenceElemLengthForcingEnabled option");
115 if (forced_ == Cleared) {
116 return BaseImpl::readElementNoStatus(elem, iter);
119 auto fromIter = iter;
120 auto es = BaseImpl::readElementNoStatus(elem, iter);
125 auto consumed = std::distance(fromIter, iter);
126 if (consumed < forced_) {
127 std::advance(iter, forced_ - consumed);
131 template <
typename TIter>
134 return basic::CommonFuncs::readSequence(*
this, iter, len);
137 static constexpr bool hasReadNoStatus()
142 template <
typename TIter>
143 void readNoStatus(TIter& iter) =
delete;
145 template <
typename TIter>
146 ErrorStatus readN(std::size_t count, TIter& iter, std::size_t& len)
148 return basic::CommonFuncs::readSequenceN(*
this, count, iter, len);
151 template <
typename TIter>
152 void readNoStatusN(std::size_t count, TIter& iter) =
delete;
159 static const std::size_t Cleared = std::numeric_limits<std::size_t>::max();
160 std::size_t forced_ = Cleared;
This file contains classes required for generic custom assertion functionality.
#define COMMS_ASSERT(expr)
Generic assert macro.
Definition Assert.h:170
This file contain definition of error statuses used by comms module.
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.