aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2017-07-17 12:00:43 +0200
committerDaniel P. Berrange <berrange@redhat.com>2017-08-02 15:32:36 +0100
commitfd4f790ecd2e13fc924846ad6d346a842324e9ff (patch)
treeab535b1c68c9893f2994ab83f78ff1a589526599 /tools
parent204930bad0adc366c0269e055559bb7882570a0e (diff)
downloadkeycodemapdb-fd4f790ecd2e13fc924846ad6d346a842324e9ff.zip
keycodemapdb-fd4f790ecd2e13fc924846ad6d346a842324e9ff.tar.gz
keycodemapdb-fd4f790ecd2e13fc924846ad6d346a842324e9ff.tar.bz2
Use STL types for C++ output
This give us much nicer lookup for string keys, boundary checks and better introspection when it comes to iteration. Signed-off-by: Pierre Ossman <ossman@cendio.se>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/keymap-gen13
1 files changed, 13 insertions, 0 deletions
diff --git a/tools/keymap-gen b/tools/keymap-gen
index cb8b8fc..6536861 100755
--- a/tools/keymap-gen
+++ b/tools/keymap-gen
@@ -530,6 +530,19 @@ class CLanguageGenerator(LanguageSrcGenerator):
class CppLanguageGenerator(CLanguageGenerator):
+ def _array_start_code(self, varname, length, fromtype, totype):
+ totypename = self.inttypename if totype == int else "const " + self.strtypename
+ if fromtype == int:
+ print("#include <vector>")
+ print("const std::vector<%s> %s = {" % (totypename, varname))
+ else:
+ print("#include <map>")
+ print("#include <string>")
+ print("const std::map<const std::string, %s> %s = {" % (totypename, varname))
+
+ def _array_end(self):
+ print("};")
+
# designated initializers not available in C++
def _array_entry_code(self, index, value, comment):
if type(index) != int: