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 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 addItem(), HtmlHelpIndex(), NON_COPYABLE, and writeFields().

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

154{
155 static const reg::Ex re(R"(@\d+)");
156 DString key = substitute(level1,"?","&quest;");
157 if (!level2.empty()) key+= "?" + substitute(level2,"?","&quest;");
158 if (reg::search(key.str(),re)) // skip anonymous stuff
159 {
160 return;
161 }
162 DString key_anchor = key;
163 if (!anchor.empty())
164 {
165 key_anchor += anchor;
166 }
167 m_map.add(key_anchor,key,url,anchor,hasLink,reversed);
168}
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:153
const std::string & str() const
Definition dstring.h:634
LinkedMap< IndexField > m_map
Definition htmlhelp.cpp:125
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:476
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:847

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

Referenced by ~HtmlHelpIndex().

◆ size()

size_t HtmlHelpIndex::size ( ) const
inline

Definition at line 123 of file htmlhelp.cpp.

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

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

Referenced by ~HtmlHelpIndex().

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: