完成构建引用网络
This commit is contained in:
parent
28bde11bda
commit
af4dde1629
|
@ -3,76 +3,151 @@
|
|||
using namespace example_novel;
|
||||
using namespace printer;
|
||||
|
||||
Access::Access(std::shared_ptr<ast_gen::ElementAccess> handle) :access_handle(handle) {}
|
||||
Access::Access(std::shared_ptr<const ast_gen::ElementAccess> handle) :access_handle(handle) {}
|
||||
|
||||
std::shared_ptr<ast_gen::ElementAccess> Access::accessPeers() const { return access_handle; }
|
||||
std::shared_ptr<const ast_gen::ElementAccess> Access::accessPeers() const { return access_handle; }
|
||||
|
||||
void Access::setHtmlRefer(const QString& href) { this->refers_store = href; }
|
||||
|
||||
QString Access::htmlRefer() const { return this->refers_store; }
|
||||
|
||||
Element::Element(std::shared_ptr<ast_gen::ElementAccess> handle) :Access(handle) {}
|
||||
Element::Element(std::shared_ptr<const ast_gen::ElementAccess> handle) :Access(handle) {}
|
||||
|
||||
std::shared_ptr<Element> Element::siblingNext() const {
|
||||
return this->sibling_store;
|
||||
Group::Group(std::shared_ptr<const ast_gen::ElementAccess> handle) : Access(handle) {}
|
||||
|
||||
void Group::append(std::shared_ptr<Element> elm)
|
||||
{
|
||||
element_store.append(elm);
|
||||
}
|
||||
|
||||
void Element::setNext(std::shared_ptr<Element> inst) {
|
||||
this->sibling_store = inst;
|
||||
}
|
||||
|
||||
Group::Group(std::shared_ptr<ast_gen::ElementAccess> handle) : Access(handle) {}
|
||||
|
||||
void Group::setChild(std::shared_ptr<Element> elm) {
|
||||
this->element_store = elm;
|
||||
}
|
||||
|
||||
std::shared_ptr<Element> Group::element() const {
|
||||
QList<std::shared_ptr<Element>> Group::elements() const
|
||||
{
|
||||
return this->element_store;
|
||||
}
|
||||
|
||||
StoryLine::StoryLine(std::shared_ptr<ast_gen::ElementAccess> handle) :Group(handle) {}
|
||||
StoryLine::StoryLine(std::shared_ptr<const ast_gen::ElementAccess> handle) :Group(handle) {}
|
||||
|
||||
QString printer::StoryLine::toHTML() const
|
||||
QString StoryLine::toHTML() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
StoryVolume::StoryVolume(std::shared_ptr<ast_gen::ElementAccess> handle) : Group(handle) {}
|
||||
StoryVolume::StoryVolume(std::shared_ptr<const ast_gen::ElementAccess> handle) : Group(handle) {}
|
||||
|
||||
QString printer::StoryVolume::toHTML() const
|
||||
QString StoryVolume::toHTML() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
FragmentRef::FragmentRef(std::shared_ptr<ast_gen::ElementAccess> handle) : Element(handle) {}
|
||||
FragmentRef::FragmentRef(std::shared_ptr<const ast_gen::ElementAccess> handle) : Element(handle) {}
|
||||
|
||||
QString printer::FragmentRef::toOutsideHTML() const
|
||||
QString FragmentRef::toOutsideHTML() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString printer::FragmentRef::toDefinitionHTML() const
|
||||
QString FragmentRef::toDefinitionHTML() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
Fragment::Fragment(std::shared_ptr<ast_gen::ElementAccess> handle) : Element(handle) {}
|
||||
Fragment::Fragment(std::shared_ptr<const ast_gen::ElementAccess> handle) : Element(handle) {}
|
||||
|
||||
void printer::Fragment::appendRefers(std::shared_ptr<FragmentRef> inst) {
|
||||
void Fragment::appendRefers(std::shared_ptr<FragmentRef> inst) {
|
||||
this->additionals_store.append(inst);
|
||||
}
|
||||
|
||||
QList<std::shared_ptr<FragmentRef>> printer::Fragment::additionals() const {
|
||||
QList<std::shared_ptr<FragmentRef>> Fragment::additionals() const {
|
||||
return this->additionals_store;
|
||||
}
|
||||
|
||||
QString printer::Fragment::toOutsideHTML() const
|
||||
QString Fragment::toOutsideHTML() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString printer::Fragment::toDefinitionHTML() const
|
||||
QString Fragment::toDefinitionHTML() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
#include <ast_novel.h>
|
||||
void tools_printer::build_fragments(std::shared_ptr<const ast_gen::ElementAccess> novel_root)
|
||||
{
|
||||
if (novel_root->element()->typeMark() == (int)example_novel::NovelNode::FragmentDefine) {
|
||||
auto inst = std::make_shared<Fragment>(novel_root);
|
||||
this->fragment_defines[novel_root->element()->signature()] = inst;
|
||||
}
|
||||
|
||||
for (auto& inst_c : novel_root->children()) {
|
||||
build_fragments(inst_c);
|
||||
}
|
||||
}
|
||||
|
||||
void tools_printer::build_refers_network(std::shared_ptr<const ast_gen::ElementAccess> novel_node)
|
||||
{
|
||||
switch ((example_novel::NovelNode)novel_node->element()->typeMark()) {
|
||||
case example_novel::NovelNode::StoryDefine: {
|
||||
auto storyinst = std::make_shared<StoryLine>(novel_node);
|
||||
this->storyline_defines[novel_node->element()->signature()] = storyinst;
|
||||
build_storyline(storyinst);
|
||||
}return;
|
||||
case example_novel::NovelNode::VolumeDefine: {
|
||||
auto volumeinst = std::make_shared<StoryVolume>(novel_node);
|
||||
this->volume_defines[novel_node->element()->signature()] = volumeinst;
|
||||
build_volumeline(volumeinst);
|
||||
}return;
|
||||
}
|
||||
|
||||
for (auto& inst_c : novel_node->children())
|
||||
build_refers_network(inst_c);
|
||||
}
|
||||
|
||||
void tools_printer::build_storyline(std::shared_ptr<StoryLine> line, std::shared_ptr<const ast_gen::ElementAccess> novel_node)
|
||||
{
|
||||
if (!novel_node) {
|
||||
for (auto& inst_c : line->accessPeers()->children()) {
|
||||
build_storyline(line, inst_c);
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch ((example_novel::NovelNode)novel_node->element()->typeMark())
|
||||
{
|
||||
case example_novel::NovelNode::FragmentDefine: {
|
||||
auto inst = this->fragment_defines[novel_node->element()->signature()];
|
||||
line->append(inst);
|
||||
}return;
|
||||
case example_novel::NovelNode::FragmentRefer: {
|
||||
auto refer_node = std::dynamic_pointer_cast<const example_novel::FragmentRefers>(novel_node->element());
|
||||
auto refer_fragment = this->fragment_defines[refer_node->signature().mid(1)];
|
||||
auto inst = std::make_shared<FragmentRef>(novel_node);
|
||||
refer_fragment->appendRefers(inst);
|
||||
line->append(inst);
|
||||
}return;
|
||||
}
|
||||
|
||||
for (auto& inst_c : novel_node->children())
|
||||
build_storyline(line, inst_c);
|
||||
}
|
||||
}
|
||||
|
||||
void tools_printer::build_volumeline(std::shared_ptr<StoryVolume> line, std::shared_ptr<const ast_gen::ElementAccess> novel_node)
|
||||
{
|
||||
if (!novel_node) {
|
||||
for (auto& inst_c : line->accessPeers()->children())
|
||||
build_volumeline(line, inst_c);
|
||||
}
|
||||
else {
|
||||
if (example_novel::NovelNode::FragmentRefer == (example_novel::NovelNode)novel_node->element()->typeMark()) {
|
||||
auto refer_node = std::dynamic_pointer_cast<const example_novel::FragmentRefers>(novel_node->element());
|
||||
auto refer_fragment = this->fragment_defines[refer_node->signature().mid(1)];
|
||||
auto inst = std::make_shared<FragmentRef>(novel_node);
|
||||
refer_fragment->appendRefers(inst);
|
||||
line->append(inst);
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto& inst_c : novel_node->children())
|
||||
build_volumeline(line, inst_c);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,16 +11,16 @@ namespace printer {
|
|||
*/
|
||||
class Access : public std::enable_shared_from_this<Access> {
|
||||
public:
|
||||
Access(std::shared_ptr<ast_gen::ElementAccess> handle);
|
||||
Access(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
||||
virtual ~Access() = default;
|
||||
|
||||
std::shared_ptr<ast_gen::ElementAccess> accessPeers() const;
|
||||
std::shared_ptr<const ast_gen::ElementAccess> accessPeers() const;
|
||||
|
||||
void setHtmlRefer(const QString& href);
|
||||
QString htmlRefer() const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<ast_gen::ElementAccess> access_handle;
|
||||
std::shared_ptr<const ast_gen::ElementAccess> access_handle;
|
||||
QString refers_store;
|
||||
};
|
||||
|
||||
|
@ -29,17 +29,11 @@ namespace printer {
|
|||
*/
|
||||
class Element : public Access {
|
||||
public:
|
||||
Element(std::shared_ptr<ast_gen::ElementAccess> handle);
|
||||
Element(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
||||
virtual ~Element() = default;
|
||||
|
||||
virtual QString toOutsideHTML() const = 0;
|
||||
virtual QString toDefinitionHTML() const = 0;
|
||||
|
||||
std::shared_ptr<Element> siblingNext() const;
|
||||
void setNext(std::shared_ptr<Element> inst);
|
||||
|
||||
private:
|
||||
std::shared_ptr<Element> sibling_store;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -47,21 +41,21 @@ namespace printer {
|
|||
*/
|
||||
class Group : public Access {
|
||||
public:
|
||||
Group(std::shared_ptr<ast_gen::ElementAccess> handle);
|
||||
Group(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
||||
virtual ~Group() = default;
|
||||
|
||||
virtual QString toHTML() const = 0;
|
||||
|
||||
void setChild(std::shared_ptr<Element> elm);
|
||||
std::shared_ptr<Element> element() const;
|
||||
void append(std::shared_ptr<Element> elm);
|
||||
QList<std::shared_ptr<Element>> elements() const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Element> element_store;
|
||||
QList<std::shared_ptr<Element>> element_store;
|
||||
};
|
||||
|
||||
class StoryLine : public Group {
|
||||
public:
|
||||
StoryLine(std::shared_ptr<ast_gen::ElementAccess> handle);
|
||||
StoryLine(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
||||
|
||||
|
||||
// 通过 Group 继承
|
||||
|
@ -71,7 +65,7 @@ namespace printer {
|
|||
|
||||
class StoryVolume : public Group {
|
||||
public:
|
||||
StoryVolume(std::shared_ptr<ast_gen::ElementAccess> handle);
|
||||
StoryVolume(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
||||
|
||||
|
||||
// 通过 Group 继承
|
||||
|
@ -79,9 +73,12 @@ namespace printer {
|
|||
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief Çé½ÚƬ¶ÎÒýÓö¨Òå
|
||||
*/
|
||||
class FragmentRef : public Element {
|
||||
public:
|
||||
FragmentRef(std::shared_ptr<ast_gen::ElementAccess> handle);
|
||||
FragmentRef(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
||||
|
||||
// 通过 Element 继承
|
||||
QString toOutsideHTML() const override;
|
||||
|
@ -96,7 +93,7 @@ namespace printer {
|
|||
QList<std::shared_ptr<FragmentRef>> additionals_store;
|
||||
|
||||
public:
|
||||
Fragment(std::shared_ptr<ast_gen::ElementAccess> handle);
|
||||
Fragment(std::shared_ptr<const ast_gen::ElementAccess> handle);
|
||||
|
||||
void appendRefers(std::shared_ptr<FragmentRef> inst);
|
||||
QList<std::shared_ptr<FragmentRef>> additionals() const;
|
||||
|
@ -107,4 +104,19 @@ namespace printer {
|
|||
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);
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue