Doxygen
Loading...
Searching...
No Matches
HtmlHelpIndex Class Reference

A helper class for HtmlHelp that manages a two level index in alphabetical order. More...

Collaboration diagram for HtmlHelpIndex:

Public Member Functions

 HtmlHelpIndex (HtmlHelpRecoder &recoder)
 ~HtmlHelpIndex ()
void addItem (const QCString &first, const QCString &second, const QCString &url, const QCString &anchor, bool hasLink, bool reversed)
void writeFields (std::ostream &t)
size_t size () const

Private Attributes

LinkedMap< IndexFieldm_map
HtmlHelpRecoderm_recoder

Detailed Description

A helper class for HtmlHelp that manages a two level index in alphabetical order.

Definition at line 113 of file htmlhelp.cpp.

Constructor & Destructor Documentation

◆ HtmlHelpIndex()

HtmlHelpIndex::HtmlHelpIndex ( HtmlHelpRecoder & recoder)

Constructs a new HtmlHelp index

Definition at line 130 of file htmlhelp.cpp.

130 : m_recoder(recoder)
131{
132}
HtmlHelpRecoder & m_recoder
Definition htmlhelp.cpp:126

References m_recoder.

Referenced by ~HtmlHelpIndex().

◆ ~HtmlHelpIndex()

HtmlHelpIndex::~HtmlHelpIndex ( )
default

Destroys the HtmlHelp index

References HtmlHelpIndex().

Member Function Documentation

◆ addItem()

void HtmlHelpIndex::addItem ( const QCString & level1,
const QCString & level2,
const QCString & url,
const QCString & anchor,
bool hasLink,
bool reversed )

Stores an item in the index if it is not already present. Items are stored in alphabetical order, by sorting on the concatenation of level1 and level2 (if present).

Parameters
level1the string at level 1 in the index.
level2the string at level 2 in the index (or 0 if not applicable).
urlthe url of the documentation (without .html extension).
anchorthe anchor of the documentation within the page.
hasLinkif true, the url (without anchor) can be used in the level1 item, when writing the header of a list of level2 items.
reversedTRUE if level1 is the member name and level2 the compound name.

Definition at line 151 of file htmlhelp.cpp.

154{
155 static const reg::Ex re(R"(@\d+)");
156 QCString key = substitute(level1,"?","&quest;");
157 if (!level2.isEmpty()) key+= "?" + substitute(level2,"?","&quest;");
158 if (reg::search(key.str(),re)) // skip anonymous stuff
159 {
160 return;
161 }
162 QCString key_anchor = key;
163 if (!anchor.isEmpty())
164 {
165 key_anchor += anchor;
166 }
167 m_map.add(key_anchor,key,url,anchor,hasLink,reversed);
168}
LinkedMap< IndexField > m_map
Definition htmlhelp.cpp:125
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
const std::string & str() const
Definition qcstring.h:552
bool search(std::string_view str, Match &match, const Ex &re, size_t pos)
Search in a given string str starting at position pos for a match against regular expression re.
Definition regex.cpp:748
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:482

References QCString::isEmpty(), m_map, reg::search(), QCString::str(), and substitute().

◆ size()

size_t HtmlHelpIndex::size ( ) const
inline

Definition at line 123 of file htmlhelp.cpp.

123{ return m_map.size(); }

References m_map.

◆ writeFields()

void HtmlHelpIndex::writeFields ( std::ostream & t)

Writes the sorted list of index items into a html like list.

An list of calls with name = level1,level2 as follows:

  a1,b1
  a1,b2
  a2,b1
  a2,b2
  a3
  a4,b1

Will result in the following list:

  a1       -> link to url if hasLink==TRUE
    b1     -> link to url#anchor
    b2     -> link to url#anchor
  a2       -> link to url if hasLink==TRUE
    b1     -> link to url#anchor
    b2     -> link to url#anchor
  a3       -> link to url if hasLink==TRUE
  a4       -> link to url if hasLink==TRUE
    b1     -> link to url#anchor

Definition at line 234 of file htmlhelp.cpp.

235{
236 std::stable_sort(std::begin(m_map),
237 std::end(m_map),
238 [](const auto &e1,const auto &e2) { return qstricmp_sort(e1->name,e2->name)<0; }
239 );
240 QCString prevLevel1;
241 bool level2Started=FALSE;
242 for (auto it = std::begin(m_map); it!=std::end(m_map); ++it)
243 {
244 auto &f = *it;
245 QCString level1,level2;
246 int i = f->name.find('?');
247 if (i!=-1)
248 {
249 level1 = f->name.left(i);
250 level2 = f->name.right(f->name.length()-i-1);
251 }
252 else
253 {
254 level1 = f->name;
255 }
256
257 { // finish old list at level 2
258 if (level2Started) t << " </UL>\n";
259 level2Started=FALSE;
260
261 // <Antony>
262 // Added this code so that an item with only one subitem is written
263 // without any subitem.
264 // For example:
265 // a1, b1 -> will create only a1, not separate subitem for b1
266 // a2, b2
267 // a2, b3
268 QCString nextLevel1;
269 auto it_next = std::next(it);
270 if (it_next!=std::end(m_map))
271 {
272 auto &fnext = *it_next;
273 int j = fnext->name.find('?');
274 if (j<0) j=0;
275 nextLevel1 = fnext->name.left(j);
276 }
277 if (!(level1 == prevLevel1 || level1 == nextLevel1))
278 {
279 level2 = "";
280 }
281 prevLevel1 = level1;
282 // </Antony>
283
284 if (level2.isEmpty())
285 {
286 t << " <LI><OBJECT type=\"text/sitemap\">";
287 t << "<param name=\"Local\" value=\"" << field2URL(f.get(),FALSE);
288 t << "\">";
289 t << "<param name=\"Name\" value=\"" << convertToHtmlAndTruncate(m_recoder.recode(level1)) << "\">"
290 "</OBJECT>\n";
291 }
292 else
293 {
294 if (f->link)
295 {
296 t << " <LI><OBJECT type=\"text/sitemap\">";
297 t << "<param name=\"Local\" value=\"" << field2URL(f.get(),TRUE);
298 t << "\">";
299 t << "<param name=\"Name\" value=\"" << convertToHtmlAndTruncate(m_recoder.recode(level1)) << "\">"
300 "</OBJECT>\n";
301 }
302 else
303 {
304 t << " <LI><OBJECT type=\"text/sitemap\">";
305 t << "<param name=\"See Also\" value=\"" << convertToHtml(m_recoder.recode(level1)) << "\">";
306 t << "<param name=\"Name\" value=\"" << convertToHtmlAndTruncate(m_recoder.recode(level1)) << "\">"
307 "</OBJECT>\n";
308 }
309 }
310 }
311 if (!level2Started && !level2.isEmpty())
312 { // start new list at level 2
313 t << " <UL>\n";
314 level2Started=TRUE;
315 }
316 else if (level2Started && level2.isEmpty())
317 { // end list at level 2
318 t << " </UL>\n";
319 level2Started=FALSE;
320 }
321 if (level2Started)
322 {
323 t << " <LI><OBJECT type=\"text/sitemap\">";
324 t << "<param name=\"Local\" value=\"" << field2URL(f.get(),FALSE);
325 t << "\">";
326 t << "<param name=\"Name\" value=\"" << convertToHtmlAndTruncate(m_recoder.recode(level2)) << "\">"
327 "</OBJECT>\n";
328 }
329 }
330 if (level2Started) t << " </UL>\n";
331}
QCString right(size_t len) const
Definition qcstring.h:234
QCString left(size_t len) const
Definition qcstring.h:229
static QCString convertToHtmlAndTruncate(const QCString &s)
Definition htmlhelp.cpp:181
static QCString field2URL(const IndexField *f, bool checkReversed)
Definition htmlhelp.cpp:170
int qstricmp_sort(const char *str1, const char *str2)
Definition qcstring.h:86
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
QCString convertToHtml(const QCString &s, bool keepEntities)
Definition util.cpp:4479

References convertToHtml(), convertToHtmlAndTruncate(), FALSE, field2URL(), QCString::find(), QCString::isEmpty(), QCString::left(), m_map, m_recoder, qstricmp_sort(), QCString::right(), and TRUE.

Member Data Documentation

◆ m_map

LinkedMap<IndexField> HtmlHelpIndex::m_map
private

Definition at line 125 of file htmlhelp.cpp.

Referenced by addItem(), size(), and writeFields().

◆ m_recoder

HtmlHelpRecoder& HtmlHelpIndex::m_recoder
private

Definition at line 126 of file htmlhelp.cpp.

Referenced by HtmlHelpIndex(), and writeFields().


The documentation for this class was generated from the following file: