Skip to content

Commit

Permalink
Handling enums in settings that double as boolean
Browse files Browse the repository at this point in the history
Small speedup of the code, only store and thus look through items that have a bool_representtaion.
  • Loading branch information
albert-github committed Apr 20, 2022
1 parent 2b61279 commit 911ac5e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
36 changes: 12 additions & 24 deletions src/configgen.py
Expand Up @@ -424,15 +424,12 @@ def escape(value):
if nv.nodeName == "value":
value = nv.getAttribute('name')
bool_representation = nv.getAttribute('bool_representation')
if value:
if bool_representation:
if bool_representation.upper() == 'YES':
enabled = "true"
else:
enabled = "false"
print(" {\"%s\", \"%s\", %s, %s}," % (name,escape(value),"true",enabled))
if value and bool_representation:
if bool_representation.upper() == 'YES':
enabled = "true"
else:
print(" {\"%s\", \"%s\", %s, %s}," % (name,escape(value),"false","false"))
enabled = "false"
print(" {\"%s\", \"%s\", %s}," % (name,escape(value),enabled))

def parseGroupMapGetter(node):
map = { 'bool':'bool', 'string':'const QCString &', 'int':'int', 'list':'const StringVector &' }
Expand Down Expand Up @@ -787,8 +784,7 @@ def main():
if n.nodeName == "group":
parseGroupMapEnums(n)
print("")
print("bool enumHasBool(QCString set, QCString val);")
print("bool enumBoolRepresentation(QCString set, QCString val);")
print("bool enumBoolRepresentation(QCString set, QCString val, bool *representation);")
print("")
print("class ConfigValues")
print("{")
Expand Down Expand Up @@ -847,7 +843,6 @@ def main():
print("#include \"configvalues.h\"")
print("#include \"configimpl.h\"")
print("#include <unordered_map>")
print("#include <cassert>")
print("")
print("const ConfigValues::Info *ConfigValues::get(const QCString &tag) const");
print("{");
Expand Down Expand Up @@ -898,7 +893,6 @@ def main():
print("{")
print(" QCString setting;")
print(" QCString value;")
print(" bool hasBool;")
print(" bool representation;")
print("};")
print("struct EnumBool enumBool[] = {")
Expand All @@ -908,22 +902,16 @@ def main():
parseGroupMapEnumsBool(n)
print("};")
print("")
print("bool enumHasBool(QCString set, QCString val)")
print("bool enumBoolRepresentation(QCString set, QCString val, bool *representation)")
print("{")
print(" for (uint i = 0; i < sizeof(enumBool) / sizeof(*enumBool); i++)")
print(" {")
print(" if (enumBool[i].setting == set && enumBool[i].value == val) return enumBool[i].hasBool;")
print(" }")
print(" return false;")
print("}")
print("")
print("bool enumBoolRepresentation(QCString set, QCString val)")
print("{")
print(" for (uint i = 0; i < sizeof(enumBool) / sizeof(*enumBool); i++)")
print(" {")
print(" if (enumBool[i].hasBool && enumBool[i].setting == set && enumBool[i].value == val) return enumBool[i].representation;")
print(" if (enumBool[i].setting == set && enumBool[i].value == val)")
print(" {")
print(" *representation = enumBool[i].representation;")
print(" return true;")
print(" }")
print(" }")
print(" assert(false);")
print(" return false;")
print("}")
print("")
Expand Down
3 changes: 2 additions & 1 deletion src/layout.cpp
Expand Up @@ -91,7 +91,8 @@ static bool elemIsVisible(const XMLHandlers::Attributes &attrib,bool defVal=TRUE
else if (opt && opt->type==ConfigValues::Info::String)
{
visible = ConfigValues::instance().*(opt->value.s);
if (opt->enumType && enumHasBool(id,visible)) return enumBoolRepresentation(id,visible);
bool representation = false;
if (opt->enumType && enumBoolRepresentation(id,visible,&representation)) return representation;
}
else if (!opt)
{
Expand Down

0 comments on commit 911ac5e

Please sign in to comment.