1/*
2 * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#ifndef STATEMENTMODEL_H
18#define STATEMENTMODEL_H
19
20#include <QObject>
21#include <QTextStream>
22#include "parserutils.h"
23
24class StatementModel : public QObject
25{
26 Q_OBJECT
27public:
28 explicit StatementModel(QObject *parent = nullptr);
29
30 void add(const PStatement& statement);
31// function DeleteFirst: Integer;
32// function DeleteLast: Integer;
33 void deleteStatement(const PStatement& statement);
34 const StatementMap& childrenStatements(const PStatement& statement = PStatement()) const;
35 const StatementMap& childrenStatements(std::weak_ptr<Statement> statement) const;
36 void clear();
37 void dump(const QString& logFile);
38#ifdef QT_DEBUG
39 void dumpAll(const QString& logFile);
40#endif
41private:
42 void addMember(StatementMap& map, const PStatement& statement);
43 int deleteMember(StatementMap& map, const PStatement& statement);
44 void dumpStatementMap(StatementMap& map, QTextStream& out, int level);
45private:
46 int mCount;
47 StatementMap mGlobalStatements; //may have overloaded functions, so use PStatementList to store
48#ifdef QT_DEBUG
49 StatementList mAllStatements;
50#endif
51};
52
53#endif // STATEMENTMODEL_H
54