18#include "comms/details/tag.h"
27using MessageInterfaceEmptyBase = comms::util::EmptyStruct<>;
31template <
typename TEndian>
32class MessageInterfaceEndianBase
40 ~MessageInterfaceEndianBase() noexcept = default;
42 template <typename T, typename TIter>
43 static
void writeData(T value, TIter& iter)
45 writeData<sizeof(T), T>(value, iter);
48 template <std::
size_t TSize,
typename T,
typename TIter>
49 static void writeData(T value, TIter& iter)
51 static_assert(TSize <=
sizeof(T),
52 "Cannot put more bytes than type contains");
53 return util::writeData<TSize, T>(value, iter,
Endian());
56 template <
typename T,
typename TIter>
59 return readData<T, sizeof(T)>(iter);
62 template <
typename T, std::
size_t TSize,
typename TIter>
65 static_assert(TSize <=
sizeof(T),
66 "Cannot get more bytes than type contains");
67 return util::readData<T, TSize>(iter,
Endian());
73template <
typename TBase,
typename TId>
74class MessageInterfaceIdTypeBase :
public TBase
78 using MsgIdParamType =
80 std::is_integral<MsgIdType>::value || std::is_enum<MsgIdType>::value
87 ~MessageInterfaceIdTypeBase() noexcept = default;
92template <typename TBase, typename TFields>
93class MessageInterfaceExtraTransportFieldsBase : public TBase
96 using TransportFields = TFields;
98 static_assert(comms::util::isTuple<TransportFields>(),
99 "TransportFields is expected to be tuple");
101 TransportFields& transportFields()
103 return transportFields_;
106 const TransportFields& transportFields()
const
108 return transportFields_;
112 ~MessageInterfaceExtraTransportFieldsBase() noexcept = default;
114 TransportFields transportFields_;
119template <typename TBase,
std::
size_t TIdx>
120class MessageInterfaceVersionInExtraTransportFieldsBase : public TBase
123 using TransportFields =
typename TBase::TransportFields;
125 static_assert(comms::util::isTuple<TransportFields>(),
126 "TransportFields is expected to be tuple");
128 static_assert(TIdx < std::tuple_size<TransportFields>::value,
129 "Index provided to comms::option::def::VersionInExtraTransportFields exceeds size of the tuple");
131 using VersionType =
typename std::tuple_element<TIdx, TransportFields>::type::ValueType;
135 return std::get<TIdx>(TBase::transportFields()).value();
140 return std::get<TIdx>(TBase::transportFields()).value();
144 ~MessageInterfaceVersionInExtraTransportFieldsBase() noexcept = default;
149template <typename TBase>
150class MessageInterfaceIdInfoBase : public TBase
153 using MsgIdParamType =
typename TBase::MsgIdParamType;
155 MsgIdParamType getId()
const
161 ~MessageInterfaceIdInfoBase() noexcept = default;
162 virtual MsgIdParamType getIdImpl() const = 0;
167template <typename TBase, typename TReadIter>
168class MessageInterfaceReadBase : public TBase
174 return this->readImpl(iter, size);
178 ~MessageInterfaceReadBase() noexcept = default;
181 static_cast<void>(iter);
182 static_cast<void>(size);
189template <
typename TBase,
typename TWriteIter>
190class MessageInterfaceWriteBase :
public TBase
196 return this->writeImpl(iter, size);
200 ~MessageInterfaceWriteBase() noexcept = default;
201 virtual
comms::ErrorStatus writeImpl(WriteIterator& iter,
std::
size_t size)
const
203 static_cast<void>(iter);
204 static_cast<void>(size);
211template <
typename TBase>
212class MessageInterfaceValidBase :
public TBase
221 ~MessageInterfaceValidBase() noexcept = default;
222 virtual
bool validImpl()
const
230template <
typename TBase>
231class MessageInterfaceLengthBase :
public TBase
234 std::size_t length()
const
240 ~MessageInterfaceLengthBase() noexcept = default;
241 virtual
std::
size_t lengthImpl()
const
243 static constexpr bool Not_overriden =
false;
244 static_cast<void>(Not_overriden);
252template <
class T,
class R =
void>
253struct MessageInterfaceIfHasRetType {
using Type = R; };
255template <
class T,
class Enable =
void>
256struct MessageInterfaceDispatchRetTypeHelper
262struct MessageInterfaceDispatchRetTypeHelper<T, typename MessageInterfaceIfHasRetType<typename T::RetType>::Type>
264 using Type =
typename T::RetType;
268using MessageInterfaceDispatchRetType =
typename MessageInterfaceDispatchRetTypeHelper<T>::Type;
271template <
typename TBase,
typename THandler>
272class MessageInterfaceHandlerBase :
public TBase
276 using DispatchRetType = MessageInterfaceDispatchRetType<Handler>;
278 DispatchRetType dispatch(Handler& handler)
280 return dispatchImpl(handler);
284 ~MessageInterfaceHandlerBase() noexcept = default;
285 virtual DispatchRetType dispatchImpl(Handler& handler)
287 static_cast<void>(handler);
288 static constexpr bool Must_not_be_called =
false;
289 static_cast<void>(Must_not_be_called);
293 std::is_void<DispatchRetType>::value
295 VoidHandleRetTypeTag,
296 NonVoidHandleRetTypeTag
298 return dispatchInternal(Tag());
302 using VoidHandleRetTypeTag = comms::details::tag::Tag1<>;
303 using NonVoidHandleRetTypeTag = comms::details::tag::Tag2<>;
305 static DispatchRetType dispatchInternal(VoidHandleRetTypeTag)
310 static DispatchRetType dispatchInternal(NonVoidHandleRetTypeTag)
312 using RetTypeInternal =
typename std::decay<DispatchRetType>::type;
313 static const RetTypeInternal Ret = RetTypeInternal();
320template <
typename TBase>
321class MessageInterfaceRefreshBase :
public TBase
326 return refreshImpl();
330 ~MessageInterfaceRefreshBase() noexcept = default;
331 virtual
bool refreshImpl()
339template <
typename TBase>
340class MessageInterfaceNameBase :
public TBase
343 const char* name()
const
349 ~MessageInterfaceNameBase() noexcept = default;
350 virtual const
char* nameImpl() const = 0;
355template <typename TBase>
356class MessageInterfaceVirtDestructorBase : public TBase
359 virtual ~MessageInterfaceVirtDestructorBase() noexcept = default;
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.
Contains definition of comms::Field class.
Contains functions for raw data access / (de)serialization.
Base class to all the field classes.
Definition Field.h:33
comms::option::app::WriteIterator< TIter > WriteIterator
Same as comms::option::app::WriteIterator.
Definition options.h:1839
comms::option::app::Handler< T > Handler
Same as comms::option::app::Handler.
Definition options.h:1858
comms::option::app::ReadIterator< TIter > ReadIterator
Same as comms::option::app::ReadIterator.
Definition options.h:1835
comms::option::def::VersionType< T > VersionType
Same as comms::option::def::VersionType.
Definition options.h:1797
comms::option::def::Endian< TEndian > Endian
Same as comms::option::def::Endian.
Definition options.h:1438
comms::option::def::MsgIdType< T > MsgIdType
Same as comms::option::def::MsgIdType.
Definition options.h:1448
T readData(TIter &iter, const traits::endian::Big &endian)
Same as readBig<T, TIter>()
Definition access.h:774
void writeData(T value, TIter &iter, const traits::endian::Big &endian)
Same as writeBig<T, TIter>()
Definition access.h:706
Main namespace for all classes / functions of COMMS library.
ErrorStatus
Error statuses reported by the Communication module.
Definition ErrorStatus.h:17
@ NotSupported
The operation is not supported.
constexpr unsigned version()
Version of the COMMS library as single numeric value.
Definition version.h:64
Contains definition of all the options used by the COMMS library.
Replacement to std::conditional.
Definition type_traits.h:28
Replacement to some types from standard type_traits.