Doxygen
Loading...
Searching...
No Matches
DocRef Class Reference

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

#include <src/docnode.h>

Inheritance diagram for DocRef:
Collaboration diagram for DocRef:

Public Member Functions

 DocRef (DocParser *parser, DocNodeVariant *parent, const QCString &target, const QCString &context)
void parse (char cmdChar, const QCString &cmdName)
QCString file () const
QCString relPath () const
QCString ref () const
QCString anchor () const
QCString targetTitle () const
SectionType sectionType () const
bool hasLinkText () const
bool refToAnchor () const
bool refToSection () const
bool refToTable () const
bool isSubPage () 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

RefType m_refType = Unknown
SectionType m_sectionType = SectionType::Anchor
bool m_isSubPage = false
QCString m_file
QCString m_relPath
QCString m_ref
QCString m_anchor
QCString m_text

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 reference to some item.

Definition at line 777 of file docnode.h.

Constructor & Destructor Documentation

◆ DocRef()

DocRef::DocRef ( DocParser * parser,
DocNodeVariant * parent,
const QCString & target,
const QCString & context )

Definition at line 708 of file docnode.cpp.

708 :
710{
711 const Definition *compound = nullptr;
712 QCString anchor;
713 AUTO_TRACE("target='{}',context='{}'",target,context);
714 ASSERT(!target.isEmpty());
715 m_relPath = parser->context.relPath;
716 auto lang = parser->context.lang;
717 const SectionInfo *sec = SectionManager::instance().find(parser->context.prefix+target);
718 if (sec==nullptr && !parser->context.prefix.isEmpty())
719 {
720 sec = SectionManager::instance().find(target);
721 }
722
723 if (sec==nullptr && getLanguageFromFileName(target)==SrcLangExt::Markdown) // lookup as markdown file
724 {
726 }
727 if (sec) // ref to section or anchor
728 {
729 PageDef *pd = nullptr;
730 int secLevel = sec->type().level();
731 if (secLevel==SectionType::Page)
732 {
733 pd = Doxygen::pageLinkedMap->find(target);
734 }
735 m_text = sec->title();
736 if (m_text.isEmpty()) m_text = sec->label();
737
738 m_ref = sec->ref();
740 if (secLevel==SectionType::Anchor)
741 {
743 }
744 else if (secLevel==SectionType::Table)
745 {
747 }
748 else if (secLevel==SectionType::Requirement)
749 {
751 if (!Config_getBool(GENERATE_REQUIREMENTS))
752 {
753 m_file.clear(); // prevent link when there is no requirements page
754 }
755 }
756 else
757 {
759 }
760 m_isSubPage = pd && pd->hasParentPage();
761 if (secLevel!=SectionType::Page || m_isSubPage)
762 {
763 m_anchor = pd ? pd->getOutputFileBase() : sec->label();
764 }
765 m_sectionType = sec->type();
766 //printf("m_text=%s,m_ref=%s,m_file=%s,type=%d\n",
767 // qPrint(m_text),qPrint(m_ref),qPrint(m_file),m_refType);
768 AUTO_TRACE_EXIT("section");
769 return;
770 }
771 else if (Config_getBool(IMPLICIT_DIR_DOCS) && target.lower().endsWith("/readme.md"))
772 {
773 QCString dirTarget = target.left(target.length() - 9); // strip readme.md part
774 const auto &dd = Doxygen::dirLinkedMap->find(dirTarget);
775 if (dd)
776 {
777 m_text = target;
778 m_file = dd->getOutputFileBase();
779 AUTO_TRACE_EXIT("directory");
780 return;
781 }
782 }
783 else if (resolveLink(context,target,true,&compound,anchor,lang,parser->context.prefix))
784 {
785 bool isFile = compound ?
786 (compound->definitionType()==Definition::TypeFile ||
788 FALSE;
789 if (compound && lang==SrcLangExt::Markdown) lang = compound->getLanguage();
790 m_text = linkToText(lang,target,isFile);
792 if (compound && compound->isLinkable()) // ref to compound
793 {
794 if (anchor.isEmpty() && /* compound link */
795 compound->definitionType()==Definition::TypeGroup && /* is group */
796 !toGroupDef(compound)->groupTitle().isEmpty() /* with title */
797 )
798 {
799 m_text=(toGroupDef(compound))->groupTitle(); // use group's title as link
800 }
801 else if (compound->definitionType()==Definition::TypeMember &&
802 toMemberDef(compound)->isObjCMethod())
803 {
804 // Objective C Method
805 const MemberDef *member = toMemberDef(compound);
806 bool localLink = parser->context.memberDef ? member->getClassDef()==parser->context.memberDef->getClassDef() : FALSE;
807 m_text = member->objCMethodName(localLink,parser->context.inSeeBlock);
808 }
809 else if (Config_getBool(HIDE_SCOPE_NAMES))
810 {
811 int funcPos = m_text.find('(');
812 if (funcPos!=-1) // see issue #11834
813 {
814 m_text=stripScope(m_text.left(funcPos))+m_text.mid(funcPos);
815 }
816 else
817 {
819 }
820 }
821
822 m_file = compound->getOutputFileBase();
823 m_ref = compound->getReference();
824 //printf("isFile=%d compound=%s (%d)\n",isFile,qPrint(compound->name()),
825 // compound->definitionType());
826 AUTO_TRACE_EXIT("compound");
827 return;
828 }
829 else if (compound && compound->definitionType()==Definition::TypeFile &&
830 toFileDef(compound)->generateSourceFile()
831 ) // undocumented file that has source code we can link to
832 {
833 m_file = compound->getSourceFileBase();
834 m_ref = compound->getReference();
835 AUTO_TRACE_EXIT("source");
836 return;
837 }
838 else
839 {
840 AUTO_TRACE_EXIT("compound '{}' not linkable",compound?compound->name():"none");
841 }
842 }
843 m_text = target;
844 warn_doc_error(parser->context.fileName,parser->tokenizer.getLineNr(),"unable to resolve reference to '{}' for \\ref command",
845 target);
846}
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
virtual bool isLinkable() const =0
virtual DefType definitionType() const =0
virtual QCString getReference() const =0
virtual QCString getSourceFileBase() const =0
virtual QCString getOutputFileBase() const =0
virtual const QCString & name() const =0
DocCompoundNode(DocParser *parser, DocNodeVariant *parent)
Definition docnode.h:141
DocParser * parser()
Definition docnode.h:98
DocNodeVariant * parent()
Definition docnode.h:90
@ Unknown
Definition docnode.h:110
@ Table
Definition docnode.h:110
@ Requirement
Definition docnode.h:110
@ Section
Definition docnode.h:110
@ Anchor
Definition docnode.h:110
QCString anchor() const
Definition docnode.h:785
QCString m_file
Definition docnode.h:798
SectionType m_sectionType
Definition docnode.h:796
QCString m_text
Definition docnode.h:802
QCString m_ref
Definition docnode.h:800
QCString m_relPath
Definition docnode.h:799
RefType m_refType
Definition docnode.h:795
QCString m_anchor
Definition docnode.h:801
bool m_isSubPage
Definition docnode.h:797
static PageLinkedMap * pageLinkedMap
Definition doxygen.h:99
static DirLinkedMap * dirLinkedMap
Definition doxygen.h:128
const T * find(const std::string &key) const
Definition linkedmap.h:47
virtual const ClassDef * getClassDef() const =0
virtual QCString objCMethodName(bool localLink, bool showStatic) const =0
virtual bool hasParentPage() const =0
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:166
QCString lower() const
Definition qcstring.h:249
bool endsWith(const char *s) const
Definition qcstring.h:524
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
QCString left(size_t len) const
Definition qcstring.h:229
QCString label() const
Definition section.h:69
QCString ref() const
Definition section.h:72
QCString fileName() const
Definition section.h:74
QCString title() const
Definition section.h:70
SectionType type() const
Definition section.h:71
static SectionManager & instance()
returns a reference to the singleton
Definition section.h:179
static constexpr int Anchor
Definition section.h:40
static constexpr int Table
Definition section.h:41
constexpr int level() const
Definition section.h:46
static constexpr int Requirement
Definition section.h:42
static constexpr int Page
Definition section.h:31
#define Config_getBool(name)
Definition config.h:33
#define AUTO_TRACE(...)
Definition docnode.cpp:47
static QCString stripKnownExtensions(const QCString &text)
Definition docnode.cpp:104
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:49
FileDef * toFileDef(Definition *d)
Definition filedef.cpp:1967
GroupDef * toGroupDef(Definition *d)
QCString markdownFileNameToId(const QCString &fileName)
processes string s and converts markdown into doxygen/html commands.
MemberDef * toMemberDef(Definition *d)
#define warn_doc_error(file, line, fmt,...)
Definition message.h:112
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
#define ASSERT(x)
Definition qcstring.h:39
QCString linkToText(SrcLangExt lang, const QCString &link, bool isFileName)
Definition util.cpp:2675
SrcLangExt getLanguageFromFileName(const QCString &fileName, SrcLangExt defLang)
Definition util.cpp:5191
QCString stripScope(const QCString &name)
Definition util.cpp:3760
bool resolveLink(const QCString &scName, const QCString &lr, bool, const Definition **resContext, QCString &resAnchor, SrcLangExt lang, const QCString &prefix)
Definition util.cpp:2701

References DocNode::Anchor, SectionType::Anchor, anchor(), ASSERT, AUTO_TRACE, AUTO_TRACE_EXIT, Config_getBool, Definition::definitionType(), Doxygen::dirLinkedMap, DocCompoundNode::DocCompoundNode(), QCString::endsWith(), FALSE, SectionInfo::fileName(), LinkedMap< T, Hash, KeyEqual, Map >::find(), MemberDef::getClassDef(), Definition::getLanguage(), getLanguageFromFileName(), Definition::getOutputFileBase(), Definition::getReference(), Definition::getSourceFileBase(), PageDef::hasParentPage(), SectionManager::instance(), QCString::isEmpty(), Definition::isLinkable(), SectionInfo::label(), QCString::left(), QCString::length(), SectionType::level(), linkToText(), QCString::lower(), m_anchor, m_file, m_isSubPage, m_ref, m_refType, m_relPath, m_sectionType, m_text, markdownFileNameToId(), Definition::name(), MemberDef::objCMethodName(), SectionType::Page, Doxygen::pageLinkedMap, DocNode::parent(), DocNode::parser(), SectionInfo::ref(), DocNode::Requirement, SectionType::Requirement, resolveLink(), DocNode::Section, stripKnownExtensions(), stripScope(), DocNode::Table, SectionType::Table, SectionInfo::title(), toFileDef(), toGroupDef(), toMemberDef(), TRUE, SectionInfo::type(), Definition::TypeFile, Definition::TypeGroup, Definition::TypeMember, Definition::TypePage, DocNode::Unknown, and warn_doc_error.

Member Function Documentation

◆ anchor()

◆ file()

◆ hasLinkText()

bool DocRef::hasLinkText ( ) const
inline

◆ isSubPage()

bool DocRef::isSubPage ( ) const
inline

◆ parse()

void DocRef::parse ( char cmdChar,
const QCString & cmdName )

Definition at line 889 of file docnode.cpp.

890{
891 AUTO_TRACE();
892 auto ns = AutoNodeStack(parser(),thisVariant());
893 char cmdCharStr[2] = { cmdChar, 0 };
894
895 Token tok = parser()->tokenizer.lex();
896 while (!tok.is_any_of(TokenRetval::TK_NONE, TokenRetval::TK_EOF))
897 {
898 if (!parser()->defaultHandleToken(thisVariant(),tok,children()))
899 {
900 switch (tok.value())
901 {
902 case TokenRetval::TK_HTMLTAG:
903 break;
904 default:
905 parser()->errorHandleDefaultToken(thisVariant(),tok,children(),cmdCharStr+cmdName);
906 break;
907 }
908 }
909 tok=parser()->tokenizer.lex();
910 }
911
912 if (children().empty() && !m_text.isEmpty())
913 {
914 QCString text = m_text;
915 if (parser()->context.insideHtmlLink)
916 {
917 // we already in a link/title only output anchor
918 text = m_anchor;
919 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),
920 "Potential recursion while resolving {:c}{} command!",cmdChar,cmdName);
921 }
923 parser()->pushContext();
925 parser()->popContext();
929 }
930
932}
DocNodeVariant * thisVariant()
Definition docnode.h:93
DocTokenizer tokenizer
Token internalValidatingParseDoc(DocNodeVariant *parent, DocNodeList &children, const QCString &doc)
void handlePendingStyleCommands(DocNodeVariant *parent, DocNodeList &children)
void popContext()
Definition docparser.cpp:75
DocParserContext context
void pushContext()
Definition docparser.cpp:60
void errorHandleDefaultToken(DocNodeVariant *parent, Token tok, DocNodeList &children, const QCString &txt)
void setStatePara()
TokenRetval value() const
bool is_any_of(ARGS... args) const
static void flattenParagraphs(DocNodeVariant *root, DocNodeList &children)
Definition docnode.cpp:857

References AUTO_TRACE, DocCompoundNode::children(), DocParser::context, DocParser::errorHandleDefaultToken(), FALSE, flattenParagraphs(), DocParser::handlePendingStyleCommands(), DocParserContext::insideHtmlLink, DocParser::internalValidatingParseDoc(), Token::is_any_of(), DocTokenizer::lex(), m_anchor, m_text, DocNode::parser(), DocParser::popContext(), DocParser::pushContext(), DocTokenizer::setStatePara(), DocNode::thisVariant(), DocParser::tokenizer, TRUE, Token::value(), and warn_doc_error.

◆ ref()

◆ refToAnchor()

bool DocRef::refToAnchor ( ) const
inline

Definition at line 789 of file docnode.h.

789{ return m_refType==Anchor; }

References DocNode::Anchor, and m_refType.

Referenced by PrintDocVisitor::operator()().

◆ refToSection()

bool DocRef::refToSection ( ) const
inline

Definition at line 790 of file docnode.h.

790{ return m_refType==Section; }

References m_refType, and DocNode::Section.

Referenced by LatexDocVisitor::operator()(), and PrintDocVisitor::operator()().

◆ refToTable()

bool DocRef::refToTable ( ) const
inline

Definition at line 791 of file docnode.h.

791{ return m_refType==Table; }

References m_refType, and DocNode::Table.

Referenced by LatexDocVisitor::operator()(), and PrintDocVisitor::operator()().

◆ relPath()

QCString DocRef::relPath ( ) const
inline

Definition at line 783 of file docnode.h.

783{ return m_relPath; }

References m_relPath.

Referenced by HtmlDocVisitor::operator()().

◆ sectionType()

SectionType DocRef::sectionType ( ) const
inline

Definition at line 787 of file docnode.h.

787{ return m_sectionType; }

References m_sectionType.

Referenced by LatexDocVisitor::operator()().

◆ targetTitle()

Member Data Documentation

◆ m_anchor

QCString DocRef::m_anchor
private

Definition at line 801 of file docnode.h.

Referenced by anchor(), DocRef(), and parse().

◆ m_file

QCString DocRef::m_file
private

Definition at line 798 of file docnode.h.

Referenced by DocRef(), and file().

◆ m_isSubPage

bool DocRef::m_isSubPage = false
private

Definition at line 797 of file docnode.h.

Referenced by DocRef(), and isSubPage().

◆ m_ref

QCString DocRef::m_ref
private

Definition at line 800 of file docnode.h.

Referenced by DocRef(), and ref().

◆ m_refType

RefType DocRef::m_refType = Unknown
private

Definition at line 795 of file docnode.h.

Referenced by DocRef(), refToAnchor(), refToSection(), and refToTable().

◆ m_relPath

QCString DocRef::m_relPath
private

Definition at line 799 of file docnode.h.

Referenced by DocRef(), and relPath().

◆ m_sectionType

SectionType DocRef::m_sectionType = SectionType::Anchor
private

Definition at line 796 of file docnode.h.

Referenced by DocRef(), and sectionType().

◆ m_text

QCString DocRef::m_text
private

Definition at line 802 of file docnode.h.

Referenced by DocRef(), parse(), and targetTitle().


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