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)
DocNodeListchildren ()
const DocNodeListchildren () const
Public Member Functions inherited from DocNode
 DocNode (DocParser *parser, DocNodeVariant *parent)
 ~DocNode ()=default
DocNodeVariantparent ()
const DocNodeVariantparent () const
DocNodeVariantthisVariant ()
const DocNodeVariantthisVariant () const
void setThisVariant (DocNodeVariant *thisVariant)
DocParserparser ()
const DocParserparser () 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 1000 of file docnode.cpp.

1001{
1002 const Definition *compound = nullptr;
1003 DString anchor;
1004 m_refText = target;
1006 if (!m_refText.empty() && m_refText.at(0)=='#')
1007 {
1008 m_refText = m_refText.mid(1);
1009 }
1011 parser->context.inSeeBlock,&compound,anchor,
1013 {
1014 m_anchor = anchor;
1015 if (compound && compound->isLinkable())
1016 {
1017 m_file = compound->getOutputFileBase();
1018 m_ref = compound->getReference();
1019 }
1020 else if (compound && compound->definitionType()==Definition::TypeFile &&
1021 (toFileDef(compound))->generateSourceFile()
1022 ) // undocumented file that has source code we can link to
1023 {
1024 m_file = compound->getSourceFileBase();
1025 m_ref = compound->getReference();
1026 }
1027 return;
1028 }
1029
1030 // bogus link target
1031 warn_doc_error(parser->context.fileName,parser->tokenizer.getLineNr(),"unable to resolve link to '{}' for \\link command",
1032 target);
1033}
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:322
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:152
char & at(size_t i)
Returns a reference to the character at index i.
Definition dstring.h:690
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 DString stripKnownExtensions(const DString &text)
Definition docnode.cpp:109
FileDef * toFileDef(Definition *d)
Definition filedef.cpp:1976
#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)
Definition util.cpp:2310

References anchor(), DString::at(), DocParser::context, DocParserContext::context, Definition::definitionType(), DocCompoundNode::DocCompoundNode(), DString::empty(), Definition::getReference(), Definition::getSourceFileBase(), DocParserContext::inSeeBlock, DocParserContext::lang, m_file, m_ref, m_refText, m_relPath, DocNode::parent(), DocNode::parser(), DocParserContext::prefix, DocParserContext::relPath, resolveLink(), stripKnownExtensions(), toFileDef(), and Definition::TypeFile.

Member Function Documentation

◆ anchor()

◆ file()

◆ parse()

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

Definition at line 1036 of file docnode.cpp.

1037{
1038 AUTO_TRACE();
1039 DString result;
1040 auto ns = AutoNodeStack(parser(),thisVariant());
1041
1042 Token tok = parser()->tokenizer.lex();
1043 while (!tok.is_any_of(TokenRetval::TK_NONE, TokenRetval::TK_EOF))
1044 {
1045 if (!parser()->defaultHandleToken(thisVariant(),tok,children(),false))
1046 {
1047 switch (tok.value())
1048 {
1049 case TokenRetval::TK_COMMAND_AT:
1050 // fall through
1051 case TokenRetval::TK_COMMAND_BS:
1052 switch (Mappers::cmdMapper->map(parser()->context.token->name))
1053 {
1055 if (isJavaLink)
1056 {
1057 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"'{{@link...' ended with '{:c}{}' command",
1058 tok.command_to_char(),parser()->context.token->name);
1059 }
1060 goto endlink;
1061 default:
1062 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"Illegal command '{:c}{}' as part of a \\link",
1063 tok.command_to_char(),parser()->context.token->name);
1064 break;
1065 }
1066 break;
1067 case TokenRetval::TK_SYMBOL:
1068 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"Unsupported symbol '{}' found as part of a \\link",
1069 parser()->context.token->name);
1070 break;
1071 case TokenRetval::TK_HTMLTAG:
1072 if (parser()->context.token->name!="see" || !isXmlLink)
1073 {
1074 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"Unexpected xml/html command {} found as part of a \\link",
1075 parser()->context.token->name);
1076 }
1077 goto endlink;
1078 case TokenRetval::TK_LNKWORD:
1079 case TokenRetval::TK_WORD:
1080 if (isJavaLink) // special case to detect closing }
1081 {
1082 DString w = parser()->context.token->name;
1083 size_t p = 0;
1084 if (w=="}")
1085 {
1086 goto endlink;
1087 }
1088 else if ((p=w.find('}'))!=DString::npos)
1089 {
1090 size_t l = w.length();
1091 children().append<DocWord>(parser(),thisVariant(),w.left(p));
1092 if (l>1 && p<l-1) // something left after the } (for instance a .)
1093 {
1094 result=w.right(l-p-1);
1095 }
1096 goto endlink;
1097 }
1098 }
1100 break;
1101 default:
1102 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"Unexpected token {}",tok.to_string());
1103 break;
1104 }
1105 }
1106 tok = parser()->tokenizer.lex();
1107 }
1108 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1109 {
1110 warn_doc_error(parser()->context.fileName,
1111 parser()->tokenizer.getLineNr(),
1112 "Unexpected end of comment while inside link command");
1113 }
1114endlink:
1115
1116 if (children().empty()) // no link text
1117 {
1118 children().append<DocWord>(parser(),thisVariant(),m_refText);
1119 }
1120
1122 return result;
1123}
AutoNodeStack(DocParser *parser, DocNodeVariant *node)
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:182
DString right(size_t len) const
Definition dstring.h:315
size_t find(char c, size_t pos=0) const
Definition dstring.h:243
DString left(size_t len) const
Definition dstring.h:310
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:155
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:51
const Mapper< CommandType > * cmdMapper
TokenInfo * token
Definition docparser_p.h:94

References DocNodeList::append(), AUTO_TRACE, AutoNodeStack::AutoNodeStack(), 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().

◆ 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: