mirror of
https://github.com/modelec/cpp-lib.git
synced 2026-01-18 16:17:22 +01:00
pi | template get option
This commit is contained in:
@@ -13,6 +13,15 @@ public:
|
||||
|
||||
[[nodiscard]] bool hasOption(const std::string& option) const;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] T getOption(const std::string& option, T defaultValue) const {
|
||||
if (!hasOption(option)) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return static_cast<T>(std::stod(_options.at(option)));
|
||||
}
|
||||
|
||||
[[nodiscard]] std::optional<std::string> getOption(const std::string& option) const;
|
||||
|
||||
[[nodiscard]] std::string getOption(const std::string& option, const std::string& defaultValue) const;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <string>
|
||||
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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user