summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitri van Heesch <doxygen@gmail.com>2021-01-05 19:52:57 (GMT)
committerDimitri van Heesch <doxygen@gmail.com>2021-01-22 20:45:18 (GMT)
commit532f1f394f28e0358cfa763737148565397a65c7 (patch)
treefcff847d44f687e347b27091d43622aa00e013f5
parent60adbd56db26f48a8fca8d057d9d27af8d69cd8d (diff)
downloadDoxygen-532f1f394f28e0358cfa763737148565397a65c7.zip
Doxygen-532f1f394f28e0358cfa763737148565397a65c7.tar.gz
Doxygen-532f1f394f28e0358cfa763737148565397a65c7.tar.bz2
Refactoring: modernize cmdmapper
-rw-r--r--src/cmdmapper.cpp29
-rw-r--r--src/cmdmapper.h46
2 files changed, 36 insertions, 39 deletions
diff --git a/src/cmdmapper.cpp b/src/cmdmapper.cpp
index 372ba5b..264a74b 100644
--- a/src/cmdmapper.cpp
+++ b/src/cmdmapper.cpp
@@ -1,13 +1,10 @@
/******************************************************************************
*
- *
- *
- *
- * Copyright (C) 1997-2015 by Dimitri van Heesch.
+ * Copyright (C) 1997-2021 by Dimitri van Heesch.
*
* Permission to use, copy, modify, and distribute this software and its
- * documentation under the terms of the GNU General Public License is hereby
- * granted. No representations are made about the suitability of this software
+ * documentation under the terms of the GNU General Public License is hereby
+ * granted. No representations are made about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
* See the GNU General Public License for more details.
*
@@ -233,34 +230,34 @@ CommandMap htmlTagMap[] =
//----------------------------------------------------------------------------
-Mapper *Mappers::cmdMapper = new Mapper(cmdMap,TRUE);
-Mapper *Mappers::htmlTagMapper = new Mapper(htmlTagMap,FALSE);
+Mapper *Mappers::cmdMapper = new Mapper(cmdMap,true);
+Mapper *Mappers::htmlTagMapper = new Mapper(htmlTagMap,false);
int Mapper::map(const char *n)
{
QCString name=n;
+ if (name.isEmpty()) return 0;
if (!m_cs) name=name.lower();
- int *result;
- return !name.isEmpty() && (result=m_map.find(name)) ? *result: 0;
+ auto it = m_map.find(name.str());
+ return it!=m_map.end() ? it->second : 0;
}
QCString Mapper::find(const int n)
{
- QDictIterator<int> mapIterator(m_map);
- for (int *curVal = mapIterator.toFirst();(curVal = mapIterator.current());++mapIterator)
+ for (const auto &kv : m_map)
{
- if (*curVal == n || (*curVal == (n | SIMPLESECT_BIT))) return mapIterator.currentKey();
+ int curVal = kv.second;
+ if (curVal == n || (curVal == (n | SIMPLESECT_BIT))) return kv.first.c_str();
}
return QCString();
}
-Mapper::Mapper(const CommandMap *cm,bool caseSensitive) : m_map(89), m_cs(caseSensitive)
+Mapper::Mapper(const CommandMap *cm,bool caseSensitive) : m_cs(caseSensitive)
{
- m_map.setAutoDelete(TRUE);
const CommandMap *p = cm;
while (p->cmdName)
{
- m_map.insert(p->cmdName,new int(p->cmdId));
+ m_map.insert(std::make_pair(p->cmdName,p->cmdId));
p++;
}
}
diff --git a/src/cmdmapper.h b/src/cmdmapper.h
index a86c20a..8cbf017 100644
--- a/src/cmdmapper.h
+++ b/src/cmdmapper.h
@@ -1,13 +1,10 @@
/******************************************************************************
*
- *
- *
- *
- * Copyright (C) 1997-2015 by Dimitri van Heesch.
+ * Copyright (C) 1997-2021 by Dimitri van Heesch.
*
* Permission to use, copy, modify, and distribute this software and its
- * documentation under the terms of the GNU General Public License is hereby
- * granted. No representations are made about the suitability of this software
+ * documentation under the terms of the GNU General Public License is hereby
+ * granted. No representations are made about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
* See the GNU General Public License for more details.
*
@@ -19,7 +16,9 @@
#ifndef _CMDMAPPER_H
#define _CMDMAPPER_H
-#include <qdict.h>
+#include <map>
+#include <string>
+#include <qcstring.h>
struct CommandMap;
@@ -28,9 +27,9 @@ const int SIMPLESECT_BIT = 0x1000;
enum CommandType
{
CMD_UNKNOWN = 0,
- CMD_ADDINDEX = 1,
+ CMD_ADDINDEX = 1,
CMD_AMP = 2,
- CMD_ANCHOR = 3,
+ CMD_ANCHOR = 3,
CMD_AT = 4,
CMD_ATTENTION = 5 | SIMPLESECT_BIT,
CMD_AUTHOR = 6 | SIMPLESECT_BIT,
@@ -38,18 +37,18 @@ enum CommandType
CMD_BOLD = 8,
CMD_BSLASH = 9,
CMD_CODE = 10,
- CMD_COPYDOC = 11,
+ CMD_COPYDOC = 11,
CMD_DATE = 12 | SIMPLESECT_BIT,
CMD_DOLLAR = 13,
- CMD_DONTINCLUDE = 14,
- CMD_DOTFILE = 15,
+ CMD_DONTINCLUDE = 14,
+ CMD_DOTFILE = 15,
CMD_EMPHASIS = 16,
- CMD_ENDCODE = 17,
- CMD_ENDHTMLONLY = 18,
- CMD_ENDLATEXONLY = 19,
- CMD_ENDLINK = 20,
+ CMD_ENDCODE = 17,
+ CMD_ENDHTMLONLY = 18,
+ CMD_ENDLATEXONLY = 19,
+ CMD_ENDLINK = 20,
CMD_ENDSECREFLIST= 21,
- CMD_ENDVERBATIM = 22,
+ CMD_ENDVERBATIM = 22,
CMD_ENDXMLONLY = 23,
CMD_EXCEPTION = 24 | SIMPLESECT_BIT,
CMD_FORMULA = 25,
@@ -57,9 +56,9 @@ enum CommandType
CMD_HASH = 27,
CMD_HTMLINCLUDE = 28,
CMD_HTMLONLY = 29,
- CMD_IMAGE = 30,
+ CMD_IMAGE = 30,
CMD_INCLUDE = 31,
- CMD_INTERNAL = 32,
+ CMD_INTERNAL = 32,
CMD_INTERNALREF = 33,
CMD_INVARIANT = 34 | SIMPLESECT_BIT ,
CMD_LATEXONLY = 35,
@@ -67,11 +66,11 @@ enum CommandType
CMD_LI = 37,
CMD_LINE = 38,
CMD_LINEBREAK = 39,
- CMD_LINK = 40,
+ CMD_LINK = 40,
CMD_NOTE = 41 | SIMPLESECT_BIT,
CMD_PAR = 42 | SIMPLESECT_BIT,
CMD_PARAM = 43 | SIMPLESECT_BIT,
- CMD_PERCENT = 44,
+ CMD_PERCENT = 44,
CMD_POST = 45 | SIMPLESECT_BIT,
CMD_PRE = 46 | SIMPLESECT_BIT,
CMD_REF = 47,
@@ -115,7 +114,7 @@ enum CommandType
CMD_COPYRIGHT = 85 | SIMPLESECT_BIT,
CMD_CITE = 86,
CMD_SNIPPET = 87,
- CMD_RTFONLY = 88,
+ CMD_RTFONLY = 88,
CMD_ENDRTFONLY = 89,
CMD_PIPE = 90,
CMD_VHDLFLOW = 91,
@@ -214,6 +213,7 @@ enum HtmlTagType
XML_INHERITDOC = XML_CmdMask + 22
};
+
/** Class representing a mapping from command names to command IDs. */
class Mapper
{
@@ -222,7 +222,7 @@ class Mapper
QCString find(const int n);
Mapper(const CommandMap *cm,bool caseSensitive);
private:
- QDict<int> m_map;
+ std::map<std::string,int> m_map;
bool m_cs;
};