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
12#include <optional>
13
14namespace KItinerary {
15
16// start of an ASN.1 SEQUENCE definition
17#define UPER_GADGET \
18 Q_GADGET \
19 static constexpr detail::num<0> _uper_optional_counter(detail::num<0>) { return {}; } \
20 static constexpr bool _uper_ExtensionMarker = false;
21
22// same as UPER_GADGET, for SEQUENCES with an extension marker
23#define UPER_EXTENDABLE_GADGET \
24 Q_GADGET \
25 static constexpr detail::num<0> _uper_optional_counter(detail::num<0>) { return {}; } \
26 static constexpr bool _uper_ExtensionMarker = true;
27
28// ASN.1 ENUMERATED definitions, with or without extension marker
29#define UPER_ENUM(Name) \
30 Q_ENUM_NS(Name) \
31 constexpr bool uperHasExtensionMarker(Name) { return false; }
32#define UPER_EXTENABLE_ENUM(Name) \
33 Q_ENUM_NS(Name) \
34 constexpr bool uperHasExtensionMarker(Name) { return true; }
35
36#define UPER_ELEMENT(Type, Name) \
37public: \
38 Type Name = {}; /* NOLINT misc-non-private-member-variables-in-classes */ \
39 Q_PROPERTY(Type Name MEMBER Name CONSTANT) \
40 [[nodiscard]] constexpr inline bool Name ## IsSet() const { return true; } \
41 [[nodiscard]] std::optional<Type> Name ## Value() const { return Name; }
42
43#define UPER_ELEMENT_OPTIONAL(Type, Name) \
44public: \
45 Type Name = {}; /* NOLINT misc-non-private-member-variables-in-classes */ \
46 Q_PROPERTY(Type Name MEMBER Name CONSTANT) \
47 Q_PROPERTY(bool Name ## IsSet READ Name ## IsSet) \
48private: \
49 static constexpr int _uper_ ## Name ## OptionalIndex = decltype(_uper_optional_counter(detail::num<>()))::value; \
50 static constexpr auto _uper_optional_counter(detail::num<decltype(_uper_optional_counter(detail::num<>()))::value + 1> n) \
51 -> decltype(n) { return {}; } \
52public: \
53 [[nodiscard]] inline bool Name ## IsSet() const { return m_optionals[m_optionals.size() - _uper_ ## Name ## OptionalIndex - 1]; } \
54 [[nodiscard]] std::optional<Type> Name ## Value() const { return Name ## IsSet() ? std::optional<Type>(Name) : std::optional<Type>(); }
55
56#define UPER_ELEMENT_DEFAULT(Type, Name, DefaultValue) \
57public: \
58 Type Name = DefaultValue; /* NOLINT misc-non-private-member-variables-in-classes */ \
59 Q_PROPERTY(Type Name MEMBER Name CONSTANT) \
60private: \
61 static constexpr int _uper_ ## Name ## OptionalIndex = decltype(_uper_optional_counter(detail::num<>()))::value; \
62 static constexpr auto _uper_optional_counter(detail::num<decltype(_uper_optional_counter(detail::num<>()))::value + 1> n) \
63 -> decltype(n) { return {}; } \
64 [[nodiscard]] inline bool Name ## IsSet() const { return m_optionals[m_optionals.size() - _uper_ ## Name ## OptionalIndex - 1]; } \
65 [[nodiscard]] std::optional<Type> Name ## Value() const { return Name; }
66
67}
68
69#define UPER_GADGET_FINALIZE \
70public: \
71 void decode(UPERDecoder &decoder); \
72private: \
73 static constexpr auto _uper_OptionalCount = decltype(_uper_optional_counter(detail::num<>()))::value; \
74 std::bitset<_uper_OptionalCount> m_optionals; \
75 inline void decodeSequence(UPERDecoder &decoder) { \
76 if constexpr (_uper_ExtensionMarker) { \
77 if (decoder.readBoolean()) { \
78 decoder.setError("SEQUENCE with extension marker set not implemented."); \
79 return; \
80 } \
81 } \
82 m_optionals = decoder.readBitset<_uper_OptionalCount>(); \
83 }
84
85#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-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:52:35 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.