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: 2007, 2009 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_PODDATA_HPP
0010 #define KASTEN_PODDATA_HPP
0011 
0012 // Okteta core
0013 #include <Okteta/Byte>
0014 #include <Okteta/OktetaCore>
0015 // Qt
0016 #include <QSysInfo>
0017 
0018 namespace Okteta {
0019 
0020 class PODData
0021 {
0022 public:
0023     static constexpr int Size = sizeof(double);
0024 
0025 public:
0026     PODData();
0027     PODData(const PODData&) = delete;
0028 
0029     ~PODData() = default;
0030 
0031     PODData& operator=(const PODData&) = delete;
0032 
0033 public:
0034     void setByteOrder(QSysInfo::Endian byteOrder);
0035     bool updateRawData(int size);
0036     Byte* rawData();
0037 
0038 public:
0039     const Byte* originalData() const;
0040     const Byte* byteOrderSetData() const;
0041     QSysInfo::Endian byteOrder() const;
0042 
0043     unsigned long bitValue(int noOfBitsToRead) const;
0044     void getPointers(const void** P8Bit, const void** P16Bit, const void** P32Bit, const void** P64Bit) const;
0045     const void* pointer(int byteCount) const;
0046     int size() const;
0047 
0048 private:
0049     // ensure strict alignment for double as needed on some architectures (e.g. PA-RISC)
0050     using Aligned64Bit = union
0051     {
0052         double mDummy;
0053         Byte mBytes[Size];
0054     };
0055 
0056 private:
0057     Byte* mCurrentOriginalData = nullptr;
0058     Byte* mCurrentEndiannessSetData = nullptr;
0059 
0060     Aligned64Bit mOriginalAligned64Bit;
0061     Aligned64Bit mByteOrderSetAligned64Bit;
0062 
0063     int mCurrentSize = 0;
0064     QSysInfo::Endian mByteOrder = QSysInfo::ByteOrder;
0065 };
0066 
0067 }
0068 
0069 #endif