Doxygen
Loading...
Searching...
No Matches
searchindex_js.cpp File Reference
#include "searchindex_js.h"
#include <algorithm>
#include <utility>
#include "classdef.h"
#include "classlist.h"
#include "conceptdef.h"
#include "docparser.h"
#include "doxygen.h"
#include "filename.h"
#include "groupdef.h"
#include "indexlist.h"
#include "language.h"
#include "membername.h"
#include "message.h"
#include "moduledef.h"
#include "namespacedef.h"
#include "pagedef.h"
#include "portable.h"
#include "resourcemgr.h"
#include "section.h"
#include "textstream.h"
#include "threadpool.h"
#include "util.h"
Include dependency graph for searchindex_js.cpp:

Go to the source code of this file.

Macros

#define SEARCH_INDEX_ALL   0
#define SEARCH_INDEX_CLASSES   1
#define SEARCH_INDEX_INTERFACES   2
#define SEARCH_INDEX_STRUCTS   3
#define SEARCH_INDEX_EXCEPTIONS   4
#define SEARCH_INDEX_NAMESPACES   5
#define SEARCH_INDEX_FILES   6
#define SEARCH_INDEX_FUNCTIONS   7
#define SEARCH_INDEX_VARIABLES   8
#define SEARCH_INDEX_TYPEDEFS   9
#define SEARCH_INDEX_SEQUENCES   10
#define SEARCH_INDEX_DICTIONARIES   11
#define SEARCH_INDEX_ENUMS   12
#define SEARCH_INDEX_ENUMVALUES   13
#define SEARCH_INDEX_PROPERTIES   14
#define SEARCH_INDEX_EVENTS   15
#define SEARCH_INDEX_RELATED   16
#define SEARCH_INDEX_DEFINES   17
#define SEARCH_INDEX_GROUPS   18
#define SEARCH_INDEX_PAGES   19
#define SEARCH_INDEX_CONCEPTS   20
#define SEARCH_INDEX_MODULES   21
#define SEARCH_INDEX_RECORDS   22

Functions

static void splitSearchTokens (DString &title, SizeVector &indices)
static void addMemberToSearchIndex (const MemberDef *md)
void createJavaScriptSearchIndex ()
static void writeJavascriptSearchData (const DString &searchDirName)
static void writeJavasScriptSearchDataPage (const DString &baseName, const DString &dataFileName, const SearchIndexList &list)
void writeJavaScriptSearchIndex ()
const std::array< SearchIndexInfo, NUM_SEARCH_INDICES > & getSearchIndices ()

Variables

static std::array< SearchIndexInfo, NUM_SEARCH_INDICES > g_searchIndexInfo

Macro Definition Documentation

◆ SEARCH_INDEX_ALL

#define SEARCH_INDEX_ALL   0

Definition at line 162 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex(), and createJavaScriptSearchIndex().

◆ SEARCH_INDEX_CLASSES

#define SEARCH_INDEX_CLASSES   1

Definition at line 163 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_CONCEPTS

#define SEARCH_INDEX_CONCEPTS   20

Definition at line 182 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_DEFINES

#define SEARCH_INDEX_DEFINES   17

Definition at line 179 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_DICTIONARIES

#define SEARCH_INDEX_DICTIONARIES   11

Definition at line 173 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_ENUMS

#define SEARCH_INDEX_ENUMS   12

Definition at line 174 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_ENUMVALUES

#define SEARCH_INDEX_ENUMVALUES   13

Definition at line 175 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_EVENTS

#define SEARCH_INDEX_EVENTS   15

Definition at line 177 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_EXCEPTIONS

#define SEARCH_INDEX_EXCEPTIONS   4

Definition at line 166 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_FILES

#define SEARCH_INDEX_FILES   6

Definition at line 168 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_FUNCTIONS

#define SEARCH_INDEX_FUNCTIONS   7

Definition at line 169 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_GROUPS

#define SEARCH_INDEX_GROUPS   18

Definition at line 180 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_INTERFACES

#define SEARCH_INDEX_INTERFACES   2

Definition at line 164 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_MODULES

#define SEARCH_INDEX_MODULES   21

Definition at line 183 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_NAMESPACES

#define SEARCH_INDEX_NAMESPACES   5

Definition at line 167 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_PAGES

#define SEARCH_INDEX_PAGES   19

Definition at line 181 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_PROPERTIES

#define SEARCH_INDEX_PROPERTIES   14

Definition at line 176 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_RECORDS

#define SEARCH_INDEX_RECORDS   22

Definition at line 184 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_RELATED

#define SEARCH_INDEX_RELATED   16

Definition at line 178 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_SEQUENCES

#define SEARCH_INDEX_SEQUENCES   10

Definition at line 172 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_STRUCTS

#define SEARCH_INDEX_STRUCTS   3

Definition at line 165 of file searchindex_js.cpp.

Referenced by createJavaScriptSearchIndex().

◆ SEARCH_INDEX_TYPEDEFS

#define SEARCH_INDEX_TYPEDEFS   9

Definition at line 171 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

◆ SEARCH_INDEX_VARIABLES

#define SEARCH_INDEX_VARIABLES   8

Definition at line 170 of file searchindex_js.cpp.

Referenced by addMemberToSearchIndex().

Function Documentation

◆ addMemberToSearchIndex()

void addMemberToSearchIndex ( const MemberDef * md)
static

Definition at line 220 of file searchindex_js.cpp.

221{
222 bool hideFriendCompounds = Config_getBool(HIDE_FRIEND_COMPOUNDS);
223 bool isLinkable = md->isLinkable();
224 const ClassDef *cd=nullptr;
225 const NamespaceDef *nd=nullptr;
226 const FileDef *fd=nullptr;
227 const GroupDef *gd=nullptr;
228 if (isLinkable &&
229 (
230 ((cd=md->getClassDef()) && cd->isLinkable() && !cd->isImplicitTemplateInstance()) ||
231 ((gd=md->getGroupDef()) && gd->isLinkable())
232 )
233 )
234 {
235 const DString &n = md->name();
236 if (!n.empty())
237 {
238 bool isFriendToHide = hideFriendCompounds && isTypeAClassFriend(md->typeString());
239 if (!(md->isFriend() && isFriendToHide))
240 {
242 }
243 if (md->isFunction() || md->isSlot() || md->isSignal())
244 {
246 }
247 else if (md->isVariable())
248 {
250 }
251 else if (md->isSequence())
252 {
254 }
255 else if (md->isDictionary())
256 {
258 }
259 else if (md->isTypedef())
260 {
262 }
263 else if (md->isEnumerate())
264 {
266 }
267 else if (md->isEnumValue())
268 {
270 }
271 else if (md->isProperty())
272 {
274 }
275 else if (md->isEvent())
276 {
278 }
279 else if (md->isRelated() || md->isForeign() ||
280 (md->isFriend() && !isFriendToHide))
281 {
283 }
284 }
285 }
286 else if (isLinkable &&
287 (((nd=md->getNamespaceDef()) && nd->isLinkable()) ||
288 ((fd=md->getFileDef()) && fd->isLinkable())
289 )
290 )
291 {
292 const DString &n = md->name();
293 if (!n.empty())
294 {
296
297 if (md->isFunction())
298 {
300 }
301 else if (md->isVariable())
302 {
304 }
305 else if (md->isSequence())
306 {
308 }
309 else if (md->isDictionary())
310 {
312 }
313 else if (md->isTypedef())
314 {
316 }
317 else if (md->isEnumerate())
318 {
320 }
321 else if (md->isEnumValue())
322 {
324 }
325 else if (md->isDefine())
326 {
328 }
329 }
330 }
331}
A abstract class representing of a compound symbol.
Definition classdef.h:100
virtual bool isImplicitTemplateInstance() const =0
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
virtual bool isLinkable() const =0
virtual const DString & name() const =0
A model of a file symbol.
Definition filedef.h:97
A model of a group of symbols.
Definition groupdef.h:48
virtual bool isSignal() const =0
virtual bool isFriend() const =0
virtual bool isForeign() const =0
virtual bool isRelated() const =0
virtual bool isSequence() const =0
virtual const ClassDef * getClassDef() const =0
virtual GroupDef * getGroupDef()=0
virtual bool isTypedef() const =0
virtual bool isSlot() const =0
virtual const FileDef * getFileDef() const =0
virtual bool isEvent() const =0
virtual bool isFunction() const =0
virtual bool isDictionary() const =0
virtual bool isDefine() const =0
virtual const NamespaceDef * getNamespaceDef() const =0
virtual bool isEnumerate() const =0
virtual bool isVariable() const =0
virtual DString typeString() const =0
virtual bool isEnumValue() const =0
virtual bool isProperty() const =0
An abstract interface of a namespace symbol.
#define Config_getBool(name)
Definition config.h:33
#define SEARCH_INDEX_TYPEDEFS
#define SEARCH_INDEX_EVENTS
static std::array< SearchIndexInfo, NUM_SEARCH_INDICES > g_searchIndexInfo
#define SEARCH_INDEX_DEFINES
#define SEARCH_INDEX_ENUMS
#define SEARCH_INDEX_DICTIONARIES
#define SEARCH_INDEX_ALL
#define SEARCH_INDEX_SEQUENCES
#define SEARCH_INDEX_PROPERTIES
#define SEARCH_INDEX_ENUMVALUES
#define SEARCH_INDEX_FUNCTIONS
#define SEARCH_INDEX_VARIABLES
#define SEARCH_INDEX_RELATED
Searchable term.
bool isTypeAClassFriend(const DString &type)
Definition types.h:924

References Config_getBool, DString::empty(), g_searchIndexInfo, MemberDef::getClassDef(), MemberDef::getFileDef(), MemberDef::getGroupDef(), MemberDef::getNamespaceDef(), MemberDef::isDefine(), MemberDef::isDictionary(), MemberDef::isEnumerate(), MemberDef::isEnumValue(), MemberDef::isEvent(), MemberDef::isForeign(), MemberDef::isFriend(), MemberDef::isFunction(), ClassDef::isImplicitTemplateInstance(), Definition::isLinkable(), MemberDef::isProperty(), MemberDef::isRelated(), MemberDef::isSequence(), MemberDef::isSignal(), MemberDef::isSlot(), isTypeAClassFriend(), MemberDef::isTypedef(), MemberDef::isVariable(), Definition::name(), SEARCH_INDEX_ALL, SEARCH_INDEX_DEFINES, SEARCH_INDEX_DICTIONARIES, SEARCH_INDEX_ENUMS, SEARCH_INDEX_ENUMVALUES, SEARCH_INDEX_EVENTS, SEARCH_INDEX_FUNCTIONS, SEARCH_INDEX_PROPERTIES, SEARCH_INDEX_RELATED, SEARCH_INDEX_SEQUENCES, SEARCH_INDEX_TYPEDEFS, SEARCH_INDEX_VARIABLES, and MemberDef::typeString().

Referenced by createJavaScriptSearchIndex().

◆ createJavaScriptSearchIndex()

void createJavaScriptSearchIndex ( )

Definition at line 335 of file searchindex_js.cpp.

336{
337 // index classes
338 for (const auto &cd : *Doxygen::classLinkedMap)
339 {
340 if (cd->isLinkable())
341 {
342 DString n = cd->localName();
344 if (Config_getBool(OPTIMIZE_OUTPUT_SLICE))
345 {
346 if (cd->compoundType()==ClassDef::Interface)
347 {
349 }
350 else if (cd->compoundType()==ClassDef::Struct)
351 {
353 }
354 else if (cd->compoundType()==ClassDef::Record)
355 {
357 }
358 else if (cd->compoundType()==ClassDef::Exception)
359 {
361 }
362 else // cd->compoundType()==ClassDef::Class
363 {
365 }
366 }
367 else // non slice optimization: group all types under classes
368 {
370 }
371 }
372 }
373
374 // index namespaces
375 for (const auto &nd : *Doxygen::namespaceLinkedMap)
376 {
377 if (nd->isLinkable())
378 {
379 DString n = nd->name();
382 }
383 }
384
385 // index concepts
386 for (const auto &cd : *Doxygen::conceptLinkedMap)
387 {
388 if (cd->isLinkable())
389 {
390 DString n = cd->localName();
393 }
394 }
395
396 // index modules
397 for (const auto &mod : ModuleManager::instance().modules())
398 {
399 if (mod->isLinkable() && mod->isPrimaryInterface())
400 {
401 DString n = mod->name();
404 }
405 }
406
407 // index files
408 for (const auto &fn : *Doxygen::inputNameLinkedMap)
409 {
410 for (const auto &fd : *fn)
411 {
412 DString n = fd->name();
413 if (fd->isLinkable())
414 {
417 }
418 }
419 }
420
421 // index class members
422 {
423 // for each member name
424 for (const auto &mn : *Doxygen::memberNameLinkedMap)
425 {
426 // for each member definition
427 for (const auto &md : *mn)
428 {
429 addMemberToSearchIndex(md.get());
430 }
431 }
432 }
433
434 // index file/namespace members
435 {
436 // for each member name
437 for (const auto &mn : *Doxygen::functionNameLinkedMap)
438 {
439 // for each member definition
440 for (const auto &md : *mn)
441 {
442 addMemberToSearchIndex(md.get());
443 }
444 }
445 }
446
447 // index groups
448 for (const auto &gd : *Doxygen::groupLinkedMap)
449 {
450 if (gd->isLinkable())
451 {
452 DString title(filterTitle(gd->groupTitle()).str());
453 SizeVector tokenIndices;
454 splitSearchTokens(title,tokenIndices);
455 for (size_t index : tokenIndices)
456 {
457 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),gd.get()));
458 g_searchIndexInfo[SEARCH_INDEX_GROUPS].add(SearchTerm(title.mid(index),gd.get()));
459 }
460 }
461 }
462
463 // index pages
464 for (const auto &pd : *Doxygen::pageLinkedMap)
465 {
466 if (pd->isLinkable())
467 {
468 DString title(filterTitle(pd->title()).str());
469 SizeVector tokenIndices;
470 splitSearchTokens(title,tokenIndices);
471 for (size_t index : tokenIndices)
472 {
473 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),pd.get()));
474 g_searchIndexInfo[SEARCH_INDEX_PAGES].add(SearchTerm(title.mid(index),pd.get()));
475 }
476 }
477 }
478
479 // main page
481 {
482 DString title(filterTitle(Doxygen::mainPage->title()).str());
483 SizeVector tokenIndices;
484 splitSearchTokens(title,tokenIndices);
485 for (size_t index : tokenIndices)
486 {
489 }
490 }
491
492 // sections
493 const auto &sm = SectionManager::instance();
494 for (const auto &sectionInfo : sm)
495 {
496 if (sectionInfo->level()>0) // level 0 is for page titles
497 {
498 DString title = filterTitle(sectionInfo->title());
499 SizeVector tokenIndices;
500 splitSearchTokens(title,tokenIndices);
501 //printf("split(%s)=(%s) %zu\n",qPrint(sectionInfo->title()),qPrint(title),tokenIndices.size());
502 for (size_t index : tokenIndices)
503 {
504 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),sectionInfo.get()));
505 g_searchIndexInfo[SEARCH_INDEX_PAGES].add(SearchTerm(title.mid(index),sectionInfo.get()));
506 }
507 }
508 }
509
510 // sort all lists
511 for (auto &sii : g_searchIndexInfo) // for each index
512 {
513 for (auto &[name,symList] : sii.symbolMap) // for each symbol in the index
514 {
515 // sort the symbols (first on search term, and then on full name)
516 //
517 // `std::stable_sort` is used here due to reproducibility issues
518 // on key collisions
519 // https://github.com/doxygen/doxygen/issues/10445
520 std::stable_sort(symList.begin(),
521 symList.end(),
522 [](const auto &t1,const auto &t2)
523 {
524 int eq = dstricmp_sort(t1.word,t2.word); // search term first
525 return eq==0 ? dstricmp_sort(t1.title,t2.title)<0 : eq<0; // then full title
526 });
527 }
528 }
529}
@ Interface
Definition classdef.h:109
@ Exception
Definition classdef.h:112
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:318
const std::string & str() const
Definition dstring.h:645
static NamespaceLinkedMap * namespaceLinkedMap
Definition doxygen.h:108
static ConceptLinkedMap * conceptLinkedMap
Definition doxygen.h:90
static std::unique_ptr< PageDef > mainPage
Definition doxygen.h:93
static FileNameLinkedMap * inputNameLinkedMap
Definition doxygen.h:97
static ClassLinkedMap * classLinkedMap
Definition doxygen.h:88
static MemberNameLinkedMap * functionNameLinkedMap
Definition doxygen.h:105
static PageLinkedMap * pageLinkedMap
Definition doxygen.h:92
static MemberNameLinkedMap * memberNameLinkedMap
Definition doxygen.h:104
static GroupLinkedMap * groupLinkedMap
Definition doxygen.h:107
static ModuleManager & instance()
static SectionManager & instance()
returns a reference to the singleton
Definition section.h:179
std::vector< size_t > SizeVector
Definition containers.h:39
static void addMemberToSearchIndex(const MemberDef *md)
#define SEARCH_INDEX_STRUCTS
#define SEARCH_INDEX_NAMESPACES
#define SEARCH_INDEX_CONCEPTS
#define SEARCH_INDEX_FILES
#define SEARCH_INDEX_PAGES
#define SEARCH_INDEX_RECORDS
#define SEARCH_INDEX_GROUPS
#define SEARCH_INDEX_INTERFACES
static void splitSearchTokens(DString &title, SizeVector &indices)
#define SEARCH_INDEX_MODULES
#define SEARCH_INDEX_CLASSES
#define SEARCH_INDEX_EXCEPTIONS
DString filterTitle(const DString &title)
Definition util.cpp:4590

References addMemberToSearchIndex(), Doxygen::classLinkedMap, Doxygen::conceptLinkedMap, Config_getBool, ClassDef::Exception, filterTitle(), Doxygen::functionNameLinkedMap, g_searchIndexInfo, Doxygen::groupLinkedMap, Doxygen::inputNameLinkedMap, ModuleManager::instance(), SectionManager::instance(), ClassDef::Interface, Doxygen::mainPage, Doxygen::memberNameLinkedMap, DString::mid(), Doxygen::namespaceLinkedMap, Doxygen::pageLinkedMap, ClassDef::Record, SEARCH_INDEX_ALL, SEARCH_INDEX_CLASSES, SEARCH_INDEX_CONCEPTS, SEARCH_INDEX_EXCEPTIONS, SEARCH_INDEX_FILES, SEARCH_INDEX_GROUPS, SEARCH_INDEX_INTERFACES, SEARCH_INDEX_MODULES, SEARCH_INDEX_NAMESPACES, SEARCH_INDEX_PAGES, SEARCH_INDEX_RECORDS, SEARCH_INDEX_STRUCTS, splitSearchTokens(), DString::str(), and ClassDef::Struct.

Referenced by generateOutput().

◆ getSearchIndices()

const std::array< SearchIndexInfo, NUM_SEARCH_INDICES > & getSearchIndices ( )

Definition at line 875 of file searchindex_js.cpp.

876{
877 return g_searchIndexInfo;
878}

References g_searchIndexInfo.

◆ splitSearchTokens()

void splitSearchTokens ( DString & title,
SizeVector & indices )
static

helper function to simplify the given title string, and fill a list of start positions for the start of each word in the simplified title string.

Definition at line 94 of file searchindex_js.cpp.

95{
96 if (title.empty()) return;
97
98 // simplify title to contain only words with single space as separator
99 size_t di=0;
100 bool lastIsSpace=true;
101 for (size_t si=0; si<title.length(); si++)
102 {
103 char c = title.at(si);
104 if (c=='@' || c=='\\') // skip over special commands
105 {
106 title.at(di)=' ';
107 if (si<title.length()-1)
108 {
109 c = title.at(++si);
110 while (si<title.length() && (isId(c) || c==':')) c = title.at(++si);
111 --si;
112 }
113 }
114 else if (c=='<') // skip over html tags
115 {
116 if (si<title.length()-1)
117 {
118 for (size_t tsi = si; tsi<title.length(); ++tsi)
119 {
120 if (title.at(tsi)=='>')
121 {
122 si=tsi;
123 break;
124 }
125 }
126 }
127 }
128 else if (isId(c) || c==':') // add "word" character
129 {
130 title.at(di)=c;
131 di++;
132 lastIsSpace=false;
133 }
134 else if (!lastIsSpace) // add one separator as space
135 {
136 title.at(di)=' ';
137 di++;
138 lastIsSpace=true;
139 }
140 }
141 if (di>0 && title.at(di-1)==' ') di--; // strip trailing whitespace
142 title.resize(di);
143
144 // create a list of start positions within title for
145 // each unique word in order of appearance
146 size_t p=0,i=0;
147 while ((i=title.find(' ',p))!=DString::npos)
148 {
149 std::string word = title.mid(p,i-p).str();
150 indices.push_back(p);
151 p = i+1;
152 }
153 if (p<title.length())
154 {
155 std::string word = title.mid(p).str();
156 indices.push_back(p);
157 }
158}
void resize(size_t newlen)
Definition dstring.h:209
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
Definition dstring.h:178
char & at(size_t i)
Returns a reference to the character at index i.
Definition dstring.h:686
size_t find(char c, size_t pos=0) const
Definition dstring.h:239
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:151
bool isId(char c)
Returns true if c is a valid character for an identifier.
Definition dstring.h:895

References DString::at(), DString::empty(), DString::find(), isId(), DString::length(), DString::mid(), DString::npos, DString::resize(), and DString::str().

Referenced by createJavaScriptSearchIndex().

◆ writeJavascriptSearchData()

void writeJavascriptSearchData ( const DString & searchDirName)
static

Definition at line 531 of file searchindex_js.cpp.

532{
533 std::ofstream t = Portable::openOutputStream(searchDirName+"/searchdata.js");
534 if (t.is_open())
535 {
536 t << "var indexSectionsWithContent =\n";
537 t << "{\n";
538 int j=0;
539 for (const auto &sii : g_searchIndexInfo)
540 {
541 if (!sii.symbolMap.empty())
542 {
543 if (j>0) t << ",\n";
544 t << " " << j << ": \"";
545
546 std::string previous_letter; // start with value that does not exist in the map
547 for (const auto &[letter,list] : sii.symbolMap)
548 {
549 if (letter != previous_letter)
550 {
551 if ( letter == "\"" ) t << "\\"; // add escape for backslash
552 t << letter;
553 previous_letter = letter;
554 }
555 }
556 t << "\"";
557 j++;
558 }
559 }
560 if (j>0) t << "\n";
561 t << "};\n\n";
562 t << "var indexSectionNames =\n";
563 t << "{\n";
564 j=0;
565 for (const auto &sii : g_searchIndexInfo)
566 {
567 if (!sii.symbolMap.empty())
568 {
569 if (j>0) t << ",\n";
570 t << " " << j << ": \"" << convertToJSString(sii.name,true,false) << "\"";
571 j++;
572 }
573 }
574 if (j>0) t << "\n";
575 t << "};\n\n";
576 t << "var indexSectionLabels =\n";
577 t << "{\n";
578 j=0;
579 for (const auto &sii : g_searchIndexInfo)
580 {
581 if (!sii.symbolMap.empty())
582 {
583 if (j>0) t << ",\n";
584 t << " " << j << ": \"" << convertToJSString(convertToXML(sii.getText()),true,false) << "\"";
585 j++;
586 }
587 }
588 if (j>0) t << "\n";
589 t << "};\n\n";
590 }
591}
std::ofstream openOutputStream(const DString &name, bool append=false)
Definition portable.cpp:679
DString convertToJSString(const DString &s, bool keepEntities, bool singleQuotes)
Definition util.cpp:3483
DString convertToXML(const DString &s, bool keepEntities, const bool citeEntry)
Definition util.cpp:3364

References convertToJSString(), convertToXML(), g_searchIndexInfo, and Portable::openOutputStream().

Referenced by writeJavaScriptSearchIndex().

◆ writeJavaScriptSearchIndex()

void writeJavaScriptSearchIndex ( )

Definition at line 804 of file searchindex_js.cpp.

805{
806 // write index files
807 DString searchDirName = Config_getString(HTML_OUTPUT)+"/search";
808
809 std::size_t numThreads = static_cast<std::size_t>(Config_getInt(NUM_PROC_THREADS));
810 if (numThreads>1) // multi threaded version
811 {
812 ThreadPool threadPool(numThreads);
813 std::vector< std::future<int> > results;
814 for (auto &sii : g_searchIndexInfo)
815 {
816 int p=0;
817 for (const auto &[letter,symList] : sii.symbolMap)
818 {
819 DString baseName;
820 baseName.sprintf("%s_%x",sii.name.data(),p);
821 DString dataFileName = searchDirName + "/"+baseName+".js";
822 auto &list = symList;
823 auto processFile = [p,baseName,dataFileName,&list]()
824 {
825 writeJavasScriptSearchDataPage(baseName,dataFileName,list);
826 return p;
827 };
828 results.emplace_back(threadPool.queue(processFile));
829 p++;
830 }
831 }
832 // wait for the results
833 for (auto &f : results) f.get();
834 }
835 else // single threaded version
836 {
837 for (auto &sii : g_searchIndexInfo)
838 {
839 int p=0;
840 for (const auto &[letter,symList] : sii.symbolMap)
841 {
842 DString baseName;
843 baseName.sprintf("%s_%x",sii.name.data(),p);
844 DString dataFileName = searchDirName + "/"+baseName+".js";
845 writeJavasScriptSearchDataPage(baseName,dataFileName,symList);
846 p++;
847 }
848 }
849 }
850
851 writeJavascriptSearchData(searchDirName);
852 auto &mgr = ResourceMgr::instance();
853 {
854 std::ofstream fn = Portable::openOutputStream(searchDirName+"/search.js");
855 if (fn.is_open())
856 {
857 TextStream t(&fn);
858 t << substitute(mgr.getAsString("search.js"),"$PROJECTID",getProjectId());
859 }
860 }
861
862 Doxygen::indexList->addStyleSheetFile("search/searchdata.js");
863 Doxygen::indexList->addStyleSheetFile("search/search.js");
864}
DString & sprintf(const char *format,...)
Definition dstring.cpp:34
static IndexList * indexList
Definition doxygen.h:125
void addStyleSheetFile(const DString &name)
Definition indexlist.h:127
static ResourceMgr & instance()
Returns the one and only instance of this class.
Text streaming class that buffers data.
Definition textstream.h:36
Class managing a pool of worker threads.
Definition threadpool.h:48
#define Config_getInt(name)
Definition config.h:34
#define Config_getString(name)
Definition config.h:32
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
Definition dstring.cpp:485
static void writeJavascriptSearchData(const DString &searchDirName)
static void writeJavasScriptSearchDataPage(const DString &baseName, const DString &dataFileName, const SearchIndexList &list)
DString getProjectId()
Definition util.cpp:5427

References IndexList::addStyleSheetFile(), Config_getInt, Config_getString, g_searchIndexInfo, getProjectId(), Doxygen::indexList, ResourceMgr::instance(), Portable::openOutputStream(), ThreadPool::queue(), DString::sprintf(), substitute(), writeJavascriptSearchData(), and writeJavasScriptSearchDataPage().

Referenced by generateOutput().

◆ writeJavasScriptSearchDataPage()

void writeJavasScriptSearchDataPage ( const DString & baseName,
const DString & dataFileName,
const SearchIndexList & list )
static

Definition at line 593 of file searchindex_js.cpp.

594{
595 auto isDef = [](const SearchTerm::LinkInfo &info)
596 {
597 return std::holds_alternative<const Definition *>(info);
598 };
599 auto getDef = [&isDef](const SearchTerm::LinkInfo &info)
600 {
601 return isDef(info) ? std::get<const Definition *>(info) : nullptr;
602 };
603 auto isSection = [](const SearchTerm::LinkInfo &info)
604 {
605 return std::holds_alternative<const SectionInfo *>(info);
606 };
607 auto getSection = [&isSection](const SearchTerm::LinkInfo &info)
608 {
609 return isSection(info) ? std::get<const SectionInfo *>(info) : nullptr;
610 };
611
612 int cnt = 0;
613 std::ofstream ti = Portable::openOutputStream(dataFileName);
614 if (!ti.is_open())
615 {
616 err("Failed to open file '{}' for writing...\n",dataFileName);
617 return;
618 }
619
620 ti << "var searchData=\n";
621 // format
622 // searchData[] = array of items
623 // searchData[x][0] = id
624 // searchData[x][1] = [ name + child1 + child2 + .. ]
625 // searchData[x][1][0] = name as shown
626 // searchData[x][1][y+1] = info for child y
627 // searchData[x][1][y+1][0] = url
628 // searchData[x][1][y+1][1] = 1 => target="_parent"
629 // searchData[x][1][y+1][1] = 0 => target="_blank"
630 // searchData[x][1][y+1][2] = scope
631
632 ti << "[\n";
633 bool firstEntry=true;
634
635 int childCount=0;
636 DString lastWord;
637 const Definition *prevScope = nullptr;
638 for (auto it = list.begin(); it!=list.end();)
639 {
640 const SearchTerm &term = *it;
641 const SearchTerm::LinkInfo info = term.info;
642 const Definition *d = getDef(info);
643 const SectionInfo *si = getSection(info);
644 ASSERT(d || si); // either d or si should be valid
645 DString word = term.word;
646 DString id = term.termEncoded();
647 ++it;
648 const Definition *scope = d ? d->getOuterScope() : nullptr;
649 const SearchTerm::LinkInfo next = it!=list.end() ? it->info : SearchTerm::LinkInfo();
650 const Definition *nextScope = isDef(next) ? getDef(next)->getOuterScope() : nullptr;
651 const MemberDef *md = toMemberDef(d);
652 DString anchor = d ? d->anchor() : si ? si->label() : DString();
653
654 if (word!=lastWord) // this item has a different search word
655 {
656 if (!firstEntry)
657 {
658 ti << "]]]";
659 ti << ",\n";
660 }
661 firstEntry=false;
662 ti << " ['" << id << "_" << cnt++ << "',['";
663 if (next==SearchTerm::LinkInfo() || it->word!=word) // unique result, show title
664 {
665 ti << convertToJSString(convertToXML(term.title),true,true);
666 }
667 else // multiple results, show matching word only, expanded list will show title
668 {
669 ti << convertToJSString(convertToXML(term.word),true,true);
670 }
671 ti << "',[";
672 childCount=0;
673 prevScope=nullptr;
674 }
675
676 if (childCount>0)
677 {
678 ti << "],[";
679 }
680 DString fn = d ? d->getOutputFileBase() : si ? si->fileName() : DString();
681 DString ref = d ? d->getReference() : si ? si->ref() : DString();
683 DString extRef = externalRef("../",ref)+fn;
684 if (!anchor.empty())
685 {
686 extRef+="#"+anchor;
687 }
688 ti << "'" << convertToJSString(extRef,true,true) << "',";
689
690 bool extLinksInWindow = Config_getBool(EXT_LINKS_IN_WINDOW);
691 if (!extLinksInWindow || ref.empty())
692 {
693 ti << "1,";
694 }
695 else
696 {
697 ti << "0,";
698 }
699
700 if (lastWord!=word && (next==SearchTerm::LinkInfo() || it->word!=word)) // unique search result
701 {
702 if (d && d->getOuterScope()!=Doxygen::globalScope)
703 {
704 ti << "'" << convertToJSString(convertToXML(d->getOuterScope()->name()),true,true) << "'";
705 }
706 else if (md)
707 {
708 const FileDef *fd = md->getBodyDef();
709 if (fd==nullptr) fd = md->getFileDef();
710 if (fd)
711 {
712 ti << "'" << convertToJSString(convertToXML(fd->localName()),true,true) << "'";
713 }
714 }
715 else
716 {
717 ti << "''";
718 }
719 }
720 else // multiple entries with the same name
721 {
722 bool found=false;
723 bool overloadedFunction = ((prevScope!=nullptr && scope==prevScope) || (scope && scope==nextScope)) &&
724 md && md->isCallable();
726 if (md) prefix=convertToXML(md->localName());
727 if (overloadedFunction) // overloaded member function
728 {
730 // show argument list to disambiguate overloaded functions
731 }
732 else if (md && md->isCallable()) // unique member function
733 {
734 prefix+="()"; // only to show it is a callable symbol
735 }
737 if (d)
738 {
739 switch (d->definitionType())
740 {
741 case Definition::TypeClass: name = convertToXML((toClassDef(d))->displayName()); found=true; break;
742 case Definition::TypeNamespace: name = convertToXML((toNamespaceDef(d))->displayName()); found=true; break;
743 case Definition::TypeModule: name = convertToXML(d->name()+" "+theTranslator->trModule(false,true)); found=true; break;
744 case Definition::TypePage: name = convertToXML(filterTitle(toPageDef(d)->title())); found=true; break;
745 case Definition::TypeGroup: name = convertToXML(filterTitle(toGroupDef(d)->groupTitle())); found=true; break;
746 default:
747 if (scope==nullptr || scope==Doxygen::globalScope) // in global scope
748 {
749 if (md)
750 {
751 const FileDef *fd = md->getBodyDef();
752 if (fd==nullptr) fd = md->resolveAlias()->getFileDef();
753 if (fd)
754 {
755 if (!prefix.empty()) prefix+=":&#160;";
757 found = true;
758 }
759 }
760 }
761 else if (md && (md->resolveAlias()->getClassDef() || md->resolveAlias()->getNamespaceDef()))
762 // member in class or namespace scope
763 {
764 SrcLangExt lang = md->getLanguage();
767 found = true;
768 }
769 else if (scope) // some thing else? -> show scope
770 {
771 name = prefix + convertToXML(scope->name());
772 found = true;
773 }
774 break;
775 }
776 }
777 else if (si)
778 {
779 name = parseCommentAsHtml(si->definition(),nullptr,si->title(),si->fileName(),si->lineNr());
780 name = convertToXML(name);
781 found = true;
782 }
783 if (!found) // fallback
784 {
786 }
787
788 ti << "'" << convertToJSString(name,true,true) << "'";
789
790 prevScope = scope;
791 childCount++;
792 }
793 lastWord = word;
794 }
795 if (!firstEntry)
796 {
797 ti << "]]]\n";
798 }
799 ti << "];\n";
800 Doxygen::indexList->addStyleSheetFile(("search/"+baseName+".js").data());
801}
constexpr auto prefix
Definition anchor.cpp:47
The common base class of all entity definitions found in the sources.
Definition definition.h:77
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
virtual DefType definitionType() const =0
virtual const DString & localName() const =0
virtual const FileDef * getBodyDef() const =0
virtual DString qualifiedName() const =0
virtual DString anchor() const =0
virtual DString getReference() const =0
virtual Definition * getOuterScope() const =0
virtual DString getOutputFileBase() const =0
static NamespaceDefMutable * globalScope
Definition doxygen.h:114
A model of a class/file/namespace member symbol.
Definition memberdef.h:45
virtual DString argsString() const =0
virtual MemberDef * resolveAlias()=0
virtual bool isCallable() const =0
class that provide information about a section.
Definition section.h:58
DString fileName() const
Definition section.h:74
Definition * definition() const
Definition section.h:77
int lineNr() const
Definition section.h:73
DString title() const
Definition section.h:70
DString ref() const
Definition section.h:72
DString label() const
Definition section.h:69
virtual DString trGlobalNamespace()=0
virtual DString trModule(bool first_capital, bool singular)=0
ClassDef * toClassDef(Definition *d)
DString parseCommentAsHtml(const Definition *scope, const MemberDef *member, const DString &doc, const DString &fileName, int lineNr)
GroupDef * toGroupDef(Definition *d)
Translator * theTranslator
Definition language.cpp:76
MemberDef * toMemberDef(Definition *d)
#define err(fmt,...)
Definition message.h:127
#define ASSERT(x)
Definition message.h:142
#define term(fmt,...)
Definition message.h:137
const char * name(int level)
Definition latexgen.h:368
NamespaceDef * toNamespaceDef(Definition *d)
PageDef * toPageDef(Definition *d)
Definition pagedef.cpp:656
std::variant< std::monostate, const Definition *, const SectionInfo * > LinkInfo
SrcLangExt
Definition types.h:207
void addHtmlExtensionIfMissing(DString &fName)
Definition util.cpp:4063
DString getLanguageSpecificSeparator(SrcLangExt lang, bool classScope)
Definition util.cpp:4765
DString externalRef(const DString &relPath, const DString &ref)
Definition util.cpp:4674

References addHtmlExtensionIfMissing(), IndexList::addStyleSheetFile(), Definition::anchor(), MemberDef::argsString(), ASSERT, Config_getBool, convertToJSString(), convertToXML(), SectionInfo::definition(), Definition::definitionType(), DString::empty(), err, externalRef(), SectionInfo::fileName(), filterTitle(), Definition::getBodyDef(), MemberDef::getClassDef(), MemberDef::getFileDef(), Definition::getLanguage(), getLanguageSpecificSeparator(), MemberDef::getNamespaceDef(), Definition::getOuterScope(), Definition::getOutputFileBase(), Definition::getReference(), Doxygen::globalScope, Doxygen::indexList, MemberDef::isCallable(), SectionInfo::label(), SectionInfo::lineNr(), Definition::localName(), Definition::name(), Portable::openOutputStream(), parseCommentAsHtml(), prefix, Definition::qualifiedName(), SectionInfo::ref(), MemberDef::resolveAlias(), term, theTranslator, SectionInfo::title(), toClassDef(), toGroupDef(), toMemberDef(), toNamespaceDef(), toPageDef(), Translator::trGlobalNamespace(), Translator::trModule(), Definition::TypeClass, Definition::TypeGroup, Definition::TypeModule, Definition::TypeNamespace, and Definition::TypePage.

Referenced by writeJavaScriptSearchIndex().

Variable Documentation

◆ g_searchIndexInfo