File indexing completed on 2024-06-23 05:48:52

0001 /*
0002     This file is part of the Okteta Kasten module, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2009, 2023 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef KASTEN_UINT32_HPP
0010 #define KASTEN_UINT32_HPP
0011 
0012 // Qt
0013 #include <QLocale>
0014 #include <QMetaType>
0015 #include <QString>
0016 
0017 struct UInt32
0018 {
0019 public:
0020     UInt32(quint32 v);
0021     UInt32(const UInt32&) = default;
0022     UInt32();
0023 
0024     ~UInt32() = default;
0025 
0026     UInt32& operator=(const UInt32&) = default;
0027 
0028 public:
0029     QString toString(bool asHex) const;
0030     QString toString(bool asHex, const QLocale& locale) const;
0031 
0032 public:
0033     quint32 value = 0;
0034 };
0035 
0036 inline UInt32::UInt32() = default;
0037 inline UInt32::UInt32(quint32 v) : value(v) {}
0038 
0039 inline QString UInt32::toString(bool asHex) const
0040 {
0041     return asHex ? QStringLiteral("0x%1").arg(value, 8, 16, QChar::fromLatin1('0')) :
0042                    QString::number(value);
0043 }
0044 
0045 inline QString UInt32::toString(bool asHex, const QLocale& locale) const
0046 {
0047     return asHex ? QStringLiteral("0x%1").arg(value, 8, 16, QChar::fromLatin1('0')) :
0048                    locale.toString(value);
0049 }
0050 
0051 Q_DECLARE_METATYPE(UInt32)
0052 
0053 #endif