8#ifndef SEN_CORE_META_TYPE_H
9#define SEN_CORE_META_TYPE_H
51 inline u32 operator()(const ::sen::MemberHash& x)
const noexcept {
return hashIntegral(x.get()); }
73 SEN_NOCOPY_NOMOVE(
Type)
80 [[nodiscard]]
virtual std::string_view
getName() const noexcept = 0;
89 [[nodiscard]] virtual
bool isBounded() const noexcept = 0;
142 [[nodiscard]] virtual
bool equals(const
Type& other) const noexcept = 0;
145 friend
bool operator==(const
Type& lhs, const
Type& rhs) {
return lhs.equals(rhs); }
160template <
typename SenTypeType>
163 using RawPtrType = SenTypeType*;
164 using ManagedPtrType = std::shared_ptr<SenTypeType>;
165 using StorageType = std::variant<RawPtrType, ManagedPtrType>;
168 template <
typename T>
171 SEN_ASSERT(
type !=
nullptr &&
"handles should not be to nullptrs");
175 template <
typename T>
180 typename... ArgTypes,
181 std::enable_if_t<std::negation_v<sen::std_util::IsInstantiationOf<TypeHandle, std::decay_t<ArgT>>>,
bool> =
true>
184 : type_(
std::make_shared<SenTypeType>(
std::forward<ArgT>(arg),
std::forward<ArgTypes>(args)...))
188 template <
typename T>
192 SEN_ASSERT(std::get<ManagedPtrType>(type_).get() !=
nullptr &&
"Handles should not be to nullptrs");
195 template <
typename OtherSenTypeType>
198 : type_(
std::visit(
sen::
Overloaded {[](OtherSenTypeType* ptr) -> StorageType { return {ptr}; },
199 [](std::shared_ptr<OtherSenTypeType> sharedPtr) -> StorageType
200 {
return {std::move(sharedPtr)}; }},
205 template <
typename OtherSenTypeType>
208 : type_(
std::visit(
sen::
Overloaded {[](OtherSenTypeType* ptr) -> StorageType { return {ptr}; },
209 [](std::shared_ptr<OtherSenTypeType> sharedPtr) -> StorageType
210 {
return {std::move(sharedPtr)}; }},
223 if (std::holds_alternative<ManagedPtrType>(type_))
225 return std::get<ManagedPtrType>(type_).get();
228 return std::get<RawPtrType>(type_);
231 const SenTypeType*
type()
const
233 if (std::holds_alternative<ManagedPtrType>(type_))
235 return std::get<ManagedPtrType>(type_).get();
238 return std::get<RawPtrType>(type_);
244 template <
typename U>
252 template <
typename U>
263 template <
typename T>
266 template <
typename T,
typename U>
287template <
typename T,
typename U>
293 if (std::holds_alternative<
typename TypeHandle<U>::ManagedPtrType>(handle.type_))
296 std::get<
typename TypeHandle<U>::ManagedPtrType>(handle.type_)))
298 return {
TypeHandle(std::move(convertedSharedPtr))};
305 if (
auto convertedPtr =
306 dynamic_cast<typename TypeHandle<T>::RawPtrType
>(std::get<
typename TypeHandle<U>::RawPtrType>(handle.type_)))
318template <
typename T = Type>
321template <
typename T = Type>
331template <
typename Type>
332struct hash<
sen::TypeHandle<Type>>
343#undef DECL_IS_TYPE_FUNC
348#define SEN_META_TYPE(classname) \
350 SEN_NOCOPY_NOMOVE(classname) \
353 void accept(FullTypeVisitor& tv) const override { tv.apply(*this); } \
355 [[nodiscard]] const classname* as##classname() const noexcept override { return this; } \
367 return std::hash<::sen::MemberHash::ValueType>()(x.get());
The following macros implement a replacement of assert that is connected to the overall fault handlin...
Here we define a set of template meta-programming helpers to let the compiler take some decisions bas...
Represents an aliased type.
Definition alias_type.h:56
Represents a user-defined type.
Definition custom_type.h:23
Represents a sen::Duration (a time duration).
Definition time_types.h:28
Represents an enumeration.
Definition enum_type.h:84
A Visitor for constant types. This class is based on the GoF Visitor design pattern....
Definition type_visitor.h:28
Represents an integral numeric type.
Definition native_types.h:80
Represents a native (built-in) type that can be created on the stack or sent in a message.
Definition native_types.h:35
Represents a numeric native type.
Definition native_types.h:45
Represents an optional type.
Definition optional_type.h:56
Represents a quantity.
Definition quantity_type.h:76
Represents a floating point numeric type.
Definition native_types.h:90
Result<T, E> is a template type that can be used to return and propagate errors. The intent is to rep...
Definition result.h:135
Represents a sequence type.
Definition sequence_type.h:67
CRTP class that wraps T to make it a strong type.
Definition strong_type.h:72
Represents a structure type.
Definition struct_type.h:96
Represents a sen::TimeStamp (a point in time).
Definition time_types.h:48
Handle around a type that, by default, ensures the lifetime of the underlying type.
Definition type.h:162
SenTypeType * operator->()
Definition type.h:218
const SenTypeType & operator*() const
Definition type.h:216
friend std::optional< TypeHandle< T > > dynamicTypeHandleCast(const TypeHandle< U > &)
Definition type.h:288
friend bool operator!=(const Type &lhs, const TypeHandle &rhs)
Definition type.h:258
TypeHandle(std::shared_ptr< T > type)
Definition type.h:190
const SenTypeType * operator->() const
Definition type.h:219
TypeHandle(const TypeHandle< OtherSenTypeType > &otherHandle)
Definition type.h:197
const SenTypeType * type() const
Definition type.h:231
friend class TypeHandle
Definition type.h:264
SenTypeType * type()
Definition type.h:221
friend bool operator!=(const TypeHandle &lhs, const Type &rhs)
Definition type.h:257
TypeHandle(ArgT &&arg, ArgTypes &&... args)
Definition type.h:183
friend bool operator==(const TypeHandle &lhs, const TypeHandle< U > &rhs)
Definition type.h:245
friend bool operator!=(const TypeHandle &lhs, const TypeHandle< U > &rhs)
Definition type.h:253
friend bool operator==(const TypeHandle &lhs, const Type &rhs)
Definition type.h:249
SenTypeType & operator*()
Definition type.h:215
friend bool operator==(const Type &lhs, const TypeHandle &rhs)
Definition type.h:250
friend TypeHandle< T > makeNonOwningTypeHandle(T *type)
Definition type.h:281
TypeHandle(TypeHandle< OtherSenTypeType > &&otherHandle)
Definition type.h:207
Represents a type that can be used to define variables and arguments for methods or functions....
Definition type.h:71
static Result< void, std::string > validateTypeName(std::string_view name)
Checks that a upper case name (used for type names) is valid.
virtual std::string_view getName() const noexcept=0
The type name.
virtual bool isBounded() const noexcept=0
True if values of this type have a bounded memory footprint (do not grow or shrink).
virtual void accept(FullTypeVisitor &tv) const =0
Accepts a type visitor.
Type(MemberHash hash) noexcept
friend bool operator!=(const Type &lhs, const Type &rhs)
Returns true if the lhs type is not the same as the rhs type.
Definition type.h:148
virtual std::string_view getDescription() const noexcept=0
The type documentation.
virtual bool equals(const Type &other) const noexcept=0
static Result< void, std::string > validateLowerCaseName(std::string_view name)
Checks that a lower case name (used for fields, enums, etc) is valid.
MemberHash getHash() const noexcept
Returns the unique hash computed for the type at compile time.
Represents a variant type.
Definition variant_type.h:75
Used for indicating that no result value is provided.
Definition native_types.h:150
#define SEN_ASSERT(expr)
Checks an intermediate result produced by a procedure (not an input or output). NOLINTNEXTLINE.
Definition assert.h:39
std::shared_ptr< const T > ConstSharedPtr
Utility typedef.
Definition type.h:316
TypeHandle< T > makeNonOwningTypeHandle(T *typePtr)
Creates a non-owning type handle from a type pointer.
Definition type.h:281
std::optional< ConstTypeHandle< T > > MaybeConstTypeHandle
Definition type.h:322
TypeHandle< const T > ConstTypeHandle
Definition type.h:319
TransportMode
How to transport information.
Definition type.h:56
@ multicast
Directed to all receivers, unreliable, unordered, no congestion control.
Definition type.h:58
@ confirmed
Directed to each receiver, reliable, ordered, with congestion control, relatively heavyweight.
Definition type.h:59
@ unicast
Directed to each receiver, unreliable, unordered, no congestion control.
Definition type.h:57
uint32_t u32
Definition numbers.h:25
This file contains functions related to hashing and compression. This is mainly used by Sen internals...
The hash of a member.
Definition type.h:39
Helper type for std::variant lambda visitors.
Definition class_helpers.h:170
Utility to indicate that your class wants to be passed by value in some of the library calls.
Definition class_helpers.h:34
size_t operator()(const sen::TypeHandle< Type > &typeHandle) const noexcept
Definition type.h:334
size_t operator()(const ::sen::MemberHash &x) const noexcept
Definition type.h:365
#define DECL_IS_TYPE_FUNC(type_name)
Definition type_impl.h:12