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,
166};
167
168enum class HtmlTagType
169{
171
194 HTML_A = 22,
196 HTML_P = 24,
210 HTML_S = 38,
218
219 XML_CmdMask = 0x100,
220
244};
245
246
247/** Class representing a mapping from command names to command IDs. */
248template<typename T>
250{
251 public:
252 T map(const QCString &n) const
253 {
254 if (n.isEmpty()) return T::UNKNOWN;
255 QCString name = n;
256 if (!m_cs) name=name.lower();
257 auto it = m_map.find(name.str());
258 return it!=m_map.end() ? it->second : T::UNKNOWN;
259 }
260
261 QCString find(const T n) const
262 {
263 for (const auto &[name,id] : m_map)
264 {
265 T curVal = id;
266 // https://stackoverflow.com/a/15889501/1657886
267 if (curVal == n || (curVal == (static_cast<T>(static_cast<int>(n) | static_cast<int>(T::SIMPLESECT_BIT))))) return name.c_str();
268 }
269 return QCString();
270 }
271
272 Mapper(const CommandMap<T> &cm,bool caseSensitive) : m_map(cm), m_cs(caseSensitive)
273 {
274 }
275
276 private:
278 bool m_cs;
279};
280
281/** Namespace for the doxygen and HTML command mappers. */
282namespace Mappers
283{
284 extern const Mapper<CommandType> *cmdMapper;
286}
287
288#endif
Class representing a mapping from command names to command IDs.
Definition cmdmapper.h:250
QCString find(const T n) const
Definition cmdmapper.h:261
const CommandMap< T > & m_map
Definition cmdmapper.h:277
bool m_cs
Definition cmdmapper.h:278
Mapper(const CommandMap< T > &cm, bool caseSensitive)
Definition cmdmapper.h:272
T map(const QCString &n) const
Definition cmdmapper.h:252
This is an alternative implementation of QCString.
Definition qcstring.h:101
QCString lower() const
Definition qcstring.h:234
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
const std::string & str() const
Definition qcstring.h:537
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:169
Namespace for the doxygen and HTML command mappers.
const Mapper< HtmlTagType > * htmlTagMapper
const Mapper< CommandType > * cmdMapper