summaryrefslogtreecommitdiffstats
path: root/src/configgen.py
diff options
context:
space:
mode:
authorDimitri van Heesch <doxygen@gmail.com>2020-06-02 09:13:43 (GMT)
committerDimitri van Heesch <doxygen@gmail.com>2020-06-04 20:06:08 (GMT)
commit0df1623c9363d52a2b04457233dcf2c64319b03c (patch)
tree7716f420ced7c05cfa50d3e12d91d02624361cff /src/configgen.py
parentfd1111503cd3e403db3784d03530e6ec3ac37032 (diff)
downloadDoxygen-0df1623c9363d52a2b04457233dcf2c64319b03c.zip
Doxygen-0df1623c9363d52a2b04457233dcf2c64319b03c.tar.gz
Doxygen-0df1623c9363d52a2b04457233dcf2c64319b03c.tar.bz2
Refactor: modernize configuration values
Diffstat (limited to 'src/configgen.py')
-rwxr-xr-xsrc/configgen.py117
1 files changed, 74 insertions, 43 deletions
diff --git a/src/configgen.py b/src/configgen.py
index 6720116..89eff6d 100755
--- a/src/configgen.py
+++ b/src/configgen.py
@@ -355,8 +355,23 @@ def parseGroups(node):
if n.nodeType == Node.ELEMENT_NODE:
parseOption(n)
-def parseGroupMap(node):
- map = { 'bool':'bool', 'string':'QCString', 'enum':'QCString', 'int':'int', 'list':'QStrList' }
+
+def parseGroupMapGetter(node):
+ map = { 'bool':'bool', 'string':'const QCString &', 'enum':'const QCString &', 'int':'int', 'list':'const StringVector &' }
+ for n in node.childNodes:
+ if n.nodeType == Node.ELEMENT_NODE:
+ setting = n.getAttribute('setting')
+ if len(setting) > 0:
+ print("#if %s" % (setting))
+ type = n.getAttribute('type')
+ name = n.getAttribute('id')
+ if type in map:
+ print(" %-20s %-30s const { return m_%s; }" % (map[type],name+'()',name))
+ if len(setting) > 0:
+ print("#endif")
+
+def parseGroupMapSetter(node):
+ map = { 'bool':'bool', 'string':'const QCString &', 'enum':'const QCString &', 'int':'int', 'list':'const StringVector &' }
for n in node.childNodes:
if n.nodeType == Node.ELEMENT_NODE:
setting = n.getAttribute('setting')
@@ -365,7 +380,21 @@ def parseGroupMap(node):
type = n.getAttribute('type')
name = n.getAttribute('id')
if type in map:
- print(" %-8s %s;" % (map[type],name))
+ print(" %-20s update_%-46s { m_%s = v; return m_%s; }" % (map[type],name+'('+map[type]+' v)',name,name))
+ if len(setting) > 0:
+ print("#endif")
+
+def parseGroupMapVar(node):
+ map = { 'bool':'bool', 'string':'QCString', 'enum':'QCString', 'int':'int', 'list':'StringVector' }
+ for n in node.childNodes:
+ if n.nodeType == Node.ELEMENT_NODE:
+ setting = n.getAttribute('setting')
+ if len(setting) > 0:
+ print("#if %s" % (setting))
+ type = n.getAttribute('type')
+ name = n.getAttribute('id')
+ if type in map:
+ print(" %-12s m_%s;" % (map[type],name))
if len(setting) > 0:
print("#endif")
@@ -379,7 +408,7 @@ def parseGroupInit(node):
type = n.getAttribute('type')
name = n.getAttribute('id')
if type in map:
- print(" %-25s = ConfigImpl::instance()->get%s(__FILE__,__LINE__,\"%s\");" % (name,map[type],name))
+ print(" %-25s = ConfigImpl::instance()->get%s(__FILE__,__LINE__,\"%s\");" % ('m_'+name,map[type],name))
if len(setting) > 0:
print("#endif")
@@ -393,7 +422,7 @@ def parseGroupMapInit(node):
type = n.getAttribute('type')
name = n.getAttribute('id')
if type in map:
- print(" m_map.insert(\"%s\",new Info%s(&ConfigValues::%s));" % (name,map[type],name))
+ print(" { %-25s Info{ %-13s &ConfigValues::m_%s }}," % ('\"'+name+'\",','Info::'+map[type]+',',name))
if len(setting) > 0:
print("#endif")
@@ -652,6 +681,7 @@ def main():
print("#include <qdict.h>")
print("#include <qstrlist.h>")
print("#include <qcstring.h>")
+ print("#include \"containers.h\"")
print("#include \"settings.h\"")
print("")
print("class ConfigValues")
@@ -661,42 +691,38 @@ def main():
for n in elem.childNodes:
if n.nodeType == Node.ELEMENT_NODE:
if (n.nodeName == "group"):
- parseGroupMap(n)
+ parseGroupMapGetter(n)
+ for n in elem.childNodes:
+ if n.nodeType == Node.ELEMENT_NODE:
+ if (n.nodeName == "group"):
+ parseGroupMapSetter(n)
print(" void init();")
- print(" struct Info")
- print(" {")
- print(" enum Type { Bool, Int, String, List, Unknown };")
- print(" Info(Type t) : type(t) {}")
- print(" virtual ~Info() {}")
- print(" Type type;")
- print(" };")
- print(" struct InfoBool : public Info")
- print(" {")
- print(" InfoBool(bool ConfigValues::*ptm) : Info(Info::Bool), item(ptm) {}")
- print(" bool ConfigValues::*item;")
- print(" };")
- print(" struct InfoInt : public Info")
- print(" {")
- print(" InfoInt(int ConfigValues::*ptm) : Info(Info::Int), item(ptm) {}")
- print(" int ConfigValues::*item;")
- print(" };")
- print(" struct InfoString : public Info")
- print(" {")
- print(" InfoString(QCString ConfigValues::*ptm) : Info(Info::String), item(ptm) {}")
- print(" QCString ConfigValues::*item;")
- print(" };")
- print(" struct InfoList : public Info")
- print(" {")
- print(" InfoList(QStrList ConfigValues::*ptm) : Info(Info::List), item(ptm) {}")
- print(" QStrList ConfigValues::*item;")
- print(" };")
- print(" const Info *get(const char *tag) const")
- print(" {")
- print(" return m_map.find(tag);")
- print(" }")
+ print(" struct Info");
+ print(" {");
+ print(" enum Type { Bool, Int, String, List, Unknown };");
+ print(" Info(Type t,bool ConfigValues::*b) : type(t), value(b) {}");
+ print(" Info(Type t,int ConfigValues::*i) : type(t), value(i) {}");
+ print(" Info(Type t,QCString ConfigValues::*s) : type(t), value(s) {}");
+ print(" Info(Type t,StringVector ConfigValues::*l) : type(t), value(l) {}");
+ print(" Type type;");
+ print(" union Item");
+ print(" {");
+ print(" Item(bool ConfigValues::*v) : b(v) {}");
+ print(" Item(int ConfigValues::*v) : i(v) {}");
+ print(" Item(QCString ConfigValues::*v) : s(v) {}");
+ print(" Item(StringVector ConfigValues::*v) : l(v) {}");
+ print(" bool ConfigValues::*b;");
+ print(" int ConfigValues::*i;");
+ print(" QCString ConfigValues::*s;");
+ print(" StringVector ConfigValues::*l;");
+ print(" } value;");
+ print(" };");
+ print(" const Info *get(const char *tag) const;");
print(" private:")
- print(" ConfigValues();")
- print(" QDict<Info> m_map;")
+ for n in elem.childNodes:
+ if n.nodeType == Node.ELEMENT_NODE:
+ if (n.nodeName == "group"):
+ parseGroupMapVar(n)
print("};")
print("")
print("#endif")
@@ -707,15 +733,20 @@ def main():
print(" */")
print("#include \"configvalues.h\"")
print("#include \"configimpl.h\"")
+ print("#include <unordered_map>")
print("")
- print("ConfigValues::ConfigValues() : m_map(257)")
- print("{")
- print(" m_map.setAutoDelete(TRUE);")
+ print("const ConfigValues::Info *ConfigValues::get(const char *tag) const");
+ print("{");
+ print(" static const std::unordered_map< std::string, Info > configMap =");
+ print(" {");
for n in elem.childNodes:
if n.nodeType == Node.ELEMENT_NODE:
if (n.nodeName == "group"):
parseGroupMapInit(n)
- print("}")
+ print(" };");
+ print(" auto it = configMap.find(tag);");
+ print(" return it!=configMap.end() ? &it->second : nullptr;");
+ print("}");
print("")
print("void ConfigValues::init()")
print("{")