File indexing completed on 2024-03-24 05:56:00
0001 /* 0002 This file is part of the Okteta Core library, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2003, 2007 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_BYTEARRAYMODEL_HPP 0010 #define OKTETA_BYTEARRAYMODEL_HPP 0011 0012 // lib 0013 #include "abstractbytearraymodel.hpp" 0014 #include "bookmarkable.hpp" 0015 #include "bookmarksconstiterator.hpp" 0016 0017 namespace Okteta { 0018 0019 class ByteArrayModelPrivate; 0020 0021 /** 0022 * @author Friedrich W. H. Kossebau 0023 */ 0024 0025 class OKTETACORE_EXPORT ByteArrayModel : public AbstractByteArrayModel 0026 , public Bookmarkable 0027 { 0028 Q_OBJECT 0029 Q_INTERFACES( 0030 Okteta::Bookmarkable 0031 ) 0032 0033 friend class ByteArrayModelPrivate; 0034 0035 public: 0036 ByteArrayModel(Byte* data, int size, int rawSize = -1, bool keepMemory = true, QObject* parent = nullptr); 0037 ByteArrayModel(const Byte* data, int size, QObject* parent = nullptr); 0038 explicit ByteArrayModel(int size = 0, int maxSize = -1, QObject* parent = nullptr); 0039 0040 ~ByteArrayModel() override; 0041 0042 public: // AbstractByteArrayModel API 0043 Byte byte(Address offset) const override; 0044 Size size() const override; 0045 bool isReadOnly() const override; 0046 bool isModified() const override; 0047 0048 Size insert(Address offset, const Byte* insertData, int insertLength) override; 0049 Size remove(const AddressRange& removeRange) override; 0050 Size replace(const AddressRange& removeRange, const Byte* insertData, int insertLength) override; 0051 bool swap(Address firstStart, const AddressRange& secondRange) override; 0052 Size fill(Byte fillByte, Address offset = 0, Size fillLength = -1) override; 0053 void setByte(Address offset, Byte byte) override; 0054 0055 void setModified(bool modified = true) override; 0056 void setReadOnly(bool isReadOnly = true) override; 0057 0058 public: // Okteta::Bookmarkable API 0059 void addBookmarks(const QVector<Okteta::Bookmark>& bookmarks) override; 0060 void removeBookmarks(const QVector<Okteta::Bookmark>& bookmarks) override; 0061 void removeAllBookmarks() override; 0062 void setBookmark(unsigned int index, const Okteta::Bookmark& bookmark) override; 0063 0064 Okteta::BookmarksConstIterator createBookmarksConstIterator() const override; 0065 const Okteta::Bookmark& bookmarkAt(unsigned int index) const override; 0066 const Okteta::Bookmark& bookmarkFor(int offset) const override; 0067 bool containsBookmarkFor(int offset) const override; 0068 unsigned int bookmarksCount() const override; 0069 0070 Q_SIGNALS: // Okteta::Bookmarkable API 0071 void bookmarksAdded(const QVector<Okteta::Bookmark>& bookmarks) override; 0072 void bookmarksRemoved(const QVector<Okteta::Bookmark>& bookmarks) override; 0073 void bookmarksModified(bool modified) override; 0074 void bookmarksModified(const QVector<int>& indizes) override; 0075 0076 public: 0077 void setMaxSize(int maxSize); 0078 /** sets whether the memory given by setData or in the constructor should be kept on resize 0079 */ 0080 void setKeepsMemory(bool keepsMemory = true); 0081 /** sets whether the memory given by setData or in the constructor gets deleted in destructor 0082 * or when new data is set. The data MUST have been allocated using new[] otherwise behaviour 0083 * is undefined */ 0084 void setAutoDelete(bool autoDelete = true); 0085 void setData(Byte* data, int size, int rawSize = -1, bool keepMemory = true); 0086 void signalContentsChanged(int start, int end); 0087 0088 public: 0089 Byte* data() const; 0090 int maxSize() const; 0091 /** returns whether the memory of the byte array is kept on resize */ 0092 bool keepsMemory() const; 0093 bool autoDelete() const; 0094 0095 private: 0096 Q_DECLARE_PRIVATE(ByteArrayModel) 0097 }; 0098 0099 } 0100 0101 #endif