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 DString &first, const DString &second, const DString &url, const DString &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 115 of file htmlhelp.cpp.

Constructor & Destructor Documentation

◆ HtmlHelpIndex()

HtmlHelpIndex::HtmlHelpIndex ( HtmlHelpRecoder & recoder)

Constructs a new HtmlHelp index

Definition at line 132 of file htmlhelp.cpp.

132 : m_recoder(recoder)
133{
134}
HtmlHelpRecoder & m_recoder
Definition htmlhelp.cpp:128

References m_recoder.

Referenced by ~HtmlHelpIndex().

◆ ~HtmlHelpIndex()

HtmlHelpIndex::~HtmlHelpIndex ( )
default

Destroys the HtmlHelp index

References HtmlHelpIndex().

Member Function Documentation

◆ addItem()

void HtmlHelpIndex::addItem ( const DString & level1,
const DString & level2,
const DString & url,
const DString & 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 153 of file htmlhelp.cpp.

156{
157 static const reg::Ex re(R"(@\d+)");
158 DString key = substitute(level1,"?","&quest;");
159 if (!level2.empty()) key+= "?" + substitute(level2,"?","&quest;");
160 if (reg::search(key.str(),re)) // skip anonymous stuff
161 {
162 return;
163 }
164 DString key_anchor = key;
165 if (!anchor.empty())
166 {
167 key_anchor += anchor;
168 }
169 m_map.add(key_anchor,key,url,anchor,hasLink,reversed);
170}
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
const std::string & str() const
Definition dstring.h:645
LinkedMap< IndexField > m_map
Definition htmlhelp.cpp:127
T * add(const char *k, Args &&... args)
Definition linkedmap.h:90
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
Definition dstring.cpp:485
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:850

References LinkedMap< T, Hash, KeyEqual, Map >::add(), DString::empty(), m_map, reg::search(), DString::str(), and substitute().

◆ size()

size_t HtmlHelpIndex::size ( ) const
inline

Definition at line 125 of file htmlhelp.cpp.

125{ return m_map.size(); }
size_t size() const
Definition linkedmap.h:210

References m_map, and LinkedMap< T, Hash, KeyEqual, Map >::size().

Referenced by HtmlHelp::Private::createProjectFile().

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

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

References convertToHtml(), convertToHtmlAndTruncate(), dstricmp_sort(), DString::empty(), field2URL(), DString::left(), m_map, m_recoder, DString::mid(), DString::npos, and HtmlHelpRecoder::recode().

Member Data Documentation

◆ m_map

LinkedMap<IndexField> HtmlHelpIndex::m_map
private

Definition at line 127 of file htmlhelp.cpp.

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

◆ m_recoder

HtmlHelpRecoder& HtmlHelpIndex::m_recoder
private

Definition at line 128 of file htmlhelp.cpp.

Referenced by HtmlHelpIndex(), and writeFields().


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