From fd4f790ecd2e13fc924846ad6d346a842324e9ff Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 17 Jul 2017 12:00:43 +0200 Subject: 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 --- tools/keymap-gen | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tools') 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 ") + print("const std::vector<%s> %s = {" % (totypename, varname)) + else: + print("#include ") + print("#include ") + print("const std::map %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: -- cgit v1.1