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 QCString escapeId(const QCString &s)
50{
51 QCString 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 QCString id = d->getOutputFileBase();
62 int i=id.findRev('/');
63 if (i!=-1)
64 {
65 id = id.right(id.length()-i-1); // strip path (for CREATE_SUBDIRS=YES)
66 }
67 // In case an extension is present translate this extension to something understood by the tooltip handler
68 // otherwise extend t with a translated htmlFileExtension.
69 QCString currentExtension = getFileNameExtension(id);
70 if (currentExtension.isEmpty())
71 {
73 }
74 else
75 {
76 id = stripExtensionGeneral(id,currentExtension) + escapeId(currentExtension);
77 }
78
79 QCString anc = d->anchor();
80 if (!anc.isEmpty())
81 {
82 id+="_"+anc;
83 }
84 id = "a" + id;
85 p->tooltipInfo.emplace(id.str(),d);
86 //printf("%p: addTooltip(%s)\n",this,id.data());
87}
88
90{
91 std::unordered_map<int, std::unordered_set<std::string> >::iterator it;
92 // critical section
93 {
94 std::lock_guard<std::mutex> lock(g_tooltipsFileMutex);
95
96 int id = ol.id();
97 it = g_tooltipsWrittenPerFile.find(id);
98 if (it==g_tooltipsWrittenPerFile.end()) // new file
99 {
100 it = g_tooltipsWrittenPerFile.emplace(id,std::unordered_set<std::string>()).first;
101 }
102 }
103
104 for (const auto &[name,d] : p->tooltipInfo)
105 {
106 bool written = false;
107
108 // critical section
109 {
110 std::lock_guard<std::mutex> lock(g_tooltipsTipMutex);
111 written = it->second.find(name)!=it->second.end();
112 if (!written) // only write tooltips once
113 {
114 it->second.insert(name); // remember we wrote this tooltip for the given file id
115 }
116 }
117
118 if (!written)
119 {
120 //printf("%p: writeTooltips(%s) ol=%d\n",this,name.c_str(),ol.id());
121 DocLinkInfo docInfo;
122 docInfo.name = d->qualifiedName();
123 docInfo.ref = d->getReference();
124 docInfo.url = d->getOutputFileBase();
125 docInfo.anchor = d->anchor();
126 SourceLinkInfo defInfo;
127 if (d->getBodyDef() && d->getStartBodyLine()!=-1)
128 {
129 defInfo.file = d->getBodyDef()->name();
130 defInfo.line = d->getStartBodyLine();
131 defInfo.url = d->getSourceFileBase();
132 defInfo.anchor = d->getSourceAnchor();
133 }
134 SourceLinkInfo declInfo; // TODO: fill in...
135 QCString decl;
136 if (d->definitionType()==Definition::TypeMember)
137 {
138 const MemberDef *md = toMemberDef(d);
139 if (!md->isAnonymous())
140 {
141 decl = md->declaration();
142 }
143 }
144 ol.writeTooltip(name.c_str(), // id
145 docInfo, // symName
146 decl, // decl
147 d->briefDescriptionAsTooltip(), // desc
148 defInfo,
149 declInfo
150 );
151 }
152 }
153}
154
The common base class of all entity definitions found in the sources.
Definition definition.h:76
virtual QCString anchor() const =0
virtual bool isAnonymous() const =0
virtual QCString getOutputFileBase() const =0
static QCString htmlFileExtension
Definition doxygen.h:122
virtual QCString declaration() const =0
Class representing a list of different code generators.
Definition outputlist.h:164
int id() const
Definition outputlist.h:191
void writeTooltip(const QCString &id, const DocLinkInfo &docInfo, const QCString &decl, const QCString &desc, const SourceLinkInfo &defInfo, const SourceLinkInfo &declInfo)
Definition outputlist.h:259
This is an alternative implementation of QCString.
Definition qcstring.h:101
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition qcstring.cpp:91
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:89
std::unique_ptr< Private > p
Definition tooltip.h:40
#define Config_getBool(name)
Definition config.h:33
MemberDef * toMemberDef(Definition *d)
static std::mutex g_tooltipsFileMutex
Definition tooltip.cpp:31
static QCString escapeId(const QCString &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
QCString stripExtensionGeneral(const QCString &fName, const QCString &ext)
Definition util.cpp:5255
QCString getFileNameExtension(const QCString &fn)
Definition util.cpp:5591
A bunch of utility functions.
bool isId(int c)
Definition util.h:202