Sen API
Sen Libraries
Loading...
Searching...
No Matches
gen.h
Go to the documentation of this file.
1
// === gen.h ===========================================================================================================
2
// Sen Infrastructure
3
// Released under the Apache License v2.0 (SPDX-License-Identifier Apache-2.0).
4
// See the LICENSE.txt file for more information.
5
// © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
6
// =====================================================================================================================
7
8
#ifndef SEN_CORE_OBJ_DETAIL_GEN_H
9
#define SEN_CORE_OBJ_DETAIL_GEN_H
10
11
// sen
12
#include "
sen/core/base/assert.h
"
13
#include "
sen/core/base/compiler_macros.h
"
14
#include "
sen/core/base/numbers.h
"
15
#include "
sen/core/base/quantity.h
"
16
#include "
sen/core/base/span.h
"
17
#include "
sen/core/base/static_vector.h
"
18
#include "
sen/core/io/util.h
"
19
#include "
sen/core/lang/vm.h
"
20
#include "
sen/core/meta/class_type.h
"
21
#include "
sen/core/meta/enum_traits.h
"
22
#include "
sen/core/meta/enum_type.h
"
23
#include "
sen/core/meta/native_types.h
"
24
#include "
sen/core/meta/optional_traits.h
"
25
#include "
sen/core/meta/quantity_traits.h
"
26
#include "
sen/core/meta/quantity_type.h
"
27
#include "
sen/core/meta/sequence_traits.h
"
28
#include "
sen/core/meta/sequence_type.h
"
29
#include "
sen/core/meta/struct_traits.h
"
30
#include "
sen/core/meta/struct_type.h
"
31
#include "
sen/core/meta/time_types.h
"
32
#include "
sen/core/meta/unit_registry.h
"
33
#include "
sen/core/meta/variant_traits.h
"
34
#include "
sen/core/meta/variant_type.h
"
35
#include "
sen/core/obj/detail/event_buffer.h
"
36
#include "
sen/core/obj/detail/native_object_proxy.h
"
37
#include "
sen/core/obj/detail/property_flags.h
"
38
#include "
sen/core/obj/detail/remote_object.h
"
39
#include "
sen/core/obj/native_object.h
"
40
41
// std
42
#include <initializer_list>
// NOLINT(misc-include-cleaner): used by not visible due to macros
43
#include <iterator>
// NOLINT(misc-include-cleaner): used by not visible due to macros
44
#include <optional>
45
#include <type_traits>
46
47
#define SEN_IMPL_GEN_NATIVE_MEMBERS \
48
protected: \
49
[[nodiscard]] inline ::sen::Var senImplGetPropertyImpl(::sen::MemberHash propertyId) const override; \
50
inline void senImplSetNextPropertyUntyped(::sen::MemberHash propertyId, const ::sen::Var& value) override; \
51
[[nodiscard]] inline ::sen::Var senImplGetNextPropertyUntyped(::sen::MemberHash propertyId) const override; \
52
[[nodiscard]] inline uint32_t senImplComputeMaxReliableSerializedPropertySizeImpl() const override; \
53
inline void senImplStreamCall(::sen::MemberHash methodId, ::sen::InputStream& in, ::sen::StreamCallForwarder&& func) \
54
override; \
55
inline void senImplVariantCall( \
56
::sen::MemberHash methodId, const ::sen::VarList& args, ::sen::VariantCallForwarder&& func) override; \
57
inline void senImplCommitImpl(::sen::TimeStamp time) override; \
58
inline void senImplWriteChangedPropertiesToStream( \
59
::sen::OutputStream& confirmed, ::sen::impl::BufferProvider uni, ::sen::impl::BufferProvider multi) override; \
60
inline void senImplWriteAllPropertiesToStream(::sen::OutputStream& out) const override; \
61
inline void senImplWriteStaticPropertiesToStream(::sen::OutputStream& out) const override; \
62
inline void senImplWriteDynamicPropertiesToStream(::sen::OutputStream& out) const override; \
63
inline void senImplRemoveTypedConnection(::sen::ConnId id) override; \
64
[[nodiscard]] inline ::sen::impl::FieldValueGetter senImplGetFieldValueGetter( \
65
::sen::MemberHash propertyId, ::sen::Span<uint16_t> fields) const override; \
66
inline void invokeAllPropertyCallbacks() override;
67
69
#define SEN_IMPL_GEN_BASE_CLASS(classname) \
70
SEN_IMPL_GEN_NATIVE_MEMBERS \
71
\
72
private: \
73
bool somePropertyIsDirty_ = false; \
74
\
75
public: \
76
inline classname(std::string name, const ::sen::VarMap& args); \
77
~classname() override = default; \
78
[[nodiscard]] inline ::sen::ConstTypeHandle<::sen::ClassType> getClass() const noexcept override; \
79
[[nodiscard]] static inline ::sen::ConstTypeHandle<::sen::ClassType> meta() noexcept; \
80
\
81
private:
82
84
#define SEN_IMPL_GEN_REMOTE_CLASS(classname) \
85
public: \
86
explicit classname(::sen::impl::RemoteObjectInfo&& info); \
87
~classname() override = default; \
88
\
89
protected: \
90
void senImplRemoveTypedConnection(::sen::ConnId id) override; \
91
void senImplWriteAllPropertiesToStream(::sen::OutputStream& out) const override; \
92
void senImplWriteStaticPropertiesToStream(::sen::OutputStream& out) const override; \
93
void senImplWriteDynamicPropertiesToStream(::sen::OutputStream& out) const override; \
94
[[nodiscard]] ::sen::Var senImplGetPropertyImpl(::sen::MemberHash propertyId) const override; \
95
[[nodiscard]] bool readPropertyFromStream(::sen::MemberHash id, ::sen::InputStream& in, bool initialState) override; \
96
[[nodiscard]] ::sen::Var deserializeMethodReturnValueAsVariant(::sen::MemberHash methodId, ::sen::InputStream& in) \
97
const override; \
98
void serializeMethodArgumentsFromVariants( \
99
::sen::MemberHash methodId, const ::sen::VarList& args, ::sen::OutputStream& out) const override; \
100
void drainInputs() override; \
101
void eventReceived(::sen::MemberHash eventId, ::sen::TimeStamp creationTime, const ::sen::Span<const uint8_t>& args) \
102
override; \
103
void invokeAllPropertyCallbacks() override; \
104
\
105
private:
106
108
#define SEN_IMPL_GEN_LOCAL_PROXY_CLASS(classname) \
109
public: \
110
explicit classname(::sen::NativeObject* owner, const std::string& localPrefix); \
111
~classname() override = default; \
112
\
113
protected: \
114
void senImplWriteAllPropertiesToStream(::sen::OutputStream& out) const override; \
115
void senImplWriteStaticPropertiesToStream(::sen::OutputStream& out) const override; \
116
void senImplWriteDynamicPropertiesToStream(::sen::OutputStream& out) const override; \
117
void senImplRemoveTypedConnection(::sen::ConnId id) override; \
118
[[nodiscard]] ::sen::Var senImplGetPropertyImpl(::sen::MemberHash propertyId) const override; \
119
void drainInputsImpl(::sen::TimeStamp lastCommitTime) override; \
120
\
121
private:
122
124
#define SEN_IMPL_GEN_UNBOUNDED_SEQUENCE(classname, elementtype) \
125
class classname final: private std::vector<elementtype> \
126
{ \
127
using Parent = std::vector<elementtype>; \
128
\
129
public: \
130
using Parent::value_type; \
131
\
132
using Parent::Parent; \
133
using Parent::operator=; \
134
using Parent::assign; \
135
\
136
using Parent::at; \
137
using Parent::operator[]; \
138
using Parent::front; \
139
using Parent::back; \
140
using Parent::data; \
141
\
142
using Parent::begin; \
143
using Parent::cbegin; \
144
using Parent::rbegin; \
145
using Parent::crbegin; \
146
using Parent::end; \
147
using Parent::cend; \
148
using Parent::rend; \
149
using Parent::crend; \
150
\
151
using Parent::empty; \
152
using Parent::size; \
153
using Parent::max_size; \
154
using Parent::reserve; \
155
using Parent::capacity; \
156
using Parent::shrink_to_fit; \
157
\
158
using Parent::clear; \
159
using Parent::insert; \
160
using Parent::emplace; \
161
using Parent::erase; \
162
using Parent::push_back; \
163
using Parent::emplace_back; \
164
using Parent::pop_back; \
165
using Parent::resize; \
166
using Parent::swap; \
167
\
168
constexpr const Parent& asVector() const& noexcept { return *this; } \
169
Parent asVector() && noexcept(std::is_nothrow_move_constructible_v<Parent>) { return std::move(*this); } \
170
\
171
friend bool operator==(const classname& lhs, const classname& rhs) { return lhs.asVector() == rhs.asVector(); } \
172
friend bool operator!=(const classname& lhs, const classname& rhs) { return !(lhs == rhs); } \
173
};
174
176
#define SEN_IMPL_GEN_BOUNDED_SEQUENCE(classname, element, maxSize) \
177
struct classname final: public ::sen::StaticVector<element, maxSize> \
178
{ \
179
using Parent = ::sen::StaticVector<element, maxSize>; \
180
using Parent::Parent; \
181
using Parent::operator=; \
182
};
183
185
#define SEN_IMPL_GEN_FIXED_SEQUENCE(classname, element, num_elements) \
186
class classname final: private std::array<element, num_elements> \
187
{ \
188
using Parent = std::array<element, num_elements>; \
189
\
190
public: \
191
using Parent::value_type; \
192
\
193
using Parent::Parent; \
194
using Parent::operator=; \
195
\
196
using Parent::at; \
197
using Parent::operator[]; \
198
using Parent::front; \
199
using Parent::back; \
200
using Parent::data; \
201
\
202
using Parent::begin; \
203
using Parent::cbegin; \
204
using Parent::rbegin; \
205
using Parent::crbegin; \
206
using Parent::end; \
207
using Parent::cend; \
208
using Parent::rend; \
209
using Parent::crend; \
210
\
211
using Parent::empty; \
212
using Parent::size; \
213
using Parent::max_size; \
214
\
215
using Parent::fill; \
216
using Parent::swap; \
217
\
218
template <typename Y, typename = std::enable_if_t<std::is_convertible_v<Y, element>, int>> \
219
constexpr classname(std::initializer_list<Y> elems): Parent() \
220
{ \
221
using DifferenceType = \
222
typename std::iterator_traits<typename std::initializer_list<Y>::iterator>::difference_type; \
223
SEN_ASSERT(std::distance(std::begin(elems), std::end(elems)) <= static_cast<DifferenceType>(num_elements)); \
224
std::move(std::begin(elems), \
225
std::next(std::begin(elems), \
226
std::min(std::distance(std::begin(elems), std::end(elems)), \
227
static_cast<DifferenceType>(num_elements))), \
228
std::begin(*this)); \
229
} \
230
\
231
constexpr const Parent& asArray() const& noexcept { return *this; } \
232
Parent asArray() && noexcept(std::is_nothrow_move_constructible_v<element>) { return std::move(*this); } \
233
\
234
friend bool operator==(const classname& lhs, const classname& rhs) { return lhs.asArray() == rhs.asArray(); } \
235
friend bool operator!=(const classname& lhs, const classname& rhs) { return !(lhs == rhs); } \
236
};
237
239
#define SEN_IMPL_GEN_STRUCT_OPERATORS(classname, doExport) \
240
SEN_MAYBE_EXPORT(doExport) std::ostream& operator<<(std::ostream& out, const classname& val); \
241
SEN_MAYBE_EXPORT(doExport) bool operator==(const classname& lhs, const classname& rhs); \
242
SEN_MAYBE_EXPORT(doExport) bool operator!=(const classname& lhs, const classname& rhs);
243
245
#define SEN_IMPL_GEN_OPTIONAL(classname, elementtype) \
246
class classname final: private std::optional<elementtype> \
247
{ \
248
using Parent = std::optional<elementtype>; \
249
\
250
public: \
251
using Parent::value_type; \
252
\
253
using Parent::Parent; \
254
using Parent::operator=; \
255
\
256
using Parent::operator->; \
257
using Parent::operator*; \
258
using Parent::operator bool; \
259
using Parent::has_value; \
260
using Parent::value; \
261
using Parent::value_or; \
262
\
263
using Parent::reset; \
264
using Parent::swap; \
265
using Parent::emplace; \
266
\
267
constexpr const Parent& asOptional() const& noexcept { return *this; } \
268
Parent asOptional() && noexcept(std::is_nothrow_move_constructible_v<Parent>) { return std::move(*this); } \
269
\
270
friend constexpr bool operator==(const classname& lhs, const classname& rhs) \
271
{ \
272
return lhs.asOptional() == rhs.asOptional(); \
273
} \
274
friend constexpr bool operator!=(const classname& lhs, const classname& rhs) { return !(lhs == rhs); } \
275
};
276
278
#define SEN_IMPL_GEN_OPTIONAL_TRAITS(classname, doExport) \
279
template <> \
280
struct MetaTypeTrait<classname> \
281
{ \
282
[[nodiscard]] SEN_MAYBE_EXPORT(doExport) static ConstTypeHandle<OptionalType> meta(); \
283
}; \
284
template <> \
285
struct VariantTraits<classname>: private OptionalTraitsBase<classname> \
286
{ \
287
using OptionalTraitsBase<classname>::valueToVariant; \
288
using OptionalTraitsBase<classname>::variantToValue; \
289
}; \
290
template <> \
291
struct SerializationTraits<classname>: private OptionalTraitsBase<classname> \
292
{ \
293
using OptionalTraitsBase<classname>::write; \
294
using OptionalTraitsBase<classname>::read; \
295
using OptionalTraitsBase<classname>::serializedSize; \
296
};
297
299
#define SEN_IMPL_GEN_ENUM_TRAITS(classname, doExport) \
300
template <> \
301
struct MetaTypeTrait<classname> \
302
{ \
303
[[nodiscard]] SEN_MAYBE_EXPORT(doExport) static ConstTypeHandle<EnumType> meta(); \
304
}; \
305
template <> \
306
struct SEN_MAYBE_EXPORT(doExport) VariantTraits<classname>: private EnumTraitsBase<classname> \
307
{ \
308
using EnumTraitsBase<classname>::valueToVariant; \
309
using EnumTraitsBase<classname>::variantToValue; \
310
}; \
311
template <> \
312
struct SEN_MAYBE_EXPORT(doExport) SerializationTraits<classname>: private EnumTraitsBase<classname> \
313
{ \
314
using EnumTraitsBase<classname>::write; \
315
using EnumTraitsBase<classname>::read; \
316
using EnumTraitsBase<classname>::serializedSize; \
317
}; \
318
template <> \
319
struct SEN_MAYBE_EXPORT(doExport) StringConversionTraits<classname> \
320
{ \
321
[[nodiscard]] static std::string_view toString(classname val); \
322
[[nodiscard]] static classname fromString(std::string_view val); \
323
}; \
324
\
325
[[nodiscard]] SEN_MAYBE_EXPORT(doExport) std::string_view toString(classname value);
326
328
#define SEN_IMPL_GEN_SEQUENCE_TRAITS(classname, doExport) \
329
template <> \
330
struct MetaTypeTrait<classname> \
331
{ \
332
[[nodiscard]] SEN_MAYBE_EXPORT(doExport) static sen::ConstTypeHandle<SequenceType> meta(); \
333
}; \
334
template <> \
335
struct SEN_MAYBE_EXPORT(doExport) VariantTraits<classname>: private SequenceTraitsBase<classname> \
336
{ \
337
using SequenceTraitsBase<classname>::valueToVariant; \
338
using SequenceTraitsBase<classname>::variantToValue; \
339
}; \
340
template <> \
341
struct SEN_MAYBE_EXPORT(doExport) SerializationTraits<classname>: private SequenceTraitsBase<classname> \
342
{ \
343
using SequenceTraitsBase<classname>::write; \
344
using SequenceTraitsBase<classname>::read; \
345
using SequenceTraitsBase<classname>::serializedSize; \
346
};
347
349
#define SEN_IMPL_GEN_ARRAY_TRAITS(classname, doExport) \
350
template <> \
351
struct MetaTypeTrait<classname> \
352
{ \
353
[[nodiscard]] SEN_MAYBE_EXPORT(doExport) static ConstTypeHandle<SequenceType> meta(); \
354
}; \
355
template <> \
356
struct SEN_MAYBE_EXPORT(doExport) VariantTraits<classname>: private ArrayTraitsBase<classname> \
357
{ \
358
using ArrayTraitsBase<classname>::valueToVariant; \
359
using ArrayTraitsBase<classname>::variantToValue; \
360
}; \
361
template <> \
362
struct SEN_MAYBE_EXPORT(doExport) SerializationTraits<classname>: private ArrayTraitsBase<classname> \
363
{ \
364
using ArrayTraitsBase<classname>::write; \
365
using ArrayTraitsBase<classname>::read; \
366
using ArrayTraitsBase<classname>::serializedSize; \
367
};
368
370
#define SEN_IMPL_GEN_STRUCT_TRAITS(classname, doExport) \
371
template <> \
372
struct MetaTypeTrait<classname> \
373
{ \
374
[[nodiscard]] SEN_MAYBE_EXPORT(doExport) static ConstTypeHandle<StructType> meta(); \
375
}; \
376
template <> \
377
struct SEN_MAYBE_EXPORT(doExport) VariantTraits<classname>: protected StructTraitsBase \
378
{ \
379
static void valueToVariant(const classname& val, Var& var); \
380
static void variantToValue(const Var& var, classname& val); \
381
static std::function<lang::Value(const void*)> getFieldValueGetterFunction(Span<uint16_t> fields); \
382
}; \
383
template <> \
384
struct SEN_MAYBE_EXPORT(doExport) SerializationTraits<classname>: protected StructTraitsBase \
385
{ \
386
static void write(OutputStream& out, const classname& val); \
387
static void read(InputStream& in, classname& val); \
388
[[nodiscard]] static uint32_t serializedSize(const classname& val) noexcept; \
389
};
390
392
#define SEN_IMPL_GEN_VARIANT_TRAITS(classname, doExport) \
393
template <> \
394
struct SEN_MAYBE_EXPORT(doExport) MetaTypeTrait<classname> \
395
{ \
396
[[nodiscard]] static ConstTypeHandle<VariantType> meta(); \
397
}; \
398
template <> \
399
struct SEN_MAYBE_EXPORT(doExport) VariantTraits<classname>: protected VariantTraitsBase<classname> \
400
{ \
401
static void valueToVariant(const classname& val, Var& var); \
402
static void variantToValue(const Var& var, classname& val); \
403
static std::function<lang::Value(const void*)> getFieldValueGetterFunction(Span<uint16_t> fields); \
404
using VariantTraitsBase<classname>::tryPrintField; \
405
}; \
406
template <> \
407
struct SEN_MAYBE_EXPORT(doExport) SerializationTraits<classname>: protected VariantTraitsBase<classname> \
408
{ \
409
static void write(OutputStream& out, const classname& val); \
410
static void read(InputStream& in, classname& val); \
411
[[nodiscard]] static uint32_t serializedSize(const classname& val) noexcept; \
412
};
413
415
#define SEN_IMPL_GEN_CLASS_META_TRAITS(classname, doExport) \
416
template <> \
417
struct MetaTypeTrait<classname> \
418
{ \
419
[[nodiscard]] SEN_MAYBE_EXPORT(doExport) static ConstTypeHandle<ClassType> meta(); \
420
};
421
423
#define SEN_IMPL_GEN_CLASS_TRAITS_TEMPLATE(interfaceName, remoteProxy, localProxy, baseName) \
424
template <> \
425
struct SenClassRelation<interfaceName> \
426
{ \
427
using InterfaceType = interfaceName; \
428
template <typename T> \
429
using BaseType = baseName<T>; \
430
static constexpr bool isBaseTypeTemplate = true; \
431
using RemoteProxyType = remoteProxy; \
432
using LocalProxyType = localProxy; \
433
}; \
434
template <> \
435
struct SenClassRelation<remoteProxy> \
436
{ \
437
using InterfaceType = interfaceName; \
438
template <typename T> \
439
using BaseType = baseName<T>; \
440
static constexpr bool isBaseTypeTemplate = true; \
441
using RemoteProxyType = remoteProxy; \
442
using LocalProxyType = localProxy; \
443
}; \
444
template <> \
445
struct SenClassRelation<localProxy> \
446
{ \
447
using InterfaceType = interfaceName; \
448
template <typename T> \
449
using BaseType = baseName<T>; \
450
static constexpr bool isBaseTypeTemplate = true; \
451
using RemoteProxyType = remoteProxy; \
452
using LocalProxyType = localProxy; \
453
}; \
454
template <typename T> \
455
struct SenClassRelation<baseName<T>> \
456
{ \
457
using InterfaceType = interfaceName; \
458
template <typename U> \
459
using BaseType = baseName<U>; \
460
static constexpr bool isBaseTypeTemplate = true; \
461
using RemoteProxyType = remoteProxy; \
462
using LocalProxyType = localProxy; \
463
};
464
466
#define SEN_IMPL_GEN_CLASS_TRAITS_NORMAL(interfaceName, remoteProxy, localProxy, baseName) \
467
template <> \
468
struct SenClassRelation<interfaceName> \
469
{ \
470
using InterfaceType = interfaceName; \
471
using BaseType = baseName; \
472
static constexpr bool isBaseTypeTemplate = false; \
473
using RemoteProxyType = remoteProxy; \
474
using LocalProxyType = localProxy; \
475
}; \
476
template <> \
477
struct SenClassRelation<remoteProxy> \
478
{ \
479
using InterfaceType = interfaceName; \
480
using BaseType = baseName; \
481
static constexpr bool isBaseTypeTemplate = false; \
482
using RemoteProxyType = remoteProxy; \
483
using LocalProxyType = localProxy; \
484
}; \
485
template <> \
486
struct SenClassRelation<localProxy> \
487
{ \
488
using InterfaceType = interfaceName; \
489
using BaseType = baseName; \
490
static constexpr bool isBaseTypeTemplate = false; \
491
using RemoteProxyType = remoteProxy; \
492
using LocalProxyType = localProxy; \
493
}; \
494
template <> \
495
struct SenClassRelation<baseName> \
496
{ \
497
using InterfaceType = interfaceName; \
498
using BaseType = baseName; \
499
static constexpr bool isBaseTypeTemplate = false; \
500
using RemoteProxyType = remoteProxy; \
501
using LocalProxyType = localProxy; \
502
};
503
505
#define SEN_IMPL_GEN_QUANTITY_TRAITS(classname, maxVal, minVal, doExport) \
506
template <> \
507
struct MetaTypeTrait<classname> \
508
{ \
509
[[nodiscard]] SEN_MAYBE_EXPORT(doExport) static ConstTypeHandle<QuantityType> meta(); \
510
}; \
511
template <> \
512
struct SEN_MAYBE_EXPORT(doExport) VariantTraits<classname>: private QuantityTraitsBase<classname> \
513
{ \
514
using QuantityTraitsBase<classname>::valueToVariant; \
515
using QuantityTraitsBase<classname>::variantToValue; \
516
}; \
517
template <> \
518
struct SEN_MAYBE_EXPORT(doExport) SerializationTraits<classname>: private QuantityTraitsBase<classname> \
519
{ \
520
using QuantityTraitsBase<classname>::write; \
521
using QuantityTraitsBase<classname>::read; \
522
using QuantityTraitsBase<classname>::serializedSize; \
523
}; \
524
template <> \
525
struct SEN_MAYBE_EXPORT(doExport) QuantityTraits<classname> \
526
{ \
527
using ValueType = typename classname::ValueType; \
528
\
529
static constexpr ValueType max = maxVal; \
530
static constexpr ValueType min = minVal; \
531
\
532
[[nodiscard]] static ::std::optional<const sen::Unit*> unit() noexcept; \
533
[[nodiscard]] static const sen::Unit& unit(sen::Unit::EnsureTag); \
534
};
535
536
#endif
// SEN_CORE_OBJ_DETAIL_GEN_H
assert.h
The following macros implement a replacement of assert that is connected to the overall fault handlin...
class_type.h
compiler_macros.h
util.h
enum_traits.h
enum_type.h
event_buffer.h
native_object.h
native_object_proxy.h
native_types.h
numbers.h
optional_traits.h
property_flags.h
quantity.h
quantity_traits.h
quantity_type.h
remote_object.h
sequence_traits.h
sequence_type.h
span.h
static_vector.h
struct_traits.h
struct_type.h
time_types.h
unit_registry.h
variant_traits.h
variant_type.h
vm.h
libs
core
include
sen
core
obj
detail
gen.h
Generated by
1.16.1