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 <memory>
20#include <string>
21#include <unordered_map>
22
23#include "dstring.h"
24
25template<typename T>
26using CommandMap = std::unordered_map< std::string, T >;
27
28
29enum class CommandType
30{
32
37 CMD_AT = 4,
70 CMD_LI = 37,
80 CMD_REF = 47,
137 CMD_PUNT = 104,
138 CMD_PLUS = 105,
171};
172
173enum class HtmlTagType
174{
176
199 HTML_A = 22,
201 HTML_P = 24,
215 HTML_S = 38,
223
224 XML_CmdMask = 0x100,
225
249};
250
251
252/** Class representing a mapping from command names to command IDs. */
253template<typename T>
255{
256 public:
257 T map(const DString &n) const
258 {
259 if (n.empty()) return T::UNKNOWN;
260 DString name = n;
261 if (!m_cs) name=name.lower();
262 auto it = m_map.find(name.str());
263 return it!=m_map.end() ? it->second : T::UNKNOWN;
264 }
265
266 DString find(const T n) const
267 {
268 DString result;
269 for (const auto &[name,id] : m_map)
270 {
271 T curVal = id;
272 // https://stackoverflow.com/a/15889501/1657886
273 if (curVal == n || (curVal == (static_cast<T>(static_cast<int>(n) | static_cast<int>(T::SIMPLESECT_BIT)))))
274 {
275 result = name;
276 break;
277 }
278 }
279 return result;
280 }
281
282 Mapper(const CommandMap<T> &cm,bool caseSensitive) : m_map(cm), m_cs(caseSensitive)
283 {
284 }
285
286 private:
288 bool m_cs;
289};
290
291/** Namespace for the doxygen and HTML command mappers. */
292namespace Mappers
293{
294 extern const Mapper<CommandType> *cmdMapper;
296}
297
298#endif
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:88
DString lower() const
Definition dstring.h:330
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:152
const std::string & str() const
Definition dstring.h:649
Class representing a mapping from command names to command IDs.
Definition cmdmapper.h:255
const CommandMap< T > & m_map
Definition cmdmapper.h:287
T map(const DString &n) const
Definition cmdmapper.h:257
bool m_cs
Definition cmdmapper.h:288
Mapper(const CommandMap< T > &cm, bool caseSensitive)
Definition cmdmapper.h:282
DString find(const T n) const
Definition cmdmapper.h:266
CommandType
Definition cmdmapper.h:30
@ CMD_ENDSECREFLIST
Definition cmdmapper.h:54
@ CMD_ENDLATEXONLY
Definition cmdmapper.h:52
@ CMD_ENDVERBATIM
Definition cmdmapper.h:55
@ CMD_DONTINCLUDE
Definition cmdmapper.h:47
@ CMD_SUBSUBSECTION
Definition cmdmapper.h:90
@ CMD_SUBSUBPARAGRAPH
Definition cmdmapper.h:162
@ CMD_INTERNALREF
Definition cmdmapper.h:66
@ CMD_ENDHTMLONLY
Definition cmdmapper.h:51
@ CMD_VERBINCLUDE
Definition cmdmapper.h:99
@ CMD_DOCBOOKINCLUDE
Definition cmdmapper.h:146
@ CMD_HTMLINCLUDE
Definition cmdmapper.h:61
@ CMD_SNIPWITHLINES
Definition cmdmapper.h:142
std::unordered_map< std::string, T > CommandMap
Definition cmdmapper.h:26
HtmlTagType
Definition cmdmapper.h:174
Namespace for the doxygen and HTML command mappers.
const Mapper< HtmlTagType > * htmlTagMapper
const Mapper< CommandType > * cmdMapper