Commit f52d5c0d authored by Volker Krause's avatar Volker Krause
Browse files

Add basic uPER element macros

This reduces the boilerplate needed for Q_PROPERTY declarations, and it
adds proper handling of optional elements.

This can potentially expanded to automatically count optional elements
with a mechanism similar to the one used for generating the comparison
operator in the datatype classes, which would avoid the error-prone
manual indexing.

We probably want something similar for the implementation as well, that
is also still rather verbose.
parent fddaecef
......@@ -11,6 +11,7 @@ target_sources(KPimItinerary PRIVATE
asn1/berelement.cpp
asn1/bitvector.cpp
asn1/uperdecoder.cpp
asn1/uperelement.cpp
datatypes/action.cpp
datatypes/boattrip.cpp
......
/*
SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "uperelement.h"
using namespace KItinerary;
/*
SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KITINERARY_UPERELEMENT_H
#define KITINERARY_UPERELEMENT_H
namespace KItinerary {
#define UPER_GADGET \
Q_GADGET
#define UPER_ELEMENT(Type, Name) \
public: \
Type Name = {}; \
Q_PROPERTY(Type Name MEMBER Name CONSTANT)
#define UPER_ELEMENT_OPTIONAL(Type, Name, OptionalIndex) \
public: \
Type Name = {}; \
inline bool Name ## IsSet() const { return m_optionals[m_optionals.size() - OptionalIndex - 1]; } \
Q_PROPERTY(Type Name MEMBER Name CONSTANT) \
Q_PROPERTY(bool Name ## IsSet READ Name ## IsSet)
#define UPER_ELEMENT_DEFAULT(Type, Name, DefaultValue, OptionalIndex) \
public: \
Type Name = DefaultValue; \
Q_PROPERTY(Type Name MEMBER Name CONSTANT) \
private: \
inline bool Name ## IsSet() const { return m_optionals[m_optionals.size() - OptionalIndex - 1]; }
}
#endif // KITINERARY_UPERELEMENT_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment