167 lines
6.0 KiB
C++
167 lines
6.0 KiB
C++
#pragma once
|
|
|
|
#include "libparse.h"
|
|
#include <ast_novel.h>
|
|
#include <QtCore/QString>
|
|
#include <QtCore/QHash>
|
|
#include <memory>
|
|
|
|
namespace example_novel {
|
|
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 剧情存在性校验器.
|
|
*/
|
|
class LIBPARSE_EXPORT FragmentExistsCheck : public lib_parse::CheckProvider {
|
|
private:
|
|
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;
|
|
|
|
public:
|
|
FragmentExistsCheck();
|
|
|
|
// 通过 CheckProvider 继承
|
|
virtual QString name() const override;
|
|
virtual void validCheck(std::shared_ptr<const ast_gen::ElementAccess> root) const override;
|
|
};
|
|
|
|
/**
|
|
* @brief 情节节点校验.
|
|
*/
|
|
class LIBPARSE_EXPORT PointGraphCheck : public lib_parse::CheckProvider, public std::enable_shared_from_this<PointGraphCheck> {
|
|
private:
|
|
QHash<QString, std::shared_ptr<PointGraphHelper>> elements_store;
|
|
QList<std::shared_ptr<const PointGraphHelper>> fragments_sort_list;
|
|
|
|
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;
|
|
|
|
public:
|
|
void setElement(std::shared_ptr<PointGraphHelper> inst);
|
|
std::shared_ptr<PointGraphHelper> getElement(const QString &signature) const;
|
|
|
|
QList<std::shared_ptr<PointGraphHelper>> getHangoutNodes();
|
|
bool nodeDismantle(std::shared_ptr<PointGraphHelper> inst);
|
|
|
|
QList<std::shared_ptr<const PointGraphHelper>> pointsSequence() const;
|
|
|
|
// CheckProvider interface
|
|
public:
|
|
virtual void validCheck(std::shared_ptr<const ast_gen::ElementAccess> root) const override;
|
|
virtual QString name() const override;
|
|
};
|
|
|
|
class PointGraphHelper : public std::enable_shared_from_this<PointGraphHelper> {
|
|
private:
|
|
std::shared_ptr<const example_novel::FragmentSlice> node_peer;
|
|
QList<std::shared_ptr<PointGraphHelper>> next_nodes;
|
|
uint indegree = 0;
|
|
|
|
public:
|
|
PointGraphHelper(std::shared_ptr<const example_novel::FragmentSlice> node);
|
|
|
|
std::shared_ptr<const example_novel::FragmentSlice> nodePeer() const;
|
|
|
|
void appendNext(std::shared_ptr<PointGraphHelper> node);
|
|
QList<std::shared_ptr<PointGraphHelper>> nextList() const;
|
|
|
|
uint& inDegree();
|
|
};
|
|
|
|
/**
|
|
* @brief 故事线排序校验.
|
|
*/
|
|
class LIBPARSE_EXPORT StoryOrderCheck : public lib_parse::CheckProvider {
|
|
private:
|
|
uint sort_index = 1;
|
|
/**
|
|
* 获取合适的文档节点.
|
|
*
|
|
* \param pnode
|
|
* \return
|
|
*/
|
|
QList<std::shared_ptr<const ast_gen::ElementAccess>> valid_docs_peak(std::shared_ptr<const ast_gen::ElementAccess> pnode) const;
|
|
|
|
public:
|
|
// 通过 CheckProvider 继承
|
|
QString name() const override;
|
|
void validCheck(std::shared_ptr<const ast_gen::ElementAccess> root) const override;
|
|
};
|
|
|
|
class FragmentNode : public std::enable_shared_from_this<FragmentNode> {
|
|
private:
|
|
std::shared_ptr<const ast_gen::ElementAccess> _src_fragm = nullptr;
|
|
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;
|
|
|
|
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>
|
|
void _refers_rebuild(std::shared_ptr<const FragmentNode> node);
|
|
|
|
/// <summary>
|
|
/// 节点层级重排
|
|
/// </summary>
|
|
/// <param name="node">目标结点</param>
|
|
/// <param name="curr">目标层级</param>
|
|
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);
|
|
void sibling_element_compair(const QString& story, std::shared_ptr<const FragmentNode> prev, std::shared_ptr<const FragmentNode> curr);
|
|
|
|
public:
|
|
// 通过 CheckProvider 继承
|
|
QString name() const override;
|
|
void validCheck(std::shared_ptr<const ast_gen::ElementAccess> root) const override;
|
|
};
|
|
} // namespace example_novel
|