File indexing completed on 2024-03-24 17:26:37
0001 /* 0002 This file is part of the Okteta Core library, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2003 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 OKTETA_FIXEDSIZEBYTEARRAYMODEL_HPP 0010 #define OKTETA_FIXEDSIZEBYTEARRAYMODEL_HPP 0011 0012 // lib 0013 #include "abstractbytearraymodel.hpp" 0014 0015 namespace Okteta { 0016 0017 /** base class for all mData buffers that are used to display 0018 * TODO: think about a way to inform KHexEdit that there has been 0019 * a change in the buffer outside. what kind of changes are possible? 0020 * @author Friedrich W. H. Kossebau 0021 */ 0022 0023 class FixedSizeByteArrayModel : public AbstractByteArrayModel 0024 { 0025 Q_OBJECT 0026 0027 public: 0028 /** creates a readonly buffer around the given data */ 0029 FixedSizeByteArrayModel(Byte* data, int size, Byte fillUpChar = '\0', QObject* parent = nullptr); 0030 /** creates a writeable buffer which is deleted at the end */ 0031 explicit FixedSizeByteArrayModel(int size, Byte fillUpChar = '\0', QObject* parent = nullptr); 0032 0033 ~FixedSizeByteArrayModel() override; 0034 0035 public: // AbstractByteArrayModel API 0036 Byte byte(Address offset) const override; 0037 Size size() const override; 0038 bool isReadOnly() const override; 0039 bool isModified() const override; 0040 0041 Size insert(Address offset, const Byte* insertData, int insertLength) override; 0042 Size remove(const AddressRange& removeRange) override; 0043 Size replace(const AddressRange& removeRange, const Byte* insertData, int insertLength) override; 0044 bool swap(Address firstStart, const AddressRange& secondRange) override; 0045 Size fill(Byte fillByte, Address offset = 0, Size fillLength = -1) override; 0046 void setByte(Address offset, Byte byte) override; 0047 0048 void setModified(bool modified = true) override; 0049 void setReadOnly(bool readOnly = true) override; 0050 0051 public: 0052 int compare(const AbstractByteArrayModel& other, const AddressRange& otherRange, Address offset = 0); 0053 int compare(const AbstractByteArrayModel& other, Address otherOffset, Size otherLength, Address offset = 0); 0054 int compare(const AbstractByteArrayModel& other); 0055 0056 public: 0057 Byte* rawData() const; 0058 0059 private: 0060 void reset(unsigned int pos, unsigned int length); 0061 0062 private: 0063 /** */ 0064 Byte* mData; 0065 /***/ 0066 int mSize; 0067 /** */ 0068 Byte mFillUpByte; 0069 /** */ 0070 bool mReadOnly : 1; 0071 /** */ 0072 bool mModified : 1; 0073 /** */ 0074 bool mAutoDelete : 1; 0075 }; 0076 0077 inline Byte FixedSizeByteArrayModel::byte(Address offset) const { return mData[offset]; } 0078 inline Size FixedSizeByteArrayModel::size() const { return mSize; } 0079 0080 inline bool FixedSizeByteArrayModel::isReadOnly() const { return mReadOnly; } 0081 inline bool FixedSizeByteArrayModel::isModified() const { return mModified; } 0082 0083 inline void FixedSizeByteArrayModel::setReadOnly(bool readOnly) { mReadOnly = readOnly; } 0084 inline void FixedSizeByteArrayModel::setModified(bool modified) { mModified = modified; } 0085 0086 inline int FixedSizeByteArrayModel::compare(const AbstractByteArrayModel& other) 0087 { return compare(other, AddressRange::fromWidth(0, other.size()), 0); } 0088 0089 inline int FixedSizeByteArrayModel::compare(const AbstractByteArrayModel& other, Address otherOffset, Size otherLength, Address offset) 0090 { return compare(other, AddressRange::fromWidth(otherOffset, otherLength), offset); } 0091 0092 inline Byte* FixedSizeByteArrayModel::rawData() const { return mData; } 0093 0094 } 0095 0096 #endif