#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 << endl << "#include " << 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 << "namespace trygvis {" << endl << "namespace apps {" << endl << endl << "template" << endl << "int launch_app(int argc, const char *argv[]);" << endl << 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 (boost::ends_with(app_name, \"" << pair.first << "\")) {" << endl << " return launch_app<" << pair.second << ">(argc, argv);" << endl; }); out << " } else {" << endl << " return EXIT_FAILURE;" << endl << " }" << endl << "}" << endl << endl << "}" << endl << "}" << endl; return EXIT_SUCCESS; }