File indexing completed on 2024-04-14 15:52:44

0001 /*
0002     This file is part of the Okteta Core library, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2003, 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 OKTETA_FILEBYTEARRAYMODEL_P_HPP
0010 #define OKTETA_FILEBYTEARRAYMODEL_P_HPP
0011 
0012 // lib
0013 #include "abstractbytearraymodel_p.hpp"
0014 #include "filebytearraymodel.hpp"
0015 // Qt
0016 #include <QVector>
0017 #include <QFile>
0018 
0019 namespace Okteta {
0020 
0021 class FileByteArrayModelPrivate : public AbstractByteArrayModelPrivate
0022 {
0023     using KPageOfChar = QVector<char*>;
0024 
0025 public:
0026     FileByteArrayModelPrivate(FileByteArrayModel* parent, int pageNumber, int pageSize);
0027 
0028     ~FileByteArrayModelPrivate() override;
0029 
0030 public:
0031     Byte byte(Address offset) const;
0032     Size size() const;
0033     bool isReadOnly() const;
0034     void setReadOnly(bool readonly);
0035 
0036 public:
0037     bool isOpen() const;
0038     bool open(const QString& fileName);
0039     bool close();
0040 
0041 private:
0042     bool ensurePageLoaded(unsigned int pageIndex) const;
0043     bool freePage(unsigned int pageIndex) const;
0044 
0045 private:
0046     /** */
0047     mutable QFile mFile;
0048     /**  */
0049     bool mReadOnly : 1;
0050     bool mIsOpen : 1;
0051     /** maximum number of pages which could be currently loaded */
0052     unsigned int mNoOfUsedPages;
0053     /**  number of actually not used pages (in terms of NoOfUsedPages) */
0054     mutable int mNoOfFreePages;
0055     /** number of bytes in a page */
0056     unsigned int mPageSize;
0057     /** first currently loaded page */
0058     mutable int mFirstPage = -1;
0059     /** last currently loaded page */
0060     mutable int mLastPage = -1;
0061     /** */
0062     mutable KPageOfChar mData;
0063     /** */
0064     int mSize = 0;
0065 
0066     /** current offset */
0067     mutable unsigned int mOffsetOfActualPage;
0068     /** points to the actual page */
0069     mutable char* mActualPage = nullptr;
0070 };
0071 
0072 inline Size FileByteArrayModelPrivate::size()        const { return mSize; }
0073 inline bool FileByteArrayModelPrivate::isReadOnly() const { return mReadOnly; }
0074 inline void FileByteArrayModelPrivate::setReadOnly(bool readonly) { mReadOnly = readonly; }
0075 
0076 inline bool FileByteArrayModelPrivate::isOpen() const { return mFile.isOpen(); }
0077 
0078 }
0079 
0080 #endif