61 lines
2.0 KiB
C++
61 lines
2.0 KiB
C++
|
#include "htmlprint.h"
|
||
|
|
||
|
using namespace example_novel;
|
||
|
|
||
|
void HtmlPrint::fragment_summary(std::shared_ptr<const ast_gen::ElementAccess> root, const QDir& frag_outs)
|
||
|
{
|
||
|
std::function<QList<std::shared_ptr<const ast_gen::ElementAccess>>(std::shared_ptr<const ast_gen::ElementAccess>)> peak_story =
|
||
|
[&](std::shared_ptr<const ast_gen::ElementAccess> pnode) -> QList<std::shared_ptr<const ast_gen::ElementAccess>> {
|
||
|
QList<std::shared_ptr<const ast_gen::ElementAccess>> listret;
|
||
|
|
||
|
if (pnode->element()->typeMark() == (int)example_novel::NovelNode::StoryDefine)
|
||
|
listret << pnode;
|
||
|
|
||
|
for (auto& vit : pnode->children())
|
||
|
listret.append(peak_story(vit));
|
||
|
|
||
|
return listret;
|
||
|
};
|
||
|
|
||
|
auto stories = peak_story(root);
|
||
|
std::sort(std::begin(stories), std::end(stories),
|
||
|
[](std::shared_ptr<const ast_gen::ElementAccess> itema, std::shared_ptr<const ast_gen::ElementAccess> itemb) -> bool {
|
||
|
auto storya = std::dynamic_pointer_cast<const example_novel::StoryDefine>(itema->element());
|
||
|
auto storyb = std::dynamic_pointer_cast<const example_novel::StoryDefine>(itemb->element());
|
||
|
return storya->sort() < storyb->sort();
|
||
|
});
|
||
|
|
||
|
for (auto& sit : stories) {
|
||
|
auto story_sort = std::make_shared<StorySortHelper>(sit);
|
||
|
const_cast<HtmlPrint*>(this)->stories_list << story_sort;
|
||
|
|
||
|
auto children = sit->children();
|
||
|
std::shared_ptr<FragmentSortHelper> temp_ptr = nullptr;
|
||
|
for (auto& nf : children) {
|
||
|
switch ((example_novel::NovelNode)nf->element()->typeMark()) {
|
||
|
case example_novel::NovelNode::FragmentDefine:
|
||
|
case example_novel::NovelNode::FragmentRefer: {
|
||
|
auto frag_sort = std::make_shared<FragmentSortHelper>(nf, story_sort->sortValue());
|
||
|
if (!temp_ptr) {
|
||
|
story_sort->attachFragmentSort(frag_sort);
|
||
|
}
|
||
|
else {
|
||
|
temp_ptr->attachNext(frag_sort);
|
||
|
}
|
||
|
temp_ptr = frag_sort;
|
||
|
} break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const_cast<HtmlPrint*>(this)->elements_link_build(this->stories_list);
|
||
|
}
|
||
|
|
||
|
void HtmlPrint::htmlOutput(std::shared_ptr<const ast_gen::ElementAccess> root, const QDir& out_directory) const
|
||
|
{
|
||
|
|
||
|
|
||
|
}
|