Commit 17180cac authored by Jakob Otto's avatar Jakob Otto

Fix enum-string generation

parent e5695676
...@@ -99,20 +99,22 @@ int main(int argc, char** argv) { ...@@ -99,20 +99,22 @@ int main(int argc, char** argv) {
cerr << "unable to open output file: " << argv[1] << '\n'; cerr << "unable to open output file: " << argv[1] << '\n';
return EXIT_FAILURE; return EXIT_FAILURE;
} }
std::string namespace_str;
for (size_t i = 0; i < namespaces.size() - 1; ++i)
namespace_str += namespaces[i] + "::";
namespace_str += namespaces[namespaces.size() - 1];
// Print file header. // Print file header.
out << "#include \"" << namespaces[0]; out << "#include \"" << namespaces[0];
for (size_t i = 1; i < namespaces.size(); ++i) for (size_t i = 1; i < namespaces.size(); ++i)
out << '/' << namespaces[i]; out << '/' << namespaces[i];
out << '/' << enum_name << ".hpp\"\n\n" out << '/' << enum_name << ".hpp\"\n\n"
<< "#include <string>\n\n" << "#include <string>\n\n"
<< "namespace " << namespaces[0] << " {\n"; << "namespace ";
for (size_t i = 1; i < namespaces.size(); ++i) out << namespace_str << " {\n";
out << "namespace " << namespaces[i] << " {\n";
out << "\nstd::string to_string(" << enum_name << " x) {\n" out << "\nstd::string to_string(" << enum_name << " x) {\n"
<< " switch(x) {\n" << " switch (x) {\n"
<< " default:\n" << " default:\n"
<< " return \"???\";\n"; << " return \"???\";\n";
// Read until hitting the closing '}'. // Read until hitting the closing '}'.
std::string case_label_prefix; std::string case_label_prefix;
if (is_enum_class) if (is_enum_class)
...@@ -136,6 +138,5 @@ int main(int argc, char** argv) { ...@@ -136,6 +138,5 @@ int main(int argc, char** argv) {
// Done. Print file footer and exit. // Done. Print file footer and exit.
out << " };\n" out << " };\n"
<< "}\n\n"; << "}\n\n";
for (auto i = namespaces.rbegin(); i != namespaces.rend(); ++i) out << "} // namespace " << namespace_str << '\n';
out << "} // namespace " << *i << '\n';
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment