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// own header
17#include "tooltip.h"
18
19// standard includes
20#include <map>
21#include <memory>
22#include <mutex>
23#include <string>
24#include <unordered_map>
25#include <unordered_set>
26
27// other includes
28#include "config.h"
29#include "definition.h"
30#include "doxygen.h"
31#include "filedef.h"
32#include "outputlist.h"
33#include "util.h"
34
35static std::mutex g_tooltipsFileMutex;
36static std::mutex g_tooltipsTipMutex;
37static std::unordered_map<int, std::unordered_set<std::string> > g_tooltipsWrittenPerFile;
38
40{
41 public:
42 std::map<std::string,const Definition*> tooltipInfo;
43};
44
46{
47}
48
52
53static DString escapeId(const DString &s)
54{
55 DString res=s;
56 for (size_t i=0;i<res.length();i++) if (!isId(res[i])) res[i]='_';
57 return res;
58}
59
61{
62 bool sourceTooltips = Config_getBool(SOURCE_TOOLTIPS);
63 if (!sourceTooltips) return;
64
65 DString id = d->getOutputFileBase();
66 if (size_t i=id.rfind('/'); i!=DString::npos)
67 {
68 id = id.mid(i+1); // strip path (for CREATE_SUBDIRS=YES)
69 }
70 // In case an extension is present translate this extension to something understood by the tooltip handler
71 // otherwise extend t with a translated htmlFileExtension.
72 DString currentExtension = getFileNameExtension(id);
73 if (currentExtension.empty())
74 {
76 }
77 else
78 {
79 id = stripExtensionGeneral(id,currentExtension) + escapeId(currentExtension);
80 }
81
82 DString anc = d->anchor();
83 if (!anc.empty())
84 {
85 id+="_"+anc;
86 }
87 id = "a" + id;
88 p->tooltipInfo.emplace(id.str(),d);
89 //printf("%p: addTooltip(%s)\n",this,id.data());
90}
91
93{
94 std::unordered_map<int, std::unordered_set<std::string> >::iterator it;
95 // critical section
96 {
97 std::lock_guard<std::mutex> lock(g_tooltipsFileMutex);
98
99 int id = ol.id();
100 it = g_tooltipsWrittenPerFile.find(id);
101 if (it==g_tooltipsWrittenPerFile.end()) // new file
102 {
103 it = g_tooltipsWrittenPerFile.emplace(id,std::unordered_set<std::string>()).first;
104 }
105 }
106
107 for (const auto &[name,d] : p->tooltipInfo)
108 {
109 bool written = false;
110
111 // critical section
112 {
113 std::lock_guard<std::mutex> lock(g_tooltipsTipMutex);
114 written = it->second.find(name)!=it->second.end();
115 if (!written) // only write tooltips once
116 {
117 it->second.insert(name); // remember we wrote this tooltip for the given file id
118 }
119 }
120
121 if (!written)
122 {
123 //printf("%p: writeTooltips(%s) ol=%d\n",this,qPrint(name),ol.id());
124 DocLinkInfo docInfo;
125 docInfo.name = d->qualifiedName();
126 docInfo.ref = d->getReference();
127 docInfo.url = d->getOutputFileBase();
128 docInfo.anchor = d->anchor();
129 SourceLinkInfo defInfo;
130 if (d->getBodyDef() && d->getStartBodyLine()!=-1)
131 {
132 defInfo.file = d->getBodyDef()->name();
133 defInfo.line = d->getStartBodyLine();
134 defInfo.url = d->getSourceFileBase();
135 defInfo.anchor = d->getSourceAnchor();
136 }
137 SourceLinkInfo declInfo; // TODO: fill in...
138 DString decl;
139 if (d->definitionType()==Definition::TypeMember)
140 {
141 const MemberDef *md = toMemberDef(d);
142 if (!md->isAnonymous())
143 {
144 decl = md->declaration();
145 }
146 }
147 ol.writeTooltip(name, // id
148 docInfo, // symName
149 decl, // decl
150 d->briefDescriptionAsTooltip(), // desc
151 defInfo,
152 declInfo
153 );
154 }
155 }
156}
157
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
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
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:151
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:115
A model of a class/file/namespace member symbol.
Definition memberdef.h:45
virtual DString declaration() const =0
Class representing a list of different code generators.
Definition outputlist.h:162
int id() const
Definition outputlist.h:189
void writeTooltip(const DString &id, const DocLinkInfo &docInfo, const DString &decl, const DString &desc, const SourceLinkInfo &defInfo, const SourceLinkInfo &declInfo)
Definition outputlist.h:257
std::map< std::string, const Definition * > tooltipInfo
Definition tooltip.cpp:42
void addTooltip(const Definition *d)
add a tooltip for a given symbol definition
Definition tooltip.cpp:60
void writeTooltips(OutputCodeList &ol)
write the list of all collected tooltip to the given outputs
Definition tooltip.cpp:92
std::unique_ptr< Private > p
Definition tooltip.h:41
#define Config_getBool(name)
Definition config.h:33
bool isId(int c)
Returns true if c is a valid character for an identifier.
Definition dstring.h:895
MemberDef * toMemberDef(Definition *d)
Definition dstring.h:913
static std::mutex g_tooltipsFileMutex
Definition tooltip.cpp:35
static DString escapeId(const DString &s)
Definition tooltip.cpp:53
static std::mutex g_tooltipsTipMutex
Definition tooltip.cpp:36
static std::unordered_map< int, std::unordered_set< std::string > > g_tooltipsWrittenPerFile
Definition tooltip.cpp:37
DString stripExtensionGeneral(const DString &fName, const DString &ext)
Definition util.cpp:3945
DString getFileNameExtension(const DString &fn)
Definition util.cpp:4210
A bunch of utility functions.