WsParser_VS/libParse/parse_novel.h

110 lines
3.9 KiB
C
Raw Normal View History

2024-03-17 07:58:28 +00:00
#pragma once
#include "libparse.h"
#include <ast_novel.h>
2025-02-15 12:25:51 +00:00
#include <QtCore/QString>
#include <QtCore/QHash>
#include <memory>
2024-03-17 07:58:28 +00:00
namespace example_novel {
2025-02-15 12:25:51 +00:00
class PointGraphHelper;
/**
* @brief
*/
class LIBPARSE_EXPORT ElementsCache {
private:
QHash<QString, std::shared_ptr<const ast_gen::SyntaxElement>> node_cache;
public:
virtual void clearCache();
virtual std::shared_ptr<const ast_gen::SyntaxElement> appendToCache(std::shared_ptr<const ast_gen::SyntaxElement> named_node);
/**
* @brief
* @param signature
* @return
* @throws
*/
virtual std::shared_ptr<const ast_gen::SyntaxElement> getNamedNodeBy(int paramType, const QString& signature) const;
};
/**
* @brief .
*/
2024-03-17 07:58:28 +00:00
class LIBPARSE_EXPORT FragmentExistsCheck : public lib_parse::CheckProvider {
private:
2025-02-15 12:25:51 +00:00
std::shared_ptr<ElementsCache> _nodes_cache;
void nodes_regist(std::shared_ptr<ElementsCache> cache, std::shared_ptr<const ast_gen::ElementAccess> target);
void exists_check(std::shared_ptr<ElementsCache> cache, std::shared_ptr<const ast_gen::ElementAccess> target) const;
2024-03-17 07:58:28 +00:00
public:
2025-02-15 12:25:51 +00:00
// 通过 CheckProvider 继承
2024-06-15 08:09:19 +00:00
virtual QString name() const override;
2025-02-15 12:25:51 +00:00
virtual void validCheck(std::shared_ptr<const ast_gen::ElementAccess> root) const override;
2024-03-17 07:58:28 +00:00
};
2025-02-15 12:25:51 +00:00
/**
* @brief .
*/
class LIBPARSE_EXPORT FragmentGraphCheck : public lib_parse::CheckProvider, public std::enable_shared_from_this<FragmentGraphCheck> {
2024-06-15 08:09:19 +00:00
private:
2025-02-15 12:25:51 +00:00
QHash<QString, std::shared_ptr<PointGraphHelper>> elements_store;
QList<std::shared_ptr<const PointGraphHelper>> fragments_sort_list;
2024-03-17 07:58:28 +00:00
2025-02-15 12:25:51 +00:00
QList<std::shared_ptr<PointGraphHelper>> refers_cycle_check(
std::shared_ptr<PointGraphHelper> item, QList<std::shared_ptr<PointGraphHelper>> prevs = QList<std::shared_ptr<PointGraphHelper>>()) const;
2024-06-15 08:52:16 +00:00
2024-06-15 08:09:19 +00:00
public:
2025-02-15 12:25:51 +00:00
void setElement(std::shared_ptr<PointGraphHelper> inst);
std::shared_ptr<PointGraphHelper> getElement(const QString &signature) const;
2024-03-17 07:58:28 +00:00
2025-02-15 12:25:51 +00:00
QList<std::shared_ptr<PointGraphHelper>> getHangoutNodes();
bool nodeDismantle(std::shared_ptr<PointGraphHelper> inst);
2024-03-17 07:58:28 +00:00
2025-02-15 12:25:51 +00:00
QList<std::shared_ptr<const PointGraphHelper>> fragmentsSequence() const;
2024-06-20 14:13:06 +00:00
2024-03-17 07:58:28 +00:00
// CheckProvider interface
public:
virtual void validCheck(std::shared_ptr<const ast_gen::ElementAccess> root) const override;
2024-06-15 08:09:19 +00:00
virtual QString name() const override;
2024-03-17 07:58:28 +00:00
};
2025-02-15 12:25:51 +00:00
class PointGraphHelper : public std::enable_shared_from_this<PointGraphHelper> {
2024-03-17 07:58:28 +00:00
private:
2025-02-02 14:30:47 +00:00
std::shared_ptr<const example_novel::PointDefines> node_peer;
2025-02-15 12:25:51 +00:00
QList<std::shared_ptr<PointGraphHelper>> next_nodes;
2024-06-15 08:09:19 +00:00
uint indegree = 0;
2024-03-17 07:58:28 +00:00
public:
2025-02-15 12:25:51 +00:00
PointGraphHelper(std::shared_ptr<const example_novel::PointDefines> node);
2024-06-15 08:09:19 +00:00
2025-02-02 14:30:47 +00:00
std::shared_ptr<const example_novel::PointDefines> nodePeer() const;
2024-03-17 07:58:28 +00:00
2025-02-15 12:25:51 +00:00
void appendNext(std::shared_ptr<PointGraphHelper> node);
QList<std::shared_ptr<PointGraphHelper>> nextList() const;
2024-03-17 07:58:28 +00:00
2024-06-15 08:09:19 +00:00
uint& inDegree();
2024-03-17 07:58:28 +00:00
};
2025-02-15 12:25:51 +00:00
/**
* @brief 线.
*/
class LIBPARSE_EXPORT StoryOrderCheck : public lib_parse::CheckProvider {
private:
uint sort_index = 1;
/**
2025-02-15 12:25:51 +00:00
* .
*
* \param pnode
* \return
*/
QList<std::shared_ptr<const ast_gen::ElementAccess>> valid_docs_peak(std::shared_ptr<const ast_gen::ElementAccess> pnode) const;
public:
2025-02-15 12:25:51 +00:00
// 通过 CheckProvider 继承
QString name() const override;
void validCheck(std::shared_ptr<const ast_gen::ElementAccess> root) const override;
};
2024-03-17 07:58:28 +00:00
} // namespace example_novel