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,
217
218 XML_CmdMask = 0x100,
219
243};
244
245
246/** Class representing a mapping from command names to command IDs. */
247template<typename T>
249{
250 public:
251 T map(const QCString &n) const
252 {
253 if (n.isEmpty()) return T::UNKNOWN;
254 QCString name = n;
255 if (!m_cs) name=name.lower();
256 auto it = m_map.find(name.str());
257 return it!=m_map.end() ? it->second : T::UNKNOWN;
258 }
259
260 QCString find(const T n) const
261 {
262 for (const auto &[name,id] : m_map)
263 {
264 T curVal = id;
265 // https://stackoverflow.com/a/15889501/1657886
266 if (curVal == n || (curVal == (static_cast<T>(static_cast<int>(n) | static_cast<int>(T::SIMPLESECT_BIT))))) return name.c_str();
267 }
268 return QCString();
269 }
270
271 Mapper(const CommandMap<T> &cm,bool caseSensitive) : m_map(cm), m_cs(caseSensitive)
272 {
273 }
274
275 private:
277 bool m_cs;
278};
279
280/** Namespace for the doxygen and HTML command mappers. */
281namespace Mappers
282{
283 extern const Mapper<CommandType> *cmdMapper;
285}
286
287#endif
Class representing a mapping from command names to command IDs.
Definition cmdmapper.h:249
QCString find(const T n) const
Definition cmdmapper.h:260
const CommandMap< T > & m_map
Definition cmdmapper.h:276
bool m_cs
Definition cmdmapper.h:277
Mapper(const CommandMap< T > &cm, bool caseSensitive)
Definition cmdmapper.h:271
T map(const QCString &n) const
Definition cmdmapper.h:251
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