Public Member Functions | Private Member Functions | Private Attributes | List of all members
HtmlCodeGenerator Class Reference

#include <htmlgen.h>

Inheritance diagram for HtmlCodeGenerator:
CodeOutputInterface

Public Member Functions

 HtmlCodeGenerator (FTextStream &t, const QCString &relPath)
 
 HtmlCodeGenerator ()
 
void setTextStream (FTextStream &t)
 
void setRelativePath (const QCString &path)
 
void codify (const char *text)
 
void writeCodeLink (const char *ref, const char *file, const char *anchor, const char *name, const char *tooltip)
 
void writeTooltip (const char *id, const DocLinkInfo &docInfo, const char *decl, const char *desc, const SourceLinkInfo &defInfo, const SourceLinkInfo &declInfo)
 
void writeLineNumber (const char *, const char *, const char *, int)
 
void startCodeLine (bool)
 
void endCodeLine ()
 
void startFontClass (const char *s)
 
void endFontClass ()
 
void writeCodeAnchor (const char *anchor)
 
void setCurrentDoc (Definition *, const char *, bool)
 
void addWord (const char *, bool)
 
- Public Member Functions inherited from CodeOutputInterface
virtual ~CodeOutputInterface ()
 

Private Member Functions

void _writeCodeLink (const char *className, const char *ref, const char *file, const char *anchor, const char *name, const char *tooltip)
 
void docify (const char *str)
 

Private Attributes

bool m_streamSet
 
FTextStream m_t
 
int m_col
 
QCString m_relPath
 

Detailed Description

Definition at line 31 of file htmlgen.h.

Constructor & Destructor Documentation

HtmlCodeGenerator::HtmlCodeGenerator ( FTextStream t,
const QCString relPath 
)

Definition at line 406 of file htmlgen.cpp.

407  : m_col(0), m_relPath(relPath)
408 {
409  setTextStream(t);
410 }
void setTextStream(FTextStream &t)
Definition: htmlgen.cpp:412
QCString m_relPath
Definition: htmlgen.h:67
HtmlCodeGenerator::HtmlCodeGenerator ( )

Definition at line 401 of file htmlgen.cpp.

402  : m_streamSet(FALSE), m_col(0)
403 {
404 }
const bool FALSE
Definition: qglobal.h:370
bool m_streamSet
Definition: htmlgen.h:64

Member Function Documentation

void HtmlCodeGenerator::_writeCodeLink ( const char *  className,
const char *  ref,
const char *  file,
const char *  anchor,
const char *  name,
const char *  tooltip 
)
private

Definition at line 533 of file htmlgen.cpp.

537 {
538  if (ref)
539  {
540  m_t << "<a class=\"" << className << "Ref\" ";
542  }
543  else
544  {
545  m_t << "<a class=\"" << className << "\" ";
546  }
547  m_t << "href=\"";
548  m_t << externalRef(m_relPath,ref,TRUE);
549  if (f) m_t << f << Doxygen::htmlFileExtension;
550  if (anchor) m_t << "#" << anchor;
551  m_t << "\"";
552  if (tooltip) m_t << " title=\"" << convertToHtml(tooltip) << "\"";
553  m_t << ">";
554  docify(name);
555  m_t << "</a>";
556  m_col+=qstrlen(name);
557 }
static QCString name
Definition: declinfo.cpp:673
static QCString htmlFileExtension
Definition: doxygen.h:130
const bool FALSE
Definition: qglobal.h:370
static QCString className
Definition: declinfo.cpp:669
void docify(const char *str)
Definition: htmlgen.cpp:471
Q_EXPORT uint qstrlen(const char *str)
Definition: qcstring.h:81
QCString convertToHtml(const char *s, bool keepEntities)
Definition: util.cpp:5746
QCString m_relPath
Definition: htmlgen.h:67
QCString externalLinkTarget()
Definition: util.cpp:7850
const bool TRUE
Definition: qglobal.h:371
FTextStream m_t
Definition: htmlgen.h:65
QCString externalRef(const QCString &relPath, const QCString &ref, bool href)
Definition: util.cpp:7856
void HtmlCodeGenerator::addWord ( const char *  ,
bool   
)
inlinevirtual

Implements CodeOutputInterface.

Definition at line 56 of file htmlgen.h.

56 {}
void HtmlCodeGenerator::codify ( const char *  s)
virtual

Writes an code fragment to the output. This function should keep spaces visible, should break lines at a newline and should convert tabs to the right number of spaces.

Implements CodeOutputInterface.

Definition at line 423 of file htmlgen.cpp.

424 {
425  static int tabSize = Config_getInt("TAB_SIZE");
426  if (str && m_streamSet)
427  {
428  const char *p=str;
429  char c;
430  int spacesToNextTabStop;
431  while (*p)
432  {
433  c=*p++;
434  switch(c)
435  {
436  case '\t': spacesToNextTabStop =
437  tabSize - (m_col%tabSize);
438  m_t << Doxygen::spaces.left(spacesToNextTabStop);
439  m_col+=spacesToNextTabStop;
440  break;
441  case '\n': m_t << "\n"; m_col=0;
442  break;
443  case '\r': break;
444  case '<': m_t << "&lt;"; m_col++;
445  break;
446  case '>': m_t << "&gt;"; m_col++;
447  break;
448  case '&': m_t << "&amp;"; m_col++;
449  break;
450  case '\'': m_t << "&#39;"; m_col++; // &apos; is not valid XHTML
451  break;
452  case '"': m_t << "&quot;"; m_col++;
453  break;
454  case '\\':
455  if (*p=='<')
456  { m_t << "&lt;"; p++; }
457  else if (*p=='>')
458  { m_t << "&gt;"; p++; }
459  else
460  m_t << "\\";
461  m_col++;
462  break;
463  default: p=writeUtf8Char(m_t,p-1);
464  m_col++;
465  break;
466  }
467  }
468  }
469 }
QCString left(uint len) const
Definition: qcstring.cpp:213
#define Config_getInt(val)
Definition: config.cpp:661
const char * writeUtf8Char(FTextStream &t, const char *s)
Definition: util.cpp:7165
p
Definition: test.py:223
bool m_streamSet
Definition: htmlgen.h:64
static QCString spaces
Definition: doxygen.h:151
static QCString str
FTextStream m_t
Definition: htmlgen.h:65
void HtmlCodeGenerator::docify ( const char *  str)
private

Definition at line 471 of file htmlgen.cpp.

472 {
473  if (str && m_streamSet)
474  {
475  const char *p=str;
476  char c;
477  while (*p)
478  {
479  c=*p++;
480  switch(c)
481  {
482  case '<': m_t << "&lt;"; break;
483  case '>': m_t << "&gt;"; break;
484  case '&': m_t << "&amp;"; break;
485  case '"': m_t << "&quot;"; break;
486  case '\\':
487  if (*p=='<')
488  { m_t << "&lt;"; p++; }
489  else if (*p=='>')
490  { m_t << "&gt;"; p++; }
491  else
492  m_t << "\\";
493  break;
494  default: m_t << c;
495  }
496  }
497  }
498 }
p
Definition: test.py:223
bool m_streamSet
Definition: htmlgen.h:64
static QCString str
FTextStream m_t
Definition: htmlgen.h:65
void HtmlCodeGenerator::endCodeLine ( )
virtual

Ends a line of code started with startCodeLine()

Implements CodeOutputInterface.

Definition at line 650 of file htmlgen.cpp.

651 {
652  if (m_streamSet) m_t << "</div>";
653 }
bool m_streamSet
Definition: htmlgen.h:64
FTextStream m_t
Definition: htmlgen.h:65
void HtmlCodeGenerator::endFontClass ( )
virtual

Ends a block started with startFontClass()

Implements CodeOutputInterface.

Definition at line 660 of file htmlgen.cpp.

661 {
662  if (m_streamSet) m_t << "</span>";
663 }
bool m_streamSet
Definition: htmlgen.h:64
FTextStream m_t
Definition: htmlgen.h:65
void HtmlCodeGenerator::setCurrentDoc ( Definition ,
const char *  ,
bool   
)
inlinevirtual

Implements CodeOutputInterface.

Definition at line 55 of file htmlgen.h.

55 {}
void HtmlCodeGenerator::setRelativePath ( const QCString path)

Definition at line 418 of file htmlgen.cpp.

419 {
420  m_relPath = path;
421 }
QCString m_relPath
Definition: htmlgen.h:67
void HtmlCodeGenerator::setTextStream ( FTextStream t)

Definition at line 412 of file htmlgen.cpp.

413 {
414  m_streamSet = t.device()!=0;
415  m_t.setDevice(t.device());
416 }
void setDevice(QIODevice *)
QIODevice * device() const
bool m_streamSet
Definition: htmlgen.h:64
FTextStream m_t
Definition: htmlgen.h:65
void HtmlCodeGenerator::startCodeLine ( bool  hasLineNumbers)
virtual

Implements CodeOutputInterface.

Definition at line 641 of file htmlgen.cpp.

642 {
643  if (m_streamSet)
644  {
645  if (!hasLineNumbers) m_t << "<div class=\"line\">";
646  m_col=0;
647  }
648 }
bool m_streamSet
Definition: htmlgen.h:64
FTextStream m_t
Definition: htmlgen.h:65
void HtmlCodeGenerator::startFontClass ( const char *  clsName)
virtual

Starts a block with a certain meaning. Used for syntax highlighting, which elements of the same type are rendered using the same 'font class'.

Parameters
clsNameThe category name.

Implements CodeOutputInterface.

Definition at line 655 of file htmlgen.cpp.

656 {
657  if (m_streamSet) m_t << "<span class=\"" << s << "\">";
658 }
bool m_streamSet
Definition: htmlgen.h:64
static QCString * s
Definition: config.cpp:1042
FTextStream m_t
Definition: htmlgen.h:65
void HtmlCodeGenerator::writeCodeAnchor ( const char *  name)
virtual

Write an anchor to a source listing.

Parameters
nameThe name of the anchor.

Implements CodeOutputInterface.

Definition at line 665 of file htmlgen.cpp.

666 {
667  if (m_streamSet) m_t << "<a name=\"" << anchor << "\"></a>";
668 }
bool m_streamSet
Definition: htmlgen.h:64
FTextStream m_t
Definition: htmlgen.h:65
void HtmlCodeGenerator::writeCodeLink ( const char *  ref,
const char *  file,
const char *  anchor,
const char *  name,
const char *  tooltip 
)
virtual

Writes a link to an object in a code fragment.

Parameters
refIf this is non-zero, the object is to be found in an external documentation file.
fileThe file in which the object is located.
anchorThe anchor uniquely identifying the object within the file.
nameThe text to display as a placeholder for the link.
tooltipThe tooltip to display when the mouse is on the link.

Implements CodeOutputInterface.

Definition at line 524 of file htmlgen.cpp.

527 {
528  if (!m_streamSet) return;
529  //printf("writeCodeLink(ref=%s,f=%s,anchor=%s,name=%s,tooltip=%s)\n",ref,f,anchor,name,tooltip);
530  _writeCodeLink("code",ref,f,anchor,name,tooltip);
531 }
static QCString name
Definition: declinfo.cpp:673
void _writeCodeLink(const char *className, const char *ref, const char *file, const char *anchor, const char *name, const char *tooltip)
Definition: htmlgen.cpp:533
bool m_streamSet
Definition: htmlgen.h:64
void HtmlCodeGenerator::writeLineNumber ( const char *  ref,
const char *  file,
const char *  anchor,
int  lineNumber 
)
virtual

Writes the line number of a source listing

Parameters
refExternal reference (when imported from a tag file)
fileThe file part of the URL pointing to the docs.
anchorThe anchor part of the URL pointing to the docs.
lineNumberThe line number to write

Implements CodeOutputInterface.

Definition at line 500 of file htmlgen.cpp.

502 {
503  if (!m_streamSet) return;
504  const int maxLineNrStr = 10;
505  char lineNumber[maxLineNrStr];
506  char lineAnchor[maxLineNrStr];
507  qsnprintf(lineNumber,maxLineNrStr,"%5d",l);
508  qsnprintf(lineAnchor,maxLineNrStr,"l%05d",l);
509 
510  m_t << "<div class=\"line\">";
511  m_t << "<a name=\"" << lineAnchor << "\"></a><span class=\"lineno\">";
512  if (filename)
513  {
514  _writeCodeLink("line",ref,filename,anchor,lineNumber,0);
515  }
516  else
517  {
518  codify(lineNumber);
519  }
520  m_t << "</span>";
521  m_t << "&#160;";
522 }
void codify(const char *text)
Definition: htmlgen.cpp:423
#define qsnprintf
Definition: qcstring.h:73
string filename
Definition: train.py:213
static QStrList * l
Definition: config.cpp:1044
void _writeCodeLink(const char *className, const char *ref, const char *file, const char *anchor, const char *name, const char *tooltip)
Definition: htmlgen.cpp:533
bool m_streamSet
Definition: htmlgen.h:64
FTextStream m_t
Definition: htmlgen.h:65
void HtmlCodeGenerator::writeTooltip ( const char *  id,
const DocLinkInfo docInfo,
const char *  decl,
const char *  desc,
const SourceLinkInfo defInfo,
const SourceLinkInfo declInfo 
)
virtual

Writes a tool tip definition

Parameters
idunique identifier for the tooltip
docInfoInfo about the symbol's documentation.
declfull declaration of the symbol (for functions)
descbrief description for the symbol
defInfoInfo about the symbol's definition in the source code
declInfoInfo about the symbol's declaration in the source code

Implements CodeOutputInterface.

Definition at line 559 of file htmlgen.cpp.

563 {
564  m_t << "<div class=\"ttc\" id=\"" << id << "\">";
565  m_t << "<div class=\"ttname\">";
566  if (!docInfo.url.isEmpty())
567  {
568  m_t << "<a href=\"";
569  m_t << externalRef(m_relPath,docInfo.ref,TRUE);
570  m_t << docInfo.url << Doxygen::htmlFileExtension;
571  if (!docInfo.anchor.isEmpty())
572  {
573  m_t << "#" << docInfo.anchor;
574  }
575  m_t << "\">";
576  }
577  docify(docInfo.name);
578  if (!docInfo.url.isEmpty())
579  {
580  m_t << "</a>";
581  }
582  m_t << "</div>";
583  if (decl)
584  {
585  m_t << "<div class=\"ttdeci\">";
586  docify(decl);
587  m_t << "</div>";
588  }
589  if (desc)
590  {
591  m_t << "<div class=\"ttdoc\">";
592  docify(desc); // desc is already HTML escaped; but there are still < and > signs
593  m_t << "</div>";
594  }
595  if (!defInfo.file.isEmpty())
596  {
597  m_t << "<div class=\"ttdef\"><b>Definition:</b> ";
598  if (!defInfo.url.isEmpty())
599  {
600  m_t << "<a href=\"";
601  m_t << externalRef(m_relPath,defInfo.ref,TRUE);
602  m_t << defInfo.url << Doxygen::htmlFileExtension;
603  if (!defInfo.anchor.isEmpty())
604  {
605  m_t << "#" << defInfo.anchor;
606  }
607  m_t << "\">";
608  }
609  m_t << defInfo.file << ":" << defInfo.line;
610  if (!defInfo.url.isEmpty())
611  {
612  m_t << "</a>";
613  }
614  m_t << "</div>";
615  }
616  if (!declInfo.file.isEmpty())
617  {
618  m_t << "<div class=\"ttdecl\"><b>Declaration:</b> ";
619  if (!declInfo.url.isEmpty())
620  {
621  m_t << "<a href=\"";
622  m_t << externalRef(m_relPath,declInfo.ref,TRUE);
623  m_t << declInfo.url << Doxygen::htmlFileExtension;
624  if (!declInfo.anchor.isEmpty())
625  {
626  m_t << "#" << declInfo.anchor;
627  }
628  m_t << "\">";
629  }
630  m_t << declInfo.file << ":" << declInfo.line;
631  if (!declInfo.url.isEmpty())
632  {
633  m_t << "</a>";
634  }
635  m_t << "</div>";
636  }
637  m_t << "</div>" << endl;
638 }
QCString ref
Definition: outputgen.h:43
QCString file
Definition: outputgen.h:50
bool isEmpty() const
Definition: qcstring.h:189
QCString url
Definition: outputgen.h:53
static QCString htmlFileExtension
Definition: doxygen.h:130
QCString ref
Definition: outputgen.h:52
QCString anchor
Definition: outputgen.h:54
void docify(const char *str)
Definition: htmlgen.cpp:471
QCString m_relPath
Definition: htmlgen.h:67
QCString name
Definition: outputgen.h:42
QCString anchor
Definition: outputgen.h:45
QCString url
Definition: outputgen.h:44
const bool TRUE
Definition: qglobal.h:371
FTextStream m_t
Definition: htmlgen.h:65
QTextStream & endl(QTextStream &s)
QCString externalRef(const QCString &relPath, const QCString &ref, bool href)
Definition: util.cpp:7856

Member Data Documentation

int HtmlCodeGenerator::m_col
private

Definition at line 66 of file htmlgen.h.

QCString HtmlCodeGenerator::m_relPath
private

Definition at line 67 of file htmlgen.h.

bool HtmlCodeGenerator::m_streamSet
private

Definition at line 64 of file htmlgen.h.

FTextStream HtmlCodeGenerator::m_t
private

Definition at line 65 of file htmlgen.h.


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