File indexing completed on 2024-11-24 04:46:18

0001 /*
0002     SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 
0008 #pragma once
0009 
0010 #include "kitinerary_export.h"
0011 
0012 #include <QString>
0013 
0014 namespace KItinerary {
0015 
0016 class Uic9183Block;
0017 
0018 /*
0019  * Low-level decoding utilities for UIC 918.3 ticket content.
0020  * @internal
0021  */
0022 namespace Uic9183Utils
0023 {
0024     /** Reads an ASCII encoded numerical value. */
0025     int readAsciiEncodedNumber(const char *data, int size, int offset, int length);
0026     KITINERARY_EXPORT int readAsciiEncodedNumber(const QByteArray &data, int offset, int length);
0027     KITINERARY_EXPORT int readAsciiEncodedNumber(const Uic9183Block &block, int offset, int length);
0028 
0029     /** Reads a UTF8 encoded string. */
0030     QString readUtf8String(const char *data, int size, int offset, int length);
0031     KITINERARY_EXPORT QString readUtf8String(const QByteArray &data, int offset, int length);
0032     KITINERARY_EXPORT QString readUtf8String(const Uic9183Block &block, int offset, int length);
0033 }
0034 
0035 #define UIC_NUM_PROPERTY(Name, Offset, Length) \
0036 public: \
0037     inline int Name() const { return Uic9183Utils::readAsciiEncodedNumber(m_data, Offset, Length); } \
0038     Q_PROPERTY(int Name READ Name)
0039 
0040 #define UIC_STR_PROPERTY(Name, Offset, Length) \
0041 public: \
0042     inline QString Name() const { return Uic9183Utils::readUtf8String(m_data, Offset, Length); } \
0043     Q_PROPERTY(QString Name READ Name)
0044 }
0045