Skip to main content

The ftvhelp.cpp File Reference

Included Headers

#include <stdio.h> #include <stdlib.h> #include <algorithm> #include "ftvhelp.h" #include "config.h" #include "message.h" #include "doxygen.h" #include "language.h" #include "htmlgen.h" #include "layout.h" #include "pagedef.h" #include "docparser.h" #include "htmldocvisitor.h" #include "filedef.h" #include "classdef.h" #include "util.h" #include "resourcemgr.h" #include "portable.h" #include "outputlist.h" #include "threadpool.h"

Classes Index

structFTVNode
structPrivate
structNavIndexEntry
classNavIndexEntryList
structJSTreeFile

Typedefs Index

usingFTVNodePtr = std::shared_ptr< FTVNode >
usingFTVNodeWeakPtr = std::weak_ptr< FTVNode >
usingFTVNodes = std::vector< FTVNodePtr >
usingJSTreeFiles = std::vector< JSTreeFile >

Functions Index

static QCStringnode2URL (const FTVNodePtr &n, bool overruleFile=FALSE, bool srcLink=FALSE)
static QCStringgenerateIndentLabel (const FTVNodePtr &n, int level)
static voidgenerateIndent (TextStream &t, const FTVNodePtr &n, bool opened)
static voidgenerateBriefDoc (TextStream &t, const Definition *def)
static charcompoundIcon (const ClassDef *cd)
static QCStringpathToNode (const FTVNodePtr &leaf, const FTVNodePtr &n)
static booldupOfParent (const FTVNodePtr &n)
static voidgenerateJSLink (TextStream &t, const FTVNodePtr &n)
static QCStringconvertFileId2Var (const QCString &fileId)
static voidcollectJSTreeFiles (const FTVNodes &nl, JSTreeFiles &files)
static boolgenerateJSTree (NavIndexEntryList &navIndex, TextStream &t, const FTVNodes &nl, int level, bool &first)
static voidgenerateJSTreeFiles (NavIndexEntryList &navIndex, TextStream &t, const FTVNodes &nodeList)
static voidgenerateJSNavTree (const FTVNodes &nodeList)

Variables Index

static intfolderId =1
static std::mutexg_navIndexMutex

Typedefs

FTVNodePtr

using FTVNodePtr = std::shared_ptr<FTVNode>

Definition at line 47 of file ftvhelp.cpp.

47using FTVNodePtr = std::shared_ptr<FTVNode>;

FTVNodes

using FTVNodes = std::vector<FTVNodePtr>

Definition at line 49 of file ftvhelp.cpp.

49using FTVNodes = std::vector<FTVNodePtr>;

FTVNodeWeakPtr

using FTVNodeWeakPtr = std::weak_ptr<FTVNode>

Definition at line 48 of file ftvhelp.cpp.

48using FTVNodeWeakPtr = std::weak_ptr<FTVNode>;

JSTreeFiles

using JSTreeFiles = std::vector<JSTreeFile>

Definition at line 583 of file ftvhelp.cpp.

583using JSTreeFiles = std::vector<JSTreeFile>;

Functions

collectJSTreeFiles()

void collectJSTreeFiles (const FTVNodes & nl, JSTreeFiles & files)
static

Definition at line 585 of file ftvhelp.cpp.

585static void collectJSTreeFiles(const FTVNodes &nl,JSTreeFiles &files)
586{
587 QCString htmlOutput = Config_getString(HTML_OUTPUT);
588 for (const auto &n : nl)
589 {
590 if (n->separateIndex) // add new file if there are children
591 {
592 if (!n->children.empty())
593 {
594 QCString fileId = n->file;
595 files.emplace_back(fileId,n);
596 collectJSTreeFiles(n->children,files);
597 }
598 }
599 else // traverse without adding a new file
600 {
601 collectJSTreeFiles(n->children,files);
602 }
603 }
604}

References collectJSTreeFiles and Config_getString.

Referenced by collectJSTreeFiles and generateJSTreeFiles.

compoundIcon()

char compoundIcon (const ClassDef * cd)
static

Definition at line 352 of file ftvhelp.cpp.

352static char compoundIcon(const ClassDef *cd)
353{
354 char icon='C';
355 if (cd->getLanguage() == SrcLangExt::Slice)
356 {
358 {
359 icon='I';
360 }
361 else if (cd->compoundType()==ClassDef::Struct)
362 {
363 icon='S';
364 }
365 else if (cd->compoundType()==ClassDef::Exception)
366 {
367 icon='E';
368 }
369 }
370 return icon;
371}

References ClassDef::compoundType, ClassDef::Exception, Definition::getLanguage, ClassDef::Interface and ClassDef::Struct.

Referenced by FTVHelp::Private::generateTree.

convertFileId2Var()

QCString convertFileId2Var (const QCString & fileId)
static

Definition at line 567 of file ftvhelp.cpp.

567static QCString convertFileId2Var(const QCString &fileId)
568{
569 QCString varId = fileId;
570 int i=varId.findRev('/');
571 if (i>=0) varId = varId.mid(i+1);
572 return substitute(varId,"-","_");
573}

References QCString::findRev, QCString::mid and substitute.

Referenced by generateJSTreeFiles.

dupOfParent()

bool dupOfParent (const FTVNodePtr & n)
static

Definition at line 540 of file ftvhelp.cpp.

540static bool dupOfParent(const FTVNodePtr &n)
541{
542 auto parent = n->parent.lock();
543 if (!parent) return FALSE;
544 if (n->file==parent->file) return TRUE;
545 return FALSE;
546}

References FALSE, parent and TRUE.

Referenced by generateJSTree and generateJSTreeFiles.

generateBriefDoc()

void generateBriefDoc (TextStream & t, const Definition * def)
static

Definition at line 329 of file ftvhelp.cpp.

329static void generateBriefDoc(TextStream &t,const Definition *def)
330{
331 QCString brief = def->briefDescription(TRUE);
332 //printf("*** %p: generateBriefDoc(%s)='%s'\n",def,qPrint(def->name()),qPrint(brief));
333 if (!brief.isEmpty())
334 {
335 auto parser { createDocParser() };
336 auto ast { validatingParseDoc(*parser.get(),
337 def->briefFile(),def->briefLine(),
338 def,nullptr,brief,FALSE,FALSE,
339 QCString(),TRUE,TRUE) };
340 const DocNodeAST *astImpl = dynamic_cast<const DocNodeAST*>(ast.get());
341 if (astImpl)
342 {
344 OutputCodeList htmlList;
345 htmlList.add<HtmlCodeGenerator>(&t,relPath);
346 HtmlDocVisitor visitor(t,htmlList,def);
347 std::visit(visitor,astImpl->root);
348 }
349 }
350}

References OutputCodeList::add, Definition::briefDescription, Definition::briefFile, Definition::briefLine, createDocParser, FALSE, Definition::getOutputFileBase, QCString::isEmpty, relativePathToRoot, DocNodeAST::root, TRUE and validatingParseDoc.

Referenced by FTVHelp::Private::generateTree.

generateIndent()

void generateIndent (TextStream & t, const FTVNodePtr & n, bool opened)
static

Definition at line 260 of file ftvhelp.cpp.

260static void generateIndent(TextStream &t, const FTVNodePtr &n,bool opened)
261{
262 int indent=0;
263 auto parent = n->parent.lock();
264 while (parent) { indent++; parent=parent->parent.lock(); }
265 if (n->isDir)
266 {
267 const char *ARROW_DOWN = "<span class=\"arrowhead opened\"></span>";
268 const char *ARROW_RIGHT = "<span class=\"arrowhead closed\"></span>";
269 QCString dir = opened ? ARROW_DOWN : ARROW_RIGHT;
270 t << "<span style=\"width:" << (indent*16) << "px;display:inline-block;\">&#160;</span>"
271 << "<span id=\"arr_" << generateIndentLabel(n,0) << "\" class=\"arrow\" ";
272 t << "onclick=\"dynsection.toggleFolder('" << generateIndentLabel(n,0) << "')\"";
273 t << ">" << dir
274 << "</span>";
275 }
276 else
277 {
278 t << "<span style=\"width:" << ((indent+1)*16) << "px;display:inline-block;\">&#160;</span>";
279 }
280}

References generateIndentLabel and parent.

Referenced by FTVHelp::Private::generateTree.

generateIndentLabel()

QCString generateIndentLabel (const FTVNodePtr & n, int level)
static

Definition at line 248 of file ftvhelp.cpp.

248static QCString generateIndentLabel(const FTVNodePtr &n,int level)
249{
250 QCString result;
251 auto parent = n->parent.lock();
252 if (parent)
253 {
254 result=generateIndentLabel(parent,level+1);
255 }
256 result+=QCString().setNum(n->index)+"_";
257 return result;
258}

References generateIndentLabel, parent and QCString::setNum.

Referenced by generateIndent, generateIndentLabel and FTVHelp::Private::generateTree.

generateJSLink()

void generateJSLink (TextStream & t, const FTVNodePtr & n)
static

Definition at line 548 of file ftvhelp.cpp.

548static void generateJSLink(TextStream &t,const FTVNodePtr &n)
549{
550 bool nameAsHtml = !n->nameAsHtml.isEmpty();
551 QCString result = nameAsHtml ? n->nameAsHtml : n->name;
552 QCString link = convertToJSString(result,nameAsHtml);
553 if (n->file.isEmpty()) // no link
554 {
555 t << "\"" << link << "\", null, ";
556 }
557 else // link into other page
558 {
559 if (Config_getBool(HIDE_SCOPE_NAMES)) result=stripScope(result);
560 t << "\"" << link << "\", \"";
561 t << externalRef("",n->ref,TRUE);
562 t << node2URL(n);
563 t << "\", ";
564 }
565}

References Config_getBool, convertToJSString, externalRef, node2URL, stripScope and TRUE.

Referenced by generateJSTree.

generateJSNavTree()

void generateJSNavTree (const FTVNodes & nodeList)
static

Definition at line 740 of file ftvhelp.cpp.

740static void generateJSNavTree(const FTVNodes &nodeList)
741{
742 QCString htmlOutput = Config_getString(HTML_OUTPUT);
743 std::ofstream f = Portable::openOutputStream(htmlOutput+"/navtreedata.js");
744 NavIndexEntryList navIndex;
745 if (f.is_open())
746 {
747 TextStream t(&f);
748 //TextStream tidx(&fidx);
749 //tidx << "var NAVTREEINDEX =\n";
750 //tidx << "{\n";
752 t << "var NAVTREE =\n";
753 t << "[\n";
754 t << " [ ";
755 QCString projName = Config_getString(PROJECT_NAME);
756 if (projName.isEmpty())
757 {
758 if (mainPageHasTitle()) // Use title of main page as root
759 {
760 t << "\"" << convertToJSString(Doxygen::mainPage->title()) << "\", ";
761 }
762 else // Use default section title as root
763 {
764 LayoutNavEntry *lne = LayoutDocManager::instance().rootNavEntry()->find(LayoutNavEntry::MainPage);
765 t << "\"" << convertToJSString(lne->title()) << "\", ";
766 }
767 }
768 else // use PROJECT_NAME as root tree element
769 {
770 t << "\"" << convertToJSString(projName) << "\", ";
771 }
772 t << "\"index" << Doxygen::htmlFileExtension << "\", ";
773
774 // add special entry for index page
775 navIndex.emplace_back("index"+Doxygen::htmlFileExtension,"");
776 // related page index is written as a child of index.html, so add this as well
777 navIndex.emplace_back("pages"+Doxygen::htmlFileExtension,"");
778
779 bool first=TRUE;
780 generateJSTree(navIndex,t,nodeList,1,first);
781 generateJSTreeFiles(navIndex,t,nodeList);
782
783 if (first)
784 t << "]\n";
785 else
786 t << "\n ] ]\n";
787 t << "];\n\n";
788
789 // write the navigation index (and sub-indices)
790 std::stable_sort(navIndex.begin(),navIndex.end(),[](const auto &n1,const auto &n2)
791 { return !n1.url.isEmpty() && (n2.url.isEmpty() || (n1.url<n2.url)); });
792
793 int subIndex=0;
794 int elemCount=0;
795 const int maxElemCount=250;
796 std::ofstream tsidx = Portable::openOutputStream(htmlOutput+"/navtreeindex0.js");
797 if (tsidx.is_open())
798 {
799 t << "var NAVTREEINDEX =\n";
800 t << "[\n";
801 tsidx << "var NAVTREEINDEX" << subIndex << " =\n";
802 tsidx << "{\n";
803 first=TRUE;
804 auto it = navIndex.begin();
805 while (it!=navIndex.end())
806 {
807 const NavIndexEntry &e = *it;
808 if (elemCount==0)
809 {
810 if (!first)
811 {
812 t << ",\n";
813 }
814 else
815 {
816 first=FALSE;
817 }
818 t << "\"" << e.url << "\"";
819 }
820 tsidx << "\"" << e.url << "\":[" << e.path << "]";
821 ++it;
822 if (it!=navIndex.end() && elemCount<maxElemCount-1) tsidx << ","; // not last entry
823 tsidx << "\n";
824
825 elemCount++;
826 if (it!=navIndex.end() && elemCount>=maxElemCount) // switch to new sub-index
827 {
828 tsidx << "};\n";
829 elemCount=0;
830 tsidx.close();
831 subIndex++;
832 QCString fileName = htmlOutput+"/navtreeindex"+QCString().setNum(subIndex)+".js";
833 tsidx = Portable::openOutputStream(fileName);
834 if (!tsidx.is_open()) break;
835 tsidx << "var NAVTREEINDEX" << subIndex << " =\n";
836 tsidx << "{\n";
837 }
838 }
839 tsidx << "};\n";
840 t << "\n];\n";
841 }
842 t << "\nvar SYNCONMSG = '" << theTranslator->trPanelSynchronisationTooltip(FALSE) << "';";
843 t << "\nvar SYNCOFFMSG = '" << theTranslator->trPanelSynchronisationTooltip(TRUE) << "';";
844 t << "\nvar LISTOFALLMEMBERS = '" << theTranslator->trListOfAllMembers() << "';";
845 }
846
847 auto &mgr = ResourceMgr::instance();
848 {
849 std::ofstream fn = Portable::openOutputStream(htmlOutput+"/navtree.js");
850 if (fn.is_open())
851 {
852 TextStream t(&fn);
853 t << substitute(
854 substitute(mgr.getAsString("navtree.js"),
855 "$TREEVIEW_WIDTH", QCString().setNum(Config_getInt(TREEVIEW_WIDTH))),
856 "$PROJECTID",getProjectId());
857 }
858 }
859}

References Config_getInt, Config_getString, convertToJSString, FALSE, LayoutNavEntry::find, generateJSTree, generateJSTreeFiles, getProjectId, Doxygen::htmlFileExtension, LayoutDocManager::instance, ResourceMgr::instance, QCString::isEmpty, JAVASCRIPT_LICENSE_TEXT, Doxygen::mainPage, mainPageHasTitle, Portable::openOutputStream, NavIndexEntry::path, LayoutDocManager::rootNavEntry, QCString::setNum, substitute, theTranslator, LayoutNavEntry::title, TRUE and NavIndexEntry::url.

Referenced by FTVHelp::generateTreeViewScripts.

generateJSTree()

bool generateJSTree (NavIndexEntryList & navIndex, TextStream & t, const FTVNodes & nl, int level, bool & first)
static

Definition at line 608 of file ftvhelp.cpp.

609 const FTVNodes &nl,int level,bool &first)
610{
611 QCString htmlOutput = Config_getString(HTML_OUTPUT);
612 QCString indentStr;
613 indentStr.fill(' ',level*2);
614
615 bool found=FALSE;
616 for (const auto &n : nl)
617 {
618 // terminate previous entry
619 if (!first) t << ",\n";
620 first=FALSE;
621
622 // start entry
623 if (!found)
624 {
625 t << "[\n";
626 }
627 found=TRUE;
628
629 if (n->addToNavIndex) // add entry to the navigation index
630 {
631 std::lock_guard lock(g_navIndexMutex);
632 if (n->def && n->def->definitionType()==Definition::TypeFile)
633 {
634 const FileDef *fd = toFileDef(n->def);
635 bool src = false;
636 bool doc = fileVisibleInIndex(fd,src);
637 if (doc)
638 {
639 navIndex.emplace_back(node2URL(n,TRUE,FALSE),pathToNode(n,n));
640 }
641 if (src)
642 {
643 navIndex.emplace_back(node2URL(n,TRUE,TRUE),pathToNode(n,n));
644 }
645 }
646 else
647 {
648 navIndex.emplace_back(node2URL(n),pathToNode(n,n));
649 }
650 }
651
652 if (n->separateIndex) // store items in a separate file for dynamic loading
653 {
654 t << indentStr << " [ ";
655 generateJSLink(t,n);
656 if (!n->children.empty()) // write children to separate file for dynamic loading
657 {
658 QCString fileId = n->file;
659 if (!n->anchor.isEmpty())
660 {
661 fileId+="_"+n->anchor;
662 }
663 if (dupOfParent(n))
664 {
665 fileId+="_dup";
666 }
667 t << "\"" << fileId << "\" ]";
668 }
669 else // no children
670 {
671 t << "null ]";
672 }
673 }
674 else // show items in this file
675 {
676 bool firstChild=TRUE;
677 t << indentStr << " [ ";
678 generateJSLink(t,n);
679 bool emptySection = !generateJSTree(navIndex,t,n->children,level+1,firstChild);
680 if (emptySection)
681 t << "null ]";
682 else
683 t << "\n" << indentStr << " ] ]";
684 }
685 }
686 return found;
687}

References Config_getString, dupOfParent, FALSE, fileVisibleInIndex, QCString::fill, g_navIndexMutex, generateJSLink, generateJSTree, node2URL, pathToNode, toFileDef, TRUE and Definition::TypeFile.

Referenced by generateJSNavTree, generateJSTree and generateJSTreeFiles.

generateJSTreeFiles()

void generateJSTreeFiles (NavIndexEntryList & navIndex, TextStream & t, const FTVNodes & nodeList)
static

Definition at line 689 of file ftvhelp.cpp.

689static void generateJSTreeFiles(NavIndexEntryList &navIndex,TextStream &t,const FTVNodes &nodeList)
690{
691 QCString htmlOutput = Config_getString(HTML_OUTPUT);
692
693 auto getVarName = [](const FTVNodePtr n)
694 {
695 QCString fileId = n->file;
696 if (!n->anchor.isEmpty()) fileId+="_"+n->anchor;
697 if (dupOfParent(n)) fileId+="_dup";
698 return fileId;
699 };
700
701 auto generateJSFile = [&](const JSTreeFile &tf)
702 {
703 QCString fileId = getVarName(tf.node);
704 QCString fileName = htmlOutput+"/"+fileId+".js";
705 std::ofstream ff = Portable::openOutputStream(fileName);
706 if (ff.is_open())
707 {
708 bool firstChild = true;
709 TextStream tt(&ff);
710 tt << "var " << convertFileId2Var(fileId) << " =\n";
711 generateJSTree(navIndex,tt,tf.node->children,1,firstChild);
712 tt << "\n];";
713 }
714 };
715
716 JSTreeFiles jsTreeFiles;
717 collectJSTreeFiles(nodeList,jsTreeFiles);
718
719 std::size_t numThreads = static_cast<std::size_t>(Config_getInt(NUM_PROC_THREADS));
720 if (numThreads>1) // multi threaded version
721 {
722 ThreadPool threadPool(numThreads);
723 std::vector< std::future<void> > results;
724 for (const auto &tf : jsTreeFiles)
725 {
726 results.emplace_back(threadPool.queue([&](){ generateJSFile(tf); }));
727 }
728 // wait for the results
729 for (auto &f : results) f.get();
730 }
731 else // single threaded version
732 {
733 for (const auto &tf : jsTreeFiles)
734 {
735 generateJSFile(tf);
736 }
737 }
738}

References collectJSTreeFiles, Config_getInt, Config_getString, convertFileId2Var, dupOfParent, generateJSTree, Portable::openOutputStream and ThreadPool::queue.

Referenced by generateJSNavTree.

node2URL()

QCString node2URL (const FTVNodePtr & n, bool overruleFile=FALSE, bool srcLink=FALSE)
static

Definition at line 216 of file ftvhelp.cpp.

216static QCString node2URL(const FTVNodePtr &n,bool overruleFile=FALSE,bool srcLink=FALSE)
217{
218 QCString url = n->file;
219 if (!url.isEmpty() && url.at(0)=='!') // relative URL
220 {
221 // remove leading !
222 url = url.mid(1);
223 }
224 else if (!url.isEmpty() && url.at(0)=='^') // absolute URL
225 {
226 // skip, keep ^ in the output
227 }
228 else // local file (with optional anchor)
229 {
230 if (overruleFile && n->def && n->def->definitionType()==Definition::TypeFile)
231 {
232 const FileDef *fd = toFileDef(n->def);
233 if (srcLink)
234 {
235 url = fd->getSourceFileBase();
236 }
237 else
238 {
239 url = fd->getOutputFileBase();
240 }
241 }
243 if (!n->anchor.isEmpty()) url+="#"+n->anchor;
244 }
245 return url;
246}

References addHtmlExtensionIfMissing, QCString::at, FALSE, Definition::getOutputFileBase, Definition::getSourceFileBase, QCString::isEmpty, QCString::mid, toFileDef and Definition::TypeFile.

Referenced by generateJSLink, generateJSTree and FTVHelp::Private::generateLink.

pathToNode()

QCString pathToNode (const FTVNodePtr & leaf, const FTVNodePtr & n)
static

Definition at line 527 of file ftvhelp.cpp.

527static QCString pathToNode(const FTVNodePtr &leaf,const FTVNodePtr &n)
528{
529 QCString result;
530 auto parent = n->parent.lock();
531 if (parent)
532 {
533 result+=pathToNode(leaf,parent);
534 }
535 result+=QCString().setNum(n->index);
536 if (leaf!=n) result+=",";
537 return result;
538}

References parent, pathToNode and QCString::setNum.

Referenced by generateJSTree and pathToNode.

Variables

folderId

int folderId =1
static

Definition at line 43 of file ftvhelp.cpp.

43static int folderId=1;

Referenced by FTVHelp::Private::generateTree.

g_navIndexMutex

std::mutex g_navIndexMutex
static

Definition at line 606 of file ftvhelp.cpp.

606static std::mutex g_navIndexMutex;

Referenced by generateJSTree.


Generated via doxygen2docusaurus by Doxygen 1.14.0.