diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-10-28 13:13:57 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-11-01 10:20:55 +0200 |
commit | 4eb685d94e89a2aef61047225c1834a89de01de2 (patch) | |
tree | 99a6cab3b8766e23aecacc1cb91b00bfcf99700f /rcc_format/util.py | |
parent | Drop libc++ default (diff) | |
download | rcc-0.1.0.tar.xz |
Simplify rccv0.1.0
- drop qrc parsing and zstd compression
Diffstat (limited to 'rcc_format/util.py')
-rw-r--r-- | rcc_format/util.py | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/rcc_format/util.py b/rcc_format/util.py index 7fcfe34..af6651b 100644 --- a/rcc_format/util.py +++ b/rcc_format/util.py @@ -9,59 +9,55 @@ def to_variable_name(path): name = name[:-5] name = name.replace('-', '_') name = name.replace('.', '_') - return name - -def filelist(file): - root = xml.parse(file).getroot() - if root.tag != 'RCC': - return None - - files = [] - for child in root: - if child.tag == 'qresource': - prefix = child.attrib['prefix'] - for i in child: - alias = prefix + '/' + i.attrib['alias'] - variable = to_variable_name(i.text) - path = i.text - files.append(resource(alias, variable, path)) - - return files + return "r__" + name def write_header(file, namespace): - print("// Autogenerated binary file hexdump", file=file) - print("// This file may get overwritten by the build system\n", file=file) - print("#include <embed.h>\n", file=file) + print("""// Autogenerated header - this file may get overwritten by the build system +#pragma once + +#include <algorithm> +#include <span> +#include <string_view> +#include <tuple> +""", file=file) print("namespace {} {{".format(namespace), file=file) def write_item(file, array_name, array_data): - line_items = 0 - - print("constexpr uint8_t {}[] = {{".format(array_name), file=file) + print("constexpr char {}[] = {{".format(array_name), file=file) - for byte in array_data[0:len(array_data)]: + line_items = 0 + for byte in array_data: line_items+=1 if line_items == 16: - print(" 0x{:02X},".format(byte), file=file) + print("0x{:02X},".format(byte), file=file) line_items = 0 else: - print(" 0x{:02X},".format(byte), file=file, end='') - + print("0x{:02X},".format(byte), file=file, end='') print("};", file=file) print("constexpr size_t {}_len = {};\n".format(array_name, len(array_data)), file=file) def write_entries(file, resource_list): print("constexpr std::array entries {", file=file) - for f in resource_list: - print(" \"{}\", ".format(f.alias), file=file) - print("};\n", file=file) - print("constexpr std::array values {", file=file) for f in resource_list: - print(" std::span( {}, {}_len ),".format(f.variable, f.variable), file=file) + print(" std::make_tuple(\"{}\", std::span({}, {}_len))," + .format(f.alias, f.variable, f.variable), file=file) + print("};\n", file=file) def write_footer(file, namespace): + print("""template<typename StrViewLambda> +constexpr auto get(StrViewLambda name) { + static_assert(std::is_same_v<std::string_view, decltype(name())>); + + constexpr auto x = std::find_if(icons::entries.begin(), icons::entries.end(), + [=](const auto &tuple) -> bool { + return std::get<0>(tuple) == name(); + }); + static_assert(x != icons::entries.end()); + + return std::get<1>(*x); +}""", file=file) print("\n}} // namespace {}".format(namespace), file=file) |