Doxygen
Loading...
Searching...
No Matches
tooltip.cpp
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Copyright (C) 1997-2020 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15
16#include <map>
17#include <memory>
18#include <unordered_map>
19#include <unordered_set>
20#include <string>
21#include <mutex>
22
23#include "tooltip.h"
24#include "definition.h"
25#include "outputlist.h"
26#include "util.h"
27#include "filedef.h"
28#include "doxygen.h"
29#include "config.h"
30
31static std::mutex g_tooltipsFileMutex;
32static std::mutex g_tooltipsTipMutex;
33static std::unordered_map<int, std::unordered_set<std::string> > g_tooltipsWrittenPerFile;
34
36{
37 public:
38 std::map<std::string,const Definition*> tooltipInfo;
39};
40
42{
43}
44
48
49static DString escapeId(const DString &s)
50{
51 DString res=s;
52 for (size_t i=0;i<res.length();i++) if (!isId(res[i])) res[i]='_';
53 return res;
54}
55
57{
58 bool sourceTooltips = Config_getBool(SOURCE_TOOLTIPS);
59 if (!sourceTooltips) return;
60
61 DString id = d->getOutputFileBase();
62 if (size_t i=id.rfind('/'); i!=DString::npos)
63 {
64 id = id.mid(i+1); // strip path (for CREATE_SUBDIRS=YES)
65 }
66 // In case an extension is present translate this extension to something understood by the tooltip handler
67 // otherwise extend t with a translated htmlFileExtension.
68 DString currentExtension = getFileNameExtension(id);
69 if (currentExtension.empty())
70 {
72 }
73 else
74 {
75 id = stripExtensionGeneral(id,currentExtension) + escapeId(currentExtension);
76 }
77
78 DString anc = d->anchor();
79 if (!anc.empty())
80 {
81 id+="_"+anc;
82 }
83 id = "a" + id;
84 p->tooltipInfo.emplace(id.str(),d);
85 //printf("%p: addTooltip(%s)\n",this,id.data());
86}
87
89{
90 std::unordered_map<int, std::unordered_set<std::string> >::iterator it;
91 // critical section
92 {
93 std::lock_guard<std::mutex> lock(g_tooltipsFileMutex);
94
95 int id = ol.id();
96 it = g_tooltipsWrittenPerFile.find(id);
97 if (it==g_tooltipsWrittenPerFile.end()) // new file
98 {
99 it = g_tooltipsWrittenPerFile.emplace(id,std::unordered_set<std::string>()).first;
100 }
101 }
102
103 for (const auto &[name,d] : p->tooltipInfo)
104 {
105 bool written = false;
106
107 // critical section
108 {
109 std::lock_guard<std::mutex> lock(g_tooltipsTipMutex);
110 written = it->second.find(name)!=it->second.end();
111 if (!written) // only write tooltips once
112 {
113 it->second.insert(name); // remember we wrote this tooltip for the given file id
114 }
115 }
116
117 if (!written)
118 {
119 //printf("%p: writeTooltips(%s) ol=%d\n",this,qPrint(name),ol.id());
120 DocLinkInfo docInfo;
121 docInfo.name = d->qualifiedName();
122 docInfo.ref = d->getReference();
123 docInfo.url = d->getOutputFileBase();
124 docInfo.anchor = d->anchor();
125 SourceLinkInfo defInfo;
126 if (d->getBodyDef() && d->getStartBodyLine()!=-1)
127 {
128 defInfo.file = d->getBodyDef()->name();
129 defInfo.line = d->getStartBodyLine();
130 defInfo.url = d->getSourceFileBase();
131 defInfo.anchor = d->getSourceAnchor();
132 }
133 SourceLinkInfo declInfo; // TODO: fill in...
134 DString decl;
135 if (d->definitionType()==Definition::TypeMember)
136 {
137 const MemberDef *md = toMemberDef(d);
138 if (!md->isAnonymous())
139 {
140 decl = md->declaration();
141 }
142 }
143 ol.writeTooltip(name, // id
144 docInfo, // symName
145 decl, // decl
146 d->briefDescriptionAsTooltip(), // desc
147 defInfo,
148 declInfo
149 );
150 }
151 }
152}
153
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:89
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:153
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:183
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:156
The common base class of all entity definitions found in the sources.
Definition definition.h:77
virtual bool isAnonymous() const =0
virtual DString anchor() const =0
virtual DString getOutputFileBase() const =0
static DString htmlFileExtension
Definition doxygen.h:122
A model of a class/file/namespace member symbol.
Definition memberdef.h:48
virtual DString declaration() const =0
Class representing a list of different code generators.
Definition outputlist.h:165
int id() const
Definition outputlist.h:192
void writeTooltip(const DString &id, const DocLinkInfo &docInfo, const DString &decl, const DString &desc, const SourceLinkInfo &defInfo, const SourceLinkInfo &declInfo)
Definition outputlist.h:260
std::map< std::string, const Definition * > tooltipInfo
Definition tooltip.cpp:38
void addTooltip(const Definition *d)
add a tooltip for a given symbol definition
Definition tooltip.cpp:56
void writeTooltips(OutputCodeList &ol)
write the list of all collected tooltip to the given outputs
Definition tooltip.cpp:88
std::unique_ptr< Private > p
Definition tooltip.h:40
#define Config_getBool(name)
Definition config.h:33
MemberDef * toMemberDef(Definition *d)
Definition dstring.h:879
static std::mutex g_tooltipsFileMutex
Definition tooltip.cpp:31
static DString escapeId(const DString &s)
Definition tooltip.cpp:49
static std::mutex g_tooltipsTipMutex
Definition tooltip.cpp:32
static std::unordered_map< int, std::unordered_set< std::string > > g_tooltipsWrittenPerFile
Definition tooltip.cpp:33
DString stripExtensionGeneral(const DString &fName, const DString &ext)
Definition util.cpp:4983
DString getFileNameExtension(const DString &fn)
Definition util.cpp:5300
A bunch of utility functions.
bool isId(int c)
Definition util.h:257