Skip to content

Commit

Permalink
slang-reflect use fmt to emit the C++ code (#803)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sustrak authored Jul 30, 2023
1 parent 7271ed6 commit 924583d
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions tools/reflect/include/CppEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

#pragma once

#include "fmt/format.h"
#include <filesystem>
#include <fstream>
#include <ranges>
#include <sstream>
#include <vector>

Expand Down Expand Up @@ -47,19 +49,15 @@ class HppFile {
}

std::string emit() {
std::stringstream ss;
ss << "// " << fileName << std::endl;
ss << "#pragma once" << std::endl;
ss << std::endl;
for (auto& header : includes) {
ss << "#include <" << header << ">" << std::endl;
}
for (auto& header : headers) {
ss << "#include \"" << header << ".h\"" << std::endl;
}
ss << std::endl;
ss << hpp.str();
return std::move(ss.str());
auto includesTransform = std::views::transform(includes, [](const auto& inc) {
return fmt::format("#include <{}>", inc);
});
auto headersTransform = std::views::transform(headers, [](const auto& h) {
return fmt::format("#include \"{}.h\"", h);
});
return fmt::format("// {}\n#pragma once\n\n{}{}\n\n{}", fileName,
fmt::join(includesTransform, "\n"), fmt::join(headersTransform, "\n"),
hpp.str());
}

void emitToFile(const fs::path& path) {
Expand Down

0 comments on commit 924583d

Please sign in to comment.