189 lines
6.0 KiB
C++
189 lines
6.0 KiB
C++
#include "htmlprint.h"
|
|
#include <QDir>
|
|
|
|
using namespace example_novel;
|
|
using namespace printer;
|
|
|
|
Access::Access(std::shared_ptr<const ast_gen::ElementAccess> handle) :access_handle(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<const ast_gen::ElementAccess> handle) :Access(handle) {}
|
|
|
|
Group::Group(std::shared_ptr<const ast_gen::ElementAccess> handle) : Access(handle) {}
|
|
|
|
void Group::append(std::shared_ptr<Element> elm)
|
|
{
|
|
element_store.append(elm);
|
|
}
|
|
|
|
QList<std::shared_ptr<Element>> Group::elements() const
|
|
{
|
|
return this->element_store;
|
|
}
|
|
|
|
StoryLine::StoryLine(std::shared_ptr<const ast_gen::ElementAccess> handle) :Group(handle) {}
|
|
|
|
QString StoryLine::toHTML() const
|
|
{
|
|
return QString();
|
|
}
|
|
|
|
StoryVolume::StoryVolume(std::shared_ptr<const ast_gen::ElementAccess> handle) : Group(handle) {}
|
|
|
|
QString StoryVolume::toHTML() const
|
|
{
|
|
return QString();
|
|
}
|
|
|
|
FragmentRef::FragmentRef(std::shared_ptr<const ast_gen::ElementAccess> handle) : Element(handle) {}
|
|
|
|
QString FragmentRef::toOutsideHTML() const
|
|
{
|
|
return QString();
|
|
}
|
|
|
|
QString FragmentRef::toDefinitionHTML() const
|
|
{
|
|
return QString();
|
|
}
|
|
|
|
Fragment::Fragment(std::shared_ptr<const ast_gen::ElementAccess> handle) : Element(handle) {}
|
|
|
|
void Fragment::appendRefers(std::shared_ptr<FragmentRef> inst) {
|
|
this->additionals_store.append(inst);
|
|
}
|
|
|
|
QList<std::shared_ptr<FragmentRef>> Fragment::additionals() const {
|
|
return this->additionals_store;
|
|
}
|
|
|
|
QString Fragment::toOutsideHTML() const
|
|
{
|
|
return QString();
|
|
}
|
|
|
|
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->referSignature()];
|
|
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> volume, std::shared_ptr<const ast_gen::ElementAccess> novel_node)
|
|
{
|
|
if (!novel_node) {
|
|
for (auto& inst_c : volume->accessPeers()->children())
|
|
build_volumeline(volume, 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->referSignature()];
|
|
auto inst = std::make_shared<FragmentRef>(novel_node);
|
|
refer_fragment->appendRefers(inst);
|
|
volume->append(inst);
|
|
return;
|
|
}
|
|
|
|
for (auto& inst_c : novel_node->children())
|
|
build_volumeline(volume, inst_c);
|
|
}
|
|
}
|
|
|
|
void printer::tools_printer::fragments_anchors_define(const QList<std::shared_ptr<Fragment>>& list, const QDir & destdir) {
|
|
for (auto &it : list) {
|
|
auto address_x = QString::number((qulonglong)it->accessPeers()->element().get());
|
|
it->setHtmlRefer(destdir.absoluteFilePath(QString("%1.html").arg(address_x)));
|
|
}
|
|
}
|
|
|
|
std::function<void(const QList<std::shared_ptr<Element>>&, const QDir &)> refers_refresh =
|
|
[&](const QList<std::shared_ptr<Element>> &items, const QDir &destdir){
|
|
for (auto &item : items) {
|
|
auto refer = std::dynamic_pointer_cast<FragmentRef>(item);
|
|
if (refer) {
|
|
auto address_x = QString::number((qulonglong)refer->accessPeers()->element().get());
|
|
refer->setHtmlRefer(destdir.absoluteFilePath(QString("%1.html").arg(address_x)));
|
|
}
|
|
}
|
|
};
|
|
|
|
void printer::tools_printer::storylines_anchors_define(const QList<std::shared_ptr<StoryLine>>& list, const QDir & destdir) {
|
|
for (auto &it : list) {
|
|
auto address_x = QString::number((qulonglong)it->accessPeers()->element().get());
|
|
it->setHtmlRefer(destdir.absoluteFilePath(QString("%1.html").arg(address_x)));
|
|
refers_refresh(it->elements(), destdir);
|
|
}
|
|
}
|
|
|
|
void printer::tools_printer::volumes_anchors_define(const QList<std::shared_ptr<StoryVolume>>& list, const QDir & destdir) {
|
|
for (auto &it : list) {
|
|
auto address_x = QString::number((qulonglong)it->accessPeers()->element().get());
|
|
it->setHtmlRefer(destdir.absoluteFilePath(QString("%1.html").arg(address_x)));
|
|
refers_refresh(it->elements(), destdir);
|
|
}
|
|
}
|