KItinerary

uperelement.h
1/*
2 SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#ifndef KITINERARY_UPERELEMENT_H
7#define KITINERARY_UPERELEMENT_H
8
9#include "uperdecoder.h"
10#include "internal/instance_counter.h"
11
12namespace KItinerary {
13
14// start of an ASN.1 SEQUENCE definition
15#define UPER_GADGET \
16 Q_GADGET \
17 static constexpr detail::num<0> _uper_optional_counter(detail::num<0>) { return {}; } \
18 static constexpr bool _uper_ExtensionMarker = false;
19
20// same as UPER_GADGET, for SEQUENCES with an extension marker
21#define UPER_EXTENDABLE_GADGET \
22 Q_GADGET \
23 static constexpr detail::num<0> _uper_optional_counter(detail::num<0>) { return {}; } \
24 static constexpr bool _uper_ExtensionMarker = true;
25
26// ASN.1 ENUMERATED definitions, with or without extension marker
27#define UPER_ENUM(Name) \
28 Q_ENUM_NS(Name) \
29 constexpr bool uperHasExtensionMarker(Name) { return false; }
30#define UPER_EXTENABLE_ENUM(Name) \
31 Q_ENUM_NS(Name) \
32 constexpr bool uperHasExtensionMarker(Name) { return true; }
33
34#define UPER_ELEMENT(Type, Name) \
35public: \
36 Type Name = {}; /* NOLINT misc-non-private-member-variables-in-classes */ \
37 Q_PROPERTY(Type Name MEMBER Name CONSTANT)
38
39#define UPER_ELEMENT_OPTIONAL(Type, Name) \
40public: \
41 Type Name = {}; /* NOLINT misc-non-private-member-variables-in-classes */ \
42 Q_PROPERTY(Type Name MEMBER Name CONSTANT) \
43 Q_PROPERTY(bool Name ## IsSet READ Name ## IsSet) \
44private: \
45 static constexpr int _uper_ ## Name ## OptionalIndex = decltype(_uper_optional_counter(detail::num<>()))::value; \
46 static constexpr auto _uper_optional_counter(detail::num<decltype(_uper_optional_counter(detail::num<>()))::value + 1> n) \
47 -> decltype(n) { return {}; } \
48public: \
49 [[nodiscard]] inline bool Name ## IsSet() const { return m_optionals[m_optionals.size() - _uper_ ## Name ## OptionalIndex - 1]; }
50
51#define UPER_ELEMENT_DEFAULT(Type, Name, DefaultValue) \
52public: \
53 Type Name = DefaultValue; /* NOLINT misc-non-private-member-variables-in-classes */ \
54 Q_PROPERTY(Type Name MEMBER Name CONSTANT) \
55private: \
56 static constexpr int _uper_ ## Name ## OptionalIndex = decltype(_uper_optional_counter(detail::num<>()))::value; \
57 static constexpr auto _uper_optional_counter(detail::num<decltype(_uper_optional_counter(detail::num<>()))::value + 1> n) \
58 -> decltype(n) { return {}; } \
59 [[nodiscard]] inline bool Name ## IsSet() const { return m_optionals[m_optionals.size() - _uper_ ## Name ## OptionalIndex - 1]; }
60}
61
62#define UPER_GADGET_FINALIZE \
63public: \
64 void decode(UPERDecoder &decoder); \
65private: \
66 static constexpr auto _uper_OptionalCount = decltype(_uper_optional_counter(detail::num<>()))::value; \
67 std::bitset<_uper_OptionalCount> m_optionals; \
68 inline void decodeSequence(UPERDecoder &decoder) { \
69 if constexpr (_uper_ExtensionMarker) { \
70 if (decoder.readBoolean()) { \
71 decoder.setError("SEQUENCE with extension marker set not implemented."); \
72 return; \
73 } \
74 } \
75 m_optionals = decoder.readBitset<_uper_OptionalCount>(); \
76 }
77
78#endif // KITINERARY_UPERELEMENT_H
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:00:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.