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 1017 of file docnode.cpp.

1018{
1019 const Definition *compound = nullptr;
1020 DString anchor;
1021 m_refText = target;
1023 if (!m_refText.empty() && m_refText.at(0)=='#')
1024 {
1025 m_refText = m_refText.mid(1);
1026 }
1028 parser->context.inSeeBlock,&compound,anchor,
1031 {
1032 m_anchor = anchor;
1033 if (compound && compound->isLinkable())
1034 {
1035 m_file = compound->getOutputFileBase();
1036 m_ref = compound->getReference();
1037 }
1038 else if (compound && compound->definitionType()==Definition::TypeFile &&
1039 (toFileDef(compound))->generateSourceFile()
1040 ) // undocumented file that has source code we can link to
1041 {
1042 m_file = compound->getSourceFileBase();
1043 m_ref = compound->getReference();
1044 }
1045 return;
1046 }
1047
1048 // bogus link target
1049 warn_doc_error(parser->context.fileName,parser->tokenizer.getLineNr(),"unable to resolve link to '{}' for \\link command",
1050 target);
1051}
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:2054
#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:2316

References anchor(), DString::at(), DocParser::context, DocParserContext::context, currentFileDef(), Definition::definitionType(), 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 1054 of file docnode.cpp.

1055{
1056 AUTO_TRACE();
1057 DString result;
1058 auto ns = AutoNodeStack(parser(),thisVariant());
1059
1060 Token tok = parser()->tokenizer.lex();
1061 while (!tok.is_any_of(TokenRetval::TK_NONE, TokenRetval::TK_EOF))
1062 {
1063 if (!parser()->defaultHandleToken(thisVariant(),tok,children(),false))
1064 {
1065 switch (tok.value())
1066 {
1067 case TokenRetval::TK_COMMAND_AT:
1068 // fall through
1069 case TokenRetval::TK_COMMAND_BS:
1070 switch (Mappers::cmdMapper->map(parser()->context.token->name))
1071 {
1073 if (isJavaLink)
1074 {
1075 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"'{{@link...' ended with '{:c}{}' command",
1076 tok.command_to_char(),parser()->context.token->name);
1077 }
1078 goto endlink;
1079 default:
1080 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"Illegal command '{:c}{}' as part of a \\link",
1081 tok.command_to_char(),parser()->context.token->name);
1082 break;
1083 }
1084 break;
1085 case TokenRetval::TK_SYMBOL:
1086 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"Unsupported symbol '{}' found as part of a \\link",
1087 parser()->context.token->name);
1088 break;
1089 case TokenRetval::TK_HTMLTAG:
1090 if (parser()->context.token->name!="see" || !isXmlLink)
1091 {
1092 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"Unexpected xml/html command {} found as part of a \\link",
1093 parser()->context.token->name);
1094 }
1095 goto endlink;
1096 case TokenRetval::TK_LNKWORD:
1097 case TokenRetval::TK_WORD:
1098 if (isJavaLink) // special case to detect closing }
1099 {
1100 DString w = parser()->context.token->name;
1101 size_t p = 0;
1102 if (w=="}")
1103 {
1104 goto endlink;
1105 }
1106 else if ((p=w.find('}'))!=DString::npos)
1107 {
1108 size_t l = w.length();
1109 children().append<DocWord>(parser(),thisVariant(),w.left(p));
1110 if (l>1 && p<l-1) // something left after the } (for instance a .)
1111 {
1112 result=w.right(l-p-1);
1113 }
1114 goto endlink;
1115 }
1116 }
1118 break;
1119 default:
1120 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"Unexpected token {}",tok.to_string());
1121 break;
1122 }
1123 }
1124 tok = parser()->tokenizer.lex();
1125 }
1126 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1127 {
1128 warn_doc_error(parser()->context.fileName,
1129 parser()->tokenizer.getLineNr(),
1130 "Unexpected end of comment while inside link command");
1131 }
1132endlink:
1133
1134 if (children().empty()) // no link text
1135 {
1136 children().append<DocWord>(parser(),thisVariant(),m_refText);
1137 }
1138
1140 return result;
1141}
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: