From c56840f03cf139d60c6d90b55cf16e70f6ae2bc2 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 21 Jun 2015 00:15:04 +0200 Subject: o Going all header file based and single-executable to launch all apps. o Ading CMake magic to generate the launcher --- apps/generate.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 apps/generate.cpp (limited to 'apps/generate.cpp') diff --git a/apps/generate.cpp b/apps/generate.cpp new file mode 100644 index 0000000..f0bf0fd --- /dev/null +++ b/apps/generate.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include + +using namespace std; + +int main(int argc, char *argv[]) { + + cout << "Generating " << argv[1] << endl; + + ofstream out; + + out.open(argv[1], ofstream::out); + + if (!out.is_open()) { + return EXIT_FAILURE; + } + + out << "#pragma once" << endl + << "#include " << endl + << endl; + + vector> apps; + + regex r("-"); + for (int i = 2; i < argc; i++) { + string app_name = argv[i]; + stringstream buf; + + regex_replace(ostream_iterator(buf), + app_name.begin(), app_name.end(), + r, "_"); + string class_name = buf.str(); + + apps.emplace_back(make_pair(app_name, class_name)); + } + + for_each(begin(apps), end(apps), [&](pair pair) { +// out << "class " << pair.second << ";" << endl; + out << "#include \"" << pair.first << ".h\"" << endl; + }); + out << endl; + + bool first = true; + + out << "template" << endl + << "int launch_app(int argc, const char *argv[]);" + << endl; + + out << "int launch(const std::string app_name, int argc, const char *argv[]) {" << endl; + + for_each(begin(apps), end(apps), [&](auto pair) { + out << " "; + if (!first) { + out << "} else "; + } else { + first = false; + } + + out << "if (app_name == \"" << pair.first << "\") {" << endl + << " return launch_app<" << pair.second << ">(argc, argv);" << endl; + }); + + out << " } else {" << endl + << " return EXIT_FAILURE;" << endl + << " }" << endl + << "}" << endl; + + return EXIT_SUCCESS; +} -- cgit v1.2.3