Doxygen
Loading...
Searching...
No Matches
DocLink Class Referencefinal

Node representing a link to some item. More...

#include <src/docnode.h>

Inheritance diagram for DocLink:
Collaboration diagram for DocLink:

Public Member Functions

 DocLink (DocParser *parser, DocNodeVariant *parent, const DString &target)
DString parse (bool, bool isXmlLink=false)
DString file () const
DString relPath () const
DString ref () const
DString anchor () const
Public Member Functions inherited from DocCompoundNode
 DocCompoundNode (DocParser *parser, DocNodeVariant *parent)
DocNodeList & children ()
const DocNodeList & children () const
Public Member Functions inherited from DocNode
 DocNode (DocParser *parser, DocNodeVariant *parent)
 ~DocNode ()=default
DocNodeVariant * parent ()
const DocNodeVariant * parent () const
DocNodeVariant * thisVariant ()
const DocNodeVariant * thisVariant () const
void setThisVariant (DocNodeVariant *thisVariant)
DocParser * parser ()
const DocParser * parser () const
void setParent (DocNodeVariant *parent)
bool isPreformatted () const

Private Attributes

DString m_file
DString m_relPath
DString m_ref
DString m_anchor
DString m_refText

Additional Inherited Members

Protected Types inherited from DocNode
enum  RefType {
  Unknown , Anchor , Section , Table ,
  Requirement
}
Protected Member Functions inherited from DocNode
void setInsidePreformatted (bool p)

Detailed Description

Node representing a link to some item.

Definition at line 767 of file docnode.h.

Constructor & Destructor Documentation

◆ DocLink()

DocLink::DocLink ( DocParser * parser,
DocNodeVariant * parent,
const DString & target )

Definition at line 1011 of file docnode.cpp.

1012{
1013 const Definition *compound = nullptr;
1014 DString anchor;
1015 m_refText = target;
1017 if (!m_refText.empty() && m_refText.at(0)=='#')
1018 {
1019 m_refText = m_refText.mid(1);
1020 }
1022 parser->context.inSeeBlock,&compound,anchor,
1025 {
1026 m_anchor = anchor;
1027 if (compound && compound->isLinkable())
1028 {
1029 m_file = compound->getOutputFileBase();
1030 m_ref = compound->getReference();
1031 }
1032 else if (compound && compound->definitionType()==Definition::TypeFile &&
1033 (toFileDef(compound))->generateSourceFile()
1034 ) // undocumented file that has source code we can link to
1035 {
1036 m_file = compound->getSourceFileBase();
1037 m_ref = compound->getReference();
1038 }
1039 return;
1040 }
1041
1042 // bogus link target
1043 warn_doc_error(parser->context.fileName,parser->tokenizer.getLineNr(),"unable to resolve link to '{}' for \\link command",
1044 target);
1045}
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:318
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
char & at(size_t i)
Returns a reference to the character at index i.
Definition dstring.h:686
virtual bool isLinkable() const =0
virtual DefType definitionType() const =0
virtual DString getReference() const =0
virtual DString getSourceFileBase() const =0
virtual DString getOutputFileBase() const =0
DocCompoundNode(DocParser *parser, DocNodeVariant *parent)
Definition docnode.h:141
DocParser * parser()
Definition docnode.h:97
DocNodeVariant * parent()
Definition docnode.h:89
DocTokenizer tokenizer
DocParserContext context
int getLineNr() const
static const FileDef * currentFileDef(const DocParser *parser)
Definition docnode.cpp:89
static DString stripKnownExtensions(const DString &text)
Definition docnode.cpp:119
FileDef * toFileDef(Definition *d)
Definition filedef.cpp:2027
#define warn_doc_error(file, line, fmt,...)
Definition message.h:112
SrcLangExt lang
Definition docparser_p.h:84
bool resolveLink(const DString &scName, const DString &lr, bool, const Definition **resContext, DString &resAnchor, SrcLangExt lang, const DString &prefix, const FileDef *currentFile)
Definition util.cpp:2308

References anchor(), DString::at(), DocParser::context, DocParserContext::context, currentFileDef(), Definition::definitionType(), DocCompoundNode::DocCompoundNode(), DString::empty(), DocParserContext::fileName, DocTokenizer::getLineNr(), Definition::getOutputFileBase(), Definition::getReference(), Definition::getSourceFileBase(), DocParserContext::inSeeBlock, Definition::isLinkable(), DocParserContext::lang, m_anchor, m_file, m_ref, m_refText, m_relPath, DocNode::parent(), DocNode::parser(), DocParserContext::prefix, DocParserContext::relPath, resolveLink(), stripKnownExtensions(), toFileDef(), DocParser::tokenizer, Definition::TypeFile, and warn_doc_error.

Member Function Documentation

◆ anchor()

◆ file()

◆ parse()

DString DocLink::parse ( bool isJavaLink,
bool isXmlLink = false )

Definition at line 1048 of file docnode.cpp.

1049{
1050 AUTO_TRACE();
1051 DString result;
1052 auto ns = AutoNodeStack(parser(),thisVariant());
1053
1054 Token tok = parser()->tokenizer.lex();
1055 while (!tok.is_any_of(TokenRetval::TK_NONE, TokenRetval::TK_EOF))
1056 {
1057 if (!parser()->defaultHandleToken(thisVariant(),tok,children(),false))
1058 {
1059 switch (tok.value())
1060 {
1061 case TokenRetval::TK_COMMAND_AT:
1062 // fall through
1063 case TokenRetval::TK_COMMAND_BS:
1064 switch (Mappers::cmdMapper->map(parser()->context.token->name))
1065 {
1067 if (isJavaLink)
1068 {
1069 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"'{{@link...' ended with '{:c}{}' command",
1070 tok.command_to_char(),parser()->context.token->name);
1071 }
1072 goto endlink;
1073 default:
1074 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"Illegal command '{:c}{}' as part of a \\link",
1075 tok.command_to_char(),parser()->context.token->name);
1076 break;
1077 }
1078 break;
1079 case TokenRetval::TK_SYMBOL:
1080 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"Unsupported symbol '{}' found as part of a \\link",
1081 parser()->context.token->name);
1082 break;
1083 case TokenRetval::TK_HTMLTAG:
1084 if (parser()->context.token->name!="see" || !isXmlLink)
1085 {
1086 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"Unexpected xml/html command {} found as part of a \\link",
1087 parser()->context.token->name);
1088 }
1089 goto endlink;
1090 case TokenRetval::TK_LNKWORD:
1091 case TokenRetval::TK_WORD:
1092 if (isJavaLink) // special case to detect closing }
1093 {
1094 DString w = parser()->context.token->name;
1095 size_t p = 0;
1096 if (w=="}")
1097 {
1098 goto endlink;
1099 }
1100 else if ((p=w.find('}'))!=DString::npos)
1101 {
1102 size_t l = w.length();
1103 children().append<DocWord>(parser(),thisVariant(),w.left(p));
1104 if (l>1 && p<l-1) // something left after the } (for instance a .)
1105 {
1106 result=w.right(l-p-1);
1107 }
1108 goto endlink;
1109 }
1110 }
1112 break;
1113 default:
1114 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"Unexpected token {}",tok.to_string());
1115 break;
1116 }
1117 }
1118 tok = parser()->tokenizer.lex();
1119 }
1120 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1121 {
1122 warn_doc_error(parser()->context.fileName,
1123 parser()->tokenizer.getLineNr(),
1124 "Unexpected end of comment while inside link command");
1125 }
1126endlink:
1127
1128 if (children().empty()) // no link text
1129 {
1130 children().append<DocWord>(parser(),thisVariant(),m_refText);
1131 }
1132
1134 return result;
1135}
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 right(size_t len) const
Definition dstring.h:311
size_t find(char c, size_t pos=0) const
Definition dstring.h:239
DString left(size_t len) const
Definition dstring.h:306
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:151
DocNodeList & children()
Definition docnode.h:143
DocNodeVariant * thisVariant()
Definition docnode.h:92
void append(Args &&... args)
Append a new DocNodeVariant to the list by constructing it with type T and parameters Args.
Definition docnode.h:1404
void handlePendingStyleCommands(DocNodeVariant *parent, DocNodeList &children, size_t numberOfElementsToClose=0)
TOKEN_SPECIFICATIONS RETVAL_SPECIFICATIONS const char * to_string() const
TokenRetval value() const
bool is_any_of(ARGS... args) const
char command_to_char() const
DString name
#define AUTO_TRACE(...)
Definition docnode.cpp:53
const Mapper< CommandType > * cmdMapper
TokenInfo * token
Definition docparser_p.h:94

References DocNodeList::append(), AUTO_TRACE, DocCompoundNode::children(), CMD_ENDLINK, Mappers::cmdMapper, Token::command_to_char(), DocParser::context, DString::find(), DocParser::handlePendingStyleCommands(), Token::is_any_of(), DString::left(), DString::length(), DocTokenizer::lex(), m_refText, TokenInfo::name, DString::npos, DocNode::parser(), DString::right(), DocNode::thisVariant(), Token::to_string(), DocParserContext::token, DocParser::tokenizer, Token::value(), and warn_doc_error.

◆ ref()

◆ relPath()

DString DocLink::relPath ( ) const
inline

Definition at line 773 of file docnode.h.

773{ return m_relPath; }

References m_relPath.

Referenced by HtmlDocVisitor::operator()().

Member Data Documentation

◆ m_anchor

DString DocLink::m_anchor
private

Definition at line 781 of file docnode.h.

Referenced by anchor(), and DocLink().

◆ m_file

DString DocLink::m_file
private

Definition at line 778 of file docnode.h.

Referenced by DocLink(), and file().

◆ m_ref

DString DocLink::m_ref
private

Definition at line 780 of file docnode.h.

Referenced by DocLink(), and ref().

◆ m_refText

DString DocLink::m_refText
private

Definition at line 782 of file docnode.h.

Referenced by DocLink(), and parse().

◆ m_relPath

DString DocLink::m_relPath
private

Definition at line 779 of file docnode.h.

Referenced by DocLink(), and relPath().


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