aboutsummaryrefslogtreecommitdiff
path: root/apps/generate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'apps/generate.cpp')
-rw-r--r--apps/generate.cpp71
1 files changed, 71 insertions, 0 deletions
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 <cstdlib>
+#include <iostream>
+#include <fstream>
+#include <regex>
+
+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 <string>" << endl
+ << endl;
+
+ vector<pair<string, string>> apps;
+
+ regex r("-");
+ for (int i = 2; i < argc; i++) {
+ string app_name = argv[i];
+ stringstream buf;
+
+ regex_replace(ostream_iterator<char>(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<string, string> pair) {
+// out << "class " << pair.second << ";" << endl;
+ out << "#include \"" << pair.first << ".h\"" << endl;
+ });
+ out << endl;
+
+ bool first = true;
+
+ out << "template<typename App>" << 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;
+}