Doxygen
Loading...
Searching...
No Matches
cmdmapper.h
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Copyright (C) 1997-2023 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#ifndef CMDMAPPER_H
17#define CMDMAPPER_H
18
19#include <unordered_map>
20#include <string>
21#include <memory>
22#include "qcstring.h"
23
24template<typename T>
25using CommandMap = std::unordered_map< std::string, T >;
26
27
28enum class CommandType
29{
31
36 CMD_AT = 4,
69 CMD_LI = 37,
79 CMD_REF = 47,
136 CMD_PUNT = 104,
137 CMD_PLUS = 105,
170};
171
172enum class HtmlTagType
173{
175
198 HTML_A = 22,
200 HTML_P = 24,
214 HTML_S = 38,
222
223 XML_CmdMask = 0x100,
224
248};
249
250
251/** Class representing a mapping from command names to command IDs. */
252template<typename T>
254{
255 public:
256 T map(const QCString &n) const
257 {
258 if (n.isEmpty()) return T::UNKNOWN;
259 QCString name = n;
260 if (!m_cs) name=name.lower();
261 auto it = m_map.find(name.str());
262 return it!=m_map.end() ? it->second : T::UNKNOWN;
263 }
264
265 QCString find(const T n) const
266 {
267 QCString result;
268 for (const auto &[name,id] : m_map)
269 {
270 T curVal = id;
271 // https://stackoverflow.com/a/15889501/1657886
272 if (curVal == n || (curVal == (static_cast<T>(static_cast<int>(n) | static_cast<int>(T::SIMPLESECT_BIT)))))
273 {
274 result = name;
275 break;
276 }
277 }
278 return result;
279 }
280
281 Mapper(const CommandMap<T> &cm,bool caseSensitive) : m_map(cm), m_cs(caseSensitive)
282 {
283 }
284
285 private:
287 bool m_cs;
288};
289
290/** Namespace for the doxygen and HTML command mappers. */
291namespace Mappers
292{
293 extern const Mapper<CommandType> *cmdMapper;
295}
296
297#endif
Class representing a mapping from command names to command IDs.
Definition cmdmapper.h:254
QCString find(const T n) const
Definition cmdmapper.h:265
const CommandMap< T > & m_map
Definition cmdmapper.h:286
bool m_cs
Definition cmdmapper.h:287
Mapper(const CommandMap< T > &cm, bool caseSensitive)
Definition cmdmapper.h:281
T map(const QCString &n) const
Definition cmdmapper.h:256
This is an alternative implementation of QCString.
Definition qcstring.h:101
QCString lower() const
Definition qcstring.h:249
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
const std::string & str() const
Definition qcstring.h:552
CommandType
Definition cmdmapper.h:29
@ CMD_ENDSECREFLIST
Definition cmdmapper.h:53
@ CMD_ENDLATEXONLY
Definition cmdmapper.h:51
@ CMD_ENDVERBATIM
Definition cmdmapper.h:54
@ CMD_DONTINCLUDE
Definition cmdmapper.h:46
@ CMD_SUBSUBSECTION
Definition cmdmapper.h:89
@ CMD_SUBSUBPARAGRAPH
Definition cmdmapper.h:161
@ CMD_INTERNALREF
Definition cmdmapper.h:65
@ CMD_ENDHTMLONLY
Definition cmdmapper.h:50
@ CMD_VERBINCLUDE
Definition cmdmapper.h:98
@ CMD_DOCBOOKINCLUDE
Definition cmdmapper.h:145
@ CMD_HTMLINCLUDE
Definition cmdmapper.h:60
@ CMD_SNIPWITHLINES
Definition cmdmapper.h:141
std::unordered_map< std::string, T > CommandMap
Definition cmdmapper.h:25
HtmlTagType
Definition cmdmapper.h:173
Namespace for the doxygen and HTML command mappers.
const Mapper< HtmlTagType > * htmlTagMapper
const Mapper< CommandType > * cmdMapper