159 lines
4.1 KiB
C++
159 lines
4.1 KiB
C++
#pragma once
|
||
#include <QList>
|
||
#include <QFileInfo>
|
||
#include <QDomDocument>
|
||
|
||
#include <ast_gen.h>
|
||
#include <parse_novel.h>
|
||
|
||
namespace printer {
|
||
/*
|
||
* @brief 所有可访问元素的基类:卷宗、故事线、情节等
|
||
*/
|
||
class Access : public std::enable_shared_from_this<Access> {
|
||
public:
|
||
Access(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
||
virtual ~Access() = default;
|
||
|
||
/*
|
||
* @brief 获取绑定的语法元素
|
||
* @return 元素内存指针
|
||
*/
|
||
std::shared_ptr<const ast_gen::ElementAccess> accessPeers() const;
|
||
|
||
/*
|
||
* @brief 设置汇总页面路径
|
||
* @param href 页面路径
|
||
*/
|
||
void setPageRefers(const QString& href);
|
||
QString pageRefers() const;
|
||
|
||
/*
|
||
* @brief 获取汇总页面的HTML
|
||
*/
|
||
virtual void buildPageHTML(QDomElement& doc) const = 0;
|
||
|
||
private:
|
||
std::shared_ptr<const ast_gen::ElementAccess> access_handle;
|
||
QString summary_refer_store;
|
||
};
|
||
|
||
/*
|
||
* @brief 可访问片段元素:故事片段本篇,故事片段引用
|
||
*/
|
||
class Element : public Access {
|
||
public:
|
||
Element(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
||
virtual ~Element() = default;
|
||
|
||
/*
|
||
* @brief 设置片段URL,从故事汇总页面跳转回出处页面
|
||
*/
|
||
virtual void setSliceRefer(const QString& href);
|
||
virtual QString sliceRefers() const;
|
||
|
||
/*
|
||
* @brief 获取故事片段出处的节点HTML
|
||
*/
|
||
virtual void buildSliceHTML(QDomElement &doc) const = 0;
|
||
|
||
private:
|
||
QString refer_store;
|
||
};
|
||
|
||
/*
|
||
* @brief 可访问集合的基类:故事线、故事卷宗
|
||
*/
|
||
class Group : public Access {
|
||
public:
|
||
Group(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
||
virtual ~Group() = default;
|
||
|
||
void append(std::shared_ptr<Element> elm);
|
||
QList<std::shared_ptr<Element>> elements() const;
|
||
std::shared_ptr<Element> getElement(const QString& signature) const;
|
||
|
||
private:
|
||
QList<std::shared_ptr<Element>> element_store;
|
||
};
|
||
|
||
class StoryLine : public Group {
|
||
public:
|
||
StoryLine(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
||
|
||
// 通过 Group 继承
|
||
void buildPageHTML(QDomElement& doc) const override;
|
||
|
||
};
|
||
|
||
class StoryVolume : public Group {
|
||
public:
|
||
StoryVolume(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
||
|
||
// 通过 Group 继承
|
||
void buildPageHTML(QDomElement& doc) const override;
|
||
|
||
};
|
||
class Fragment;
|
||
/*
|
||
* @brief 情节片段引用定义
|
||
*/
|
||
class FragmentRef : public Element {
|
||
public:
|
||
FragmentRef(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
||
|
||
void setHost(std::shared_ptr<Fragment> frag_inst);
|
||
std::shared_ptr<Fragment> hostFragment() const;
|
||
|
||
// 通过 Access 继承
|
||
void buildPageHTML(QDomElement& doc) const override;
|
||
|
||
// 通过 Element 继承
|
||
void buildSliceHTML(QDomElement& doc) const override;
|
||
|
||
private:
|
||
std::weak_ptr<Fragment> host_inst;
|
||
};
|
||
|
||
/*
|
||
* @brief 情节片段本篇定义,存储情节引用定义
|
||
*/
|
||
class Fragment : public Element{
|
||
private:
|
||
QList<std::shared_ptr<FragmentRef>> additionals_store;
|
||
|
||
public:
|
||
Fragment(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
||
|
||
void appendRefers(std::shared_ptr<FragmentRef> inst);
|
||
QList<std::shared_ptr<FragmentRef>> additionals() const;
|
||
|
||
// 通过 Access 继承
|
||
void buildPageHTML(QDomElement& doc) const override;
|
||
|
||
// 通过 Element 继承
|
||
void buildSliceHTML(QDomElement& doc) const override;
|
||
};
|
||
|
||
|
||
class tools_printer {
|
||
public:
|
||
QHash<QString, std::shared_ptr<Fragment>> fragment_defines;
|
||
QHash<QString, std::shared_ptr<StoryLine>> storyline_defines;
|
||
QHash<QString, std::shared_ptr<StoryVolume>> volume_defines;
|
||
|
||
public:
|
||
void build_fragments(std::shared_ptr<const ast_gen::ElementAccess> novel_root);
|
||
|
||
void build_refers_network(std::shared_ptr<const ast_gen::ElementAccess> novel_node);
|
||
|
||
void build_storyline(std::shared_ptr<StoryLine> line, std::shared_ptr<const ast_gen::ElementAccess> novel_node = nullptr);
|
||
void build_volumeline(std::shared_ptr<StoryVolume> line, std::shared_ptr<const ast_gen::ElementAccess> novel_node = nullptr);
|
||
|
||
void fragments_anchors_define(const QList<std::shared_ptr<Fragment>> &list, const QDir &destdir);
|
||
void storylines_anchors_define(const QList<std::shared_ptr<StoryLine>> &list, const QDir &destdir);
|
||
void volumes_anchors_define(const QList<std::shared_ptr<StoryVolume>> &list, const QDir &destdir);
|
||
|
||
QString storylines_paint(const QList<std::shared_ptr<StoryLine>> lines);
|
||
};
|
||
} |