Refactor code structure for improved readability and maintainability

This commit is contained in:
2026-05-05 16:14:52 +08:00
parent 47131c9d25
commit 49cf67006b
2 changed files with 1206 additions and 0 deletions
+1162
View File
File diff suppressed because it is too large Load Diff
+44
View File
@@ -8,6 +8,50 @@ if is_plat("mingw") then
add_ldflags("-static", "-static-libgcc", "-static-libstdc++")
end
task("export_all")
set_menu {
usage = "xmake export_all",
description = "Generate the single-header bitserial_all.hpp"
}
on_run(function ()
local rootdir = os.projectdir()
local output = path.join(rootdir, "bitserial_all.hpp")
local headers = {
"include/bitserial/detail/config.hpp",
"include/bitserial/bit_io.hpp",
"include/bitserial/bulk.hpp",
"include/bitserial/bitserial.hpp"
}
local out = {
"// This file is generated by `xmake export_all`.",
"// Do not edit it directly; edit headers under include/bitserial instead.",
"#pragma once"
}
local function append_header(header)
table.insert(out, "")
table.insert(out, "// =============================================================================")
table.insert(out, "// " .. header)
table.insert(out, "// =============================================================================")
local content = io.readfile(path.join(rootdir, header))
content = content:gsub("\r\n", "\n")
for line in (content .. "\n"):gmatch("(.-)\n") do
if not line:match("^%s*#pragma%s+once%s*$") and
not line:match("^%s*#%s*include%s*[<\"]bitserial/") then
table.insert(out, line)
end
end
end
for _, header in ipairs(headers) do
append_header(header)
end
io.writefile(output, table.concat(out, "\n") .. "\n")
cprint("${bright green}generated ${clear}%s", output)
end)
target("bitserial")
set_kind("headeronly")
add_headerfiles("bitserial.hpp", "include/(bitserial/**.hpp)")