cmdmapper.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  *
4  *
5  *
6  * Copyright (C) 1997-2015 by Dimitri van Heesch.
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation under the terms of the GNU General Public License is hereby
10  * granted. No representations are made about the suitability of this software
11  * for any purpose. It is provided "as is" without express or implied warranty.
12  * See the GNU General Public License for more details.
13  *
14  * Documents produced by Doxygen are derivative works derived from the
15  * input used in their production; they are not affected by this license.
16  *
17  */
18 
19 #include "cmdmapper.h"
20 
21 /** Call representing a mapping from a command name to a command ID. */
22 struct CommandMap
23 {
24  const char *cmdName;
25  int cmdId;
26 };
27 
29 {
30  { "a", CMD_EMPHASIS },
31  { "addindex", CMD_ADDINDEX },
32  { "anchor", CMD_ANCHOR },
33  { "arg", CMD_LI },
34  { "attention", CMD_ATTENTION },
35  { "author", CMD_AUTHOR },
36  { "authors", CMD_AUTHORS },
37  { "b", CMD_BOLD },
38  { "c", CMD_CODE },
39  { "cite", CMD_CITE },
40  { "code", CMD_STARTCODE },
41  { "copydoc", CMD_COPYDOC },
42  { "copybrief", CMD_COPYBRIEF },
43  { "copydetails", CMD_COPYDETAILS },
44  { "copyright", CMD_COPYRIGHT },
45  { "date", CMD_DATE },
46  { "dontinclude", CMD_DONTINCLUDE },
47  { "dotfile", CMD_DOTFILE },
48  { "e", CMD_EMPHASIS },
49  { "em", CMD_EMPHASIS },
50  { "endcode", CMD_ENDCODE },
51  { "endhtmlonly", CMD_ENDHTMLONLY },
52  { "endlatexonly", CMD_ENDLATEXONLY },
53  { "endlink", CMD_ENDLINK },
54  { "endsecreflist", CMD_ENDSECREFLIST },
55  { "endverbatim", CMD_ENDVERBATIM },
56  { "endxmlonly", CMD_ENDXMLONLY },
57  { "exception", CMD_EXCEPTION },
58  { "form", CMD_FORMULA },
59  { "htmlinclude", CMD_HTMLINCLUDE },
60  { "htmlonly", CMD_HTMLONLY },
61  { "image", CMD_IMAGE },
62  { "include", CMD_INCLUDE },
63  { "internal", CMD_INTERNAL },
64  { "invariant", CMD_INVARIANT },
65  { "javalink", CMD_JAVALINK },
66  { "latexinclude", CMD_LATEXINCLUDE },
67  { "latexonly", CMD_LATEXONLY },
68  { "li", CMD_LI },
69  { "line", CMD_LINE },
70  { "link", CMD_LINK },
71  { "n", CMD_LINEBREAK },
72  { "note", CMD_NOTE },
73  { "p", CMD_CODE },
74  { "par", CMD_PAR },
75  { "param", CMD_PARAM },
76  { "post", CMD_POST },
77  { "pre", CMD_PRE },
78  { "ref", CMD_REF },
79  { "refitem", CMD_SECREFITEM },
80  { "remark", CMD_REMARK },
81  { "remarks", CMD_REMARK },
82  { "result", CMD_RETURN },
83  { "return", CMD_RETURN },
84  { "returns", CMD_RETURN },
85  { "retval", CMD_RETVAL },
86  { "rtfonly", CMD_RTFONLY },
87  { "sa", CMD_SA },
88  { "secreflist", CMD_SECREFLIST },
89  { "section", CMD_SECTION },
90  { "snippet", CMD_SNIPPET },
91  { "subpage", CMD_SUBPAGE },
92  { "subsection", CMD_SUBSECTION },
93  { "subsubsection", CMD_SUBSUBSECTION },
94  { "paragraph", CMD_PARAGRAPH },
95  { "see", CMD_SA },
96  { "since", CMD_SINCE },
97  { "skip", CMD_SKIP },
98  { "skipline", CMD_SKIPLINE },
99  { "xmlonly", CMD_XMLONLY },
100  { "xrefitem", CMD_XREFITEM },
101  { "throw", CMD_EXCEPTION },
102  { "until", CMD_UNTIL },
103  { "verbatim", CMD_VERBATIM },
104  { "verbinclude", CMD_VERBINCLUDE },
105  { "version", CMD_VERSION },
106  { "warning", CMD_WARNING },
107  { "throws", CMD_EXCEPTION },
108  { "tparam", CMD_TPARAM },
109  { "\\", CMD_BSLASH },
110  { "@", CMD_AT },
111  { "<", CMD_LESS },
112  { ">", CMD_GREATER },
113  { "&", CMD_AMP },
114  { "$", CMD_DOLLAR },
115  { "#", CMD_HASH },
116  { "%", CMD_PERCENT },
117  { "|", CMD_PIPE },
118  { ".", CMD_PUNT },
119  { "+", CMD_PLUS },
120  { "-", CMD_MINUS },
121  { "::", CMD_DCOLON },
122  { "\"", CMD_QUOTE },
123  { "_internalref", CMD_INTERNALREF },
124  { "dot", CMD_DOT },
125  { "msc", CMD_MSC },
126  { "startuml", CMD_STARTUML },
127  { "enddot", CMD_ENDDOT },
128  { "endmsc", CMD_ENDMSC },
129  { "enduml", CMD_ENDUML },
130  { "manonly", CMD_MANONLY },
131  { "endmanonly", CMD_ENDMANONLY },
132  { "includelineno", CMD_INCWITHLINES },
133  { "inheritdoc", CMD_INHERITDOC },
134  { "mscfile", CMD_MSCFILE },
135  { "rtfonly", CMD_RTFONLY },
136  { "endrtfonly", CMD_ENDRTFONLY },
137  { "vhdlflow", CMD_VHDLFLOW },
138  { "docbookonly", CMD_DBONLY },
139  { "enddocbookonly",CMD_ENDDBONLY },
140  { "endinternal", CMD_ENDINTERNAL },
141  { "parblock", CMD_PARBLOCK },
142  { "endparblock", CMD_ENDPARBLOCK },
143  { "diafile", CMD_DIAFILE },
144  { "--", CMD_NDASH },
145  { "---", CMD_MDASH },
146  { "_setscope", CMD_SETSCOPE },
147  { 0, 0 },
148 };
149 
150 //----------------------------------------------------------------------------
151 
153 {
154  { "strong", HTML_BOLD },
155  { "center", HTML_CENTER },
156  { "table", HTML_TABLE },
157  { "caption", HTML_CAPTION },
158  { "small", HTML_SMALL },
159  { "code", HTML_CODE },
160  { "dfn", HTML_CODE },
161  { "var", HTML_EMPHASIS },
162  { "img", HTML_IMG },
163  { "pre", HTML_PRE },
164  { "sub", HTML_SUB },
165  { "sup", HTML_SUP },
166  { "tr", HTML_TR },
167  { "td", HTML_TD },
168  { "th", HTML_TH },
169  { "ol", HTML_OL },
170  { "ul", HTML_UL },
171  { "li", HTML_LI },
172  { "tt", XML_C /*HTML_CODE*/ },
173  { "kbd", XML_C /*HTML_CODE*/ },
174  { "em", HTML_EMPHASIS },
175  { "hr", HTML_HR },
176  { "dl", HTML_DL },
177  { "dt", HTML_DT },
178  { "dd", HTML_DD },
179  { "br", HTML_BR },
180  { "i", HTML_EMPHASIS },
181  { "a", HTML_A },
182  { "b", HTML_BOLD },
183  { "p", HTML_P },
184  { "h1", HTML_H1 },
185  { "h2", HTML_H2 },
186  { "h3", HTML_H3 },
187  { "h4", HTML_H4 },
188  { "h5", HTML_H5 },
189  { "h6", HTML_H6 },
190  { "span", HTML_SPAN },
191  { "div", HTML_DIV },
192  { "blockquote", HTML_BLOCKQUOTE },
193 
194  { "c", XML_C },
195  // { "code", XML_CODE }, <= ambiguous <code> is also a HTML tag
196  { "description", XML_DESCRIPTION },
197  { "example", XML_EXAMPLE },
198  { "exception", XML_EXCEPTION },
199  { "include", XML_INCLUDE },
200  { "item", XML_ITEM },
201  { "list", XML_LIST }, // type="table|bullet|number"
202  { "listheader", XML_LISTHEADER },
203  { "para", XML_PARA },
204  { "param", XML_PARAM },
205  { "paramref", XML_PARAMREF },
206  { "typeparam", XML_TYPEPARAM },
207  { "typeparamref", XML_TYPEPARAMREF },
208  { "permission", XML_PERMISSION },
209  { "remarks", XML_REMARKS },
210  { "returns", XML_RETURNS },
211  { "see", XML_SEE },
212  { "seealso", XML_SEEALSO },
213  { "summary", XML_SUMMARY },
214  { "term", XML_TERM },
215  { "value", XML_VALUE },
216  { "inheritdoc", XML_INHERITDOC },
217  { 0, 0 }
218 };
219 
220 //----------------------------------------------------------------------------
221 
222 Mapper *Mappers::cmdMapper = new Mapper(cmdMap,TRUE);
223 Mapper *Mappers::htmlTagMapper = new Mapper(htmlTagMap,FALSE);
224 
225 int Mapper::map(const char *n)
226 {
227  QCString name=n;
228  if (!m_cs) name=name.lower();
229  int *result;
230  return !name.isEmpty() && (result=m_map.find(name)) ? *result: 0;
231 }
232 
234 {
235  QDictIterator<int> mapIterator(m_map);
236  for (int *curVal = mapIterator.toFirst();(curVal = mapIterator.current());++mapIterator)
237  {
238  if (*curVal == n || (*curVal == (n | SIMPLESECT_BIT))) return mapIterator.currentKey();
239  }
240  return NULL;
241 }
242 
243 Mapper::Mapper(const CommandMap *cm,bool caseSensitive) : m_map(89), m_cs(caseSensitive)
244 {
245  m_map.setAutoDelete(TRUE);
246  const CommandMap *p = cm;
247  while (p->cmdName)
248  {
249  m_map.insert(p->cmdName,new int(p->cmdId));
250  p++;
251  }
252 }
253 
255 {
256  delete cmdMapper; cmdMapper = 0;
257  delete htmlTagMapper; htmlTagMapper = 0;
258 }
259 
260 
static constexpr double cm
Definition: Units.h:68
static QCString name
Definition: declinfo.cpp:673
Mapper(const CommandMap *cm, bool caseSensitive)
Definition: cmdmapper.cpp:243
static QCString result
bool isEmpty() const
Definition: qcstring.h:189
const bool FALSE
Definition: qglobal.h:370
static Mapper * htmlTagMapper
Definition: cmdmapper.h:220
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
const int SIMPLESECT_BIT
Definition: cmdmapper.h:26
QDict< int > m_map
Definition: cmdmapper.h:211
QString find(const int n)
Definition: cmdmapper.cpp:233
CommandMap htmlTagMap[]
Definition: cmdmapper.cpp:152
static void freeMappers()
Definition: cmdmapper.cpp:254
std::void_t< T > n
CommandMap cmdMap[]
Definition: cmdmapper.cpp:28
p
Definition: test.py:223
int map(const char *n)
Definition: cmdmapper.cpp:225
static Mapper * cmdMapper
Definition: cmdmapper.h:219
const char * cmdName
Definition: cmdmapper.cpp:24
QCString lower() const
Definition: qcstring.cpp:263
const bool TRUE
Definition: qglobal.h:371