File indexing completed on 2024-05-12 05:43:33

0001 /*
0002     Copyright (C) 2015 Volker Krause <vkrause@kde.org>
0003 
0004     This program is free software; you can redistribute it and/or modify it
0005     under the terms of the GNU Library General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or (at your
0007     option) any later version.
0008 
0009     This program is distributed in the hope that it will be useful, but WITHOUT
0010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0012     License for more details.
0013 
0014     You should have received a copy of the GNU General Public License
0015     along with this program.  If not, see <https://www.gnu.org/licenses/>.
0016 */
0017 
0018 #ifndef TYPEMODEL_H
0019 #define TYPEMODEL_H
0020 
0021 #include <QAbstractItemModel>
0022 #include <QVector>
0023 
0024 class ElfFileSet;
0025 class ElfFile;
0026 class DwarfDie;
0027 
0028 /** All data types found in a ELF file set. */
0029 class TypeModel : public QAbstractItemModel
0030 {
0031     Q_OBJECT
0032 public:
0033     enum Role {
0034         DetailRole = Qt::UserRole + 1
0035     };
0036 
0037     explicit TypeModel(QObject* parent = nullptr);
0038     ~TypeModel();
0039 
0040     void setFileSet(ElfFileSet *fileSet);
0041 
0042     int rowCount(const QModelIndex& parent = QModelIndex()) const override;
0043     int columnCount(const QModelIndex& parent = QModelIndex()) const override;
0044     QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
0045     QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
0046     QModelIndex parent(const QModelIndex& child) const override;
0047     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0048 
0049     bool hasInvalidDies() const { return m_hasInvalidDies; }
0050 private:
0051     void addFile(ElfFile *file);
0052     bool addDwarfDieRecursive(DwarfDie* die, uint32_t parentId);
0053 
0054     // the tree hierarchy is built using 32bit sequential ids, which act as index for the node struct
0055     struct Node {
0056         DwarfDie *die = nullptr;
0057     };
0058     QVector<QVector<uint32_t>> m_childMap;
0059     QVector<uint32_t> m_parentMap;
0060     QVector<Node> m_nodes;
0061 
0062     ElfFileSet *m_fileSet = nullptr;
0063     bool m_hasInvalidDies;
0064 };
0065 
0066 #endif // TYPEMODEL_H