diff --git a/components/CLParser/include/Modelec/CLParser.h b/components/CLParser/include/Modelec/CLParser.h index 4cee155..2483605 100644 --- a/components/CLParser/include/Modelec/CLParser.h +++ b/components/CLParser/include/Modelec/CLParser.h @@ -13,6 +13,15 @@ public: [[nodiscard]] bool hasOption(const std::string& option) const; + template + [[nodiscard]] T getOption(const std::string& option, T defaultValue) const { + if (!hasOption(option)) { + return defaultValue; + } + + return static_cast(std::stod(_options.at(option))); + } + [[nodiscard]] std::optional getOption(const std::string& option) const; [[nodiscard]] std::string getOption(const std::string& option, const std::string& defaultValue) const; diff --git a/components/Utils/include/Modelec/Utils.h b/components/Utils/include/Modelec/Utils.h index 06b9ce3..3d395c6 100644 --- a/components/Utils/include/Modelec/Utils.h +++ b/components/Utils/include/Modelec/Utils.h @@ -4,6 +4,8 @@ #include namespace Modelec { + #define PI 3.14159265358979323846 + bool startWith(const std::string& str, const std::string& start); bool endsWith(const std::string& str, const std::string& end); diff --git a/example/main.cpp b/example/main.cpp index 444ca05..e7126cf 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -7,7 +7,7 @@ int main(int argc, char* argv[]) { CLParser parser(argc, argv); - int port = std::stoi(parser.getOption("port", "8080")); + int port = parser.getOption("port", 8080); bool loggerMode = parser.hasOption("logger");