Skip to content

Commit

Permalink
Added Options::as_uint
Browse files Browse the repository at this point in the history
  • Loading branch information
opokatech committed Feb 29, 2024
1 parent 89b741e commit c5a01ab
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/options/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ namespace Options
return _impl->find_option_by_long_name(name)->as_int();
}

uint32_t Options::as_uint(const std::string &name) const
{
return _impl->find_option_by_long_name(name)->as_uint();
}

double Options::as_double(const std::string &name) const
{
return _impl->find_option_by_long_name(name)->as_double();
Expand Down
2 changes: 2 additions & 0 deletions src/options/Options.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <cstdint>
#include <string>

#include "Validator.hpp"
Expand Down Expand Up @@ -66,6 +67,7 @@ namespace Options
const std::string &positional(size_t idx) const;

int32_t as_int(const std::string &name) const;
uint32_t as_uint(const std::string &name) const;
double as_double(const std::string &name) const;
bool as_bool(const std::string &name) const;
const std::string &as_string(const std::string &name) const;
Expand Down
7 changes: 4 additions & 3 deletions src/tests/Options_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST_CASE("Options")
SECTION("Parsing")
{
options.add_mandatory("mode", "Operation mode. Valid are: fast, slow.",
[](const std::string &value) { return (value == "fast" || value == "slow"); });
[](const std::string &value) { return (value == "fast" || value == "slow"); });

options.add_optional("opt", 'o', "Bla bla", "");
options.add_flag("only_long", "flag with only long option visible");
Expand Down Expand Up @@ -94,8 +94,9 @@ TEST_CASE("Options")
options.add_optional("mode", "Operating mode", "fake");
options.add_optional("color", 'c', "Color selection", "none");
options.add_optional("speed", "Speed selection", "slow",
[](const std::string &value) { return value == "slow" || value == "fast"; });
options.add_optional("height", 'h', "Height", "low", [](const std::string &value) { return value == "low" || value == "high"; });
[](const std::string &value) { return value == "slow" || value == "fast"; });
options.add_optional("height", 'h', "Height", "low",
[](const std::string &value) { return value == "low" || value == "high"; });

SECTION("no parameters")
{
Expand Down

0 comments on commit c5a01ab

Please sign in to comment.