WsParser_VS/libParse/parse_novel.h

167 lines
6.0 KiB
C
Raw Permalink 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 15:47:42 +00:00
FragmentExistsCheck();
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 .
*/
2025-02-15 15:47:42 +00:00
class LIBPARSE_EXPORT PointGraphCheck : public lib_parse::CheckProvider, public std::enable_shared_from_this<PointGraphCheck> {
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 15:47:42 +00:00
QList<std::shared_ptr<const PointGraphHelper>> pointsSequence() 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-03-29 09:53:28 +00:00
std::shared_ptr<const example_novel::FragmentSlice> 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-03-29 09:53:28 +00:00
PointGraphHelper(std::shared_ptr<const example_novel::FragmentSlice> node);
2024-06-15 08:09:19 +00:00
2025-03-29 09:53:28 +00:00
std::shared_ptr<const example_novel::FragmentSlice> 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;
};
2025-05-16 17:23:29 +00:00
class FragmentNode : public std::enable_shared_from_this<FragmentNode> {
private:
std::shared_ptr<const ast_gen::ElementAccess> _src_fragm = nullptr;
2025-05-16 17:23:29 +00:00
QList<std::shared_ptr<FragmentNode>> _next_fragms;
int _layer_number = -1;
public:
FragmentNode(std::shared_ptr<const ast_gen::ElementAccess> bind);
std::shared_ptr<const ast_gen::ElementAccess> bind() const;
2025-05-16 17:23:29 +00:00
void setLayer(int number);
int layerNumber() const;
QList<std::shared_ptr<FragmentNode>> referNodes() const;
void appendNext(std::shared_ptr<FragmentNode> ins);
};
/**
* @brief
*/
class LIBPARSE_EXPORT FragmentLayerCheck : public lib_parse::CheckProvider {
private:
QHash<QString, std::shared_ptr<FragmentNode>> _node_set;
QList<std::shared_ptr<FragmentNode>> _story_start;
/**
* @brief 线
*/
std::shared_ptr<FragmentNode> _sets_fill(std::shared_ptr<const ast_gen::ElementAccess> node);
/// <summary>
/// 引用网络重构
/// </summary>
/// <param name="node">传入情节定义结点</param>
2025-05-16 17:23:29 +00:00
void _refers_rebuild(std::shared_ptr<const FragmentNode> node);
/// <summary>
/// 节点层级重排
/// </summary>
/// <param name="node">目标结点</param>
/// <param name="curr">目标层级</param>
2025-05-16 17:23:29 +00:00
void node_relayer(std::shared_ptr<FragmentNode> node, int curr = 0);
/// <summary>
/// 层级确认
/// </summary>
/// <param name="node">故事线</param>
void layer_check(std::shared_ptr<const ast_gen::ElementAccess> node);
void story_layer_check(std::shared_ptr<const ast_gen::ElementAccess> story);
2025-05-17 14:25:21 +00:00
void sibling_element_compair(const QString& story, std::shared_ptr<const FragmentNode> prev, std::shared_ptr<const FragmentNode> curr);
2025-05-16 17:23:29 +00:00
public:
// 通过 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