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 std::string key = level1.str();
157 if (!level2.isEmpty()) key+= std::string("?") + level2.str();
158 if (reg::search(key,re)) // skip anonymous stuff
159 {
160 return;
161 }
162 std::string key_anchor;
163 if (!anchor.isEmpty())
164 {
165 key_anchor = key+anchor.str();
166 }
167 else
168 {
169 key_anchor = key;
170 }
171 m_map.add(key_anchor.c_str(),key.c_str(),url,anchor,hasLink,reversed);
172}
LinkedMap< IndexField > m_map
Definition htmlhelp.cpp:125
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
const std::string & str() const
Definition qcstring.h:526
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

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

◆ 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 238 of file htmlhelp.cpp.

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

References convertToHtml(), convertToHtmlAndTruncate(), FALSE, field2URL(), 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: