RedPanda-CPP/RedPandaIDE/parser/statementmodel.h

67 lines
2.2 KiB
C
Raw Normal View History

2021-12-26 23:18:28 +08:00
/*
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2021-08-05 23:13:21 +08:00
#ifndef STATEMENTMODEL_H
#define STATEMENTMODEL_H
#include <QObject>
2021-08-08 17:22:37 +08:00
#include <QTextStream>
#include "parserutils.h"
2021-08-05 23:13:21 +08:00
class StatementModel : public QObject
{
Q_OBJECT
public:
explicit StatementModel(QObject *parent = nullptr);
StatementModel(const StatementModel&)=delete;
StatementModel& operator=(const StatementModel&)=delete;
2021-08-05 23:13:21 +08:00
2021-08-29 00:48:23 +08:00
void add(const PStatement& statement);
void deleteStatement(const PStatement& statement);
const StatementMap& childrenStatements(const PStatement& statement = PStatement()) const {
if (!statement) {
return mGlobalStatements;
} else {
return statement->children;
}
}
const StatementMap& childrenStatements(std::weak_ptr<Statement> statement) const { return childrenStatements(statement.lock()); }
void clear() {
mCount=0;
mGlobalStatements.clear();
#ifdef QT_DEBUG
mAllStatements.clear();
#endif
}
2023-10-27 09:49:34 +08:00
int count() const { return mCount; }
#ifdef QT_DEBUG
void dump(const QString& logFile);
void dumpAll(const QString& logFile);
#endif
2021-08-07 18:02:57 +08:00
private:
2021-08-29 00:48:23 +08:00
void addMember(StatementMap& map, const PStatement& statement);
int deleteMember(StatementMap& map, const PStatement& statement);
2021-08-08 17:22:37 +08:00
void dumpStatementMap(StatementMap& map, QTextStream& out, int level);
2021-08-07 14:08:51 +08:00
private:
int mCount;
StatementMap mGlobalStatements; //may have overloaded functions, so use PStatementList to store
#ifdef QT_DEBUG
StatementList mAllStatements;
#endif
2021-08-05 23:13:21 +08:00
};
#endif // STATEMENTMODEL_H