122 lines
3.0 KiB
C++
122 lines
3.0 KiB
C++
#pragma once
|
|
#include <QList>
|
|
#include <QFileInfo>
|
|
|
|
#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;
|
|
|
|
std::shared_ptr<const ast_gen::ElementAccess> accessPeers() const;
|
|
|
|
void setHtmlRefer(const QString& href);
|
|
QString htmlRefer() const;
|
|
|
|
private:
|
|
std::shared_ptr<const ast_gen::ElementAccess> access_handle;
|
|
QString refers_store;
|
|
};
|
|
|
|
/*
|
|
* @brief 可访问片段元素:故事片段本篇,故事片段引用
|
|
*/
|
|
class Element : public Access {
|
|
public:
|
|
Element(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
|
virtual ~Element() = default;
|
|
|
|
virtual QString toOutsideHTML() const = 0;
|
|
virtual QString toDefinitionHTML() const = 0;
|
|
};
|
|
|
|
/*
|
|
* @brief 可访问集合的基类:故事线、故事卷宗
|
|
*/
|
|
class Group : public Access {
|
|
public:
|
|
Group(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
|
virtual ~Group() = default;
|
|
|
|
virtual QString toHTML() const = 0;
|
|
|
|
void append(std::shared_ptr<Element> elm);
|
|
QList<std::shared_ptr<Element>> elements() const;
|
|
|
|
private:
|
|
QList<std::shared_ptr<Element>> element_store;
|
|
};
|
|
|
|
class StoryLine : public Group {
|
|
public:
|
|
StoryLine(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
|
|
|
|
|
// 通过 Group 继承
|
|
QString toHTML() const override;
|
|
|
|
};
|
|
|
|
class StoryVolume : public Group {
|
|
public:
|
|
StoryVolume(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
|
|
|
|
|
// 通过 Group 继承
|
|
QString toHTML() const override;
|
|
|
|
};
|
|
|
|
/*
|
|
* @brief 情节片段引用定义
|
|
*/
|
|
class FragmentRef : public Element {
|
|
public:
|
|
FragmentRef(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
|
|
|
// 通过 Element 继承
|
|
QString toOutsideHTML() const override;
|
|
QString toDefinitionHTML() const override;
|
|
};
|
|
|
|
/*
|
|
* @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;
|
|
|
|
|
|
// 通过 Element 继承
|
|
QString toOutsideHTML() const override;
|
|
QString toDefinitionHTML() const override;
|
|
};
|
|
|
|
|
|
class tools_printer {
|
|
private:
|
|
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);
|
|
};
|
|
} |