add int64_t

This commit is contained in:
Carl Pearson
2020-06-09 15:15:44 -05:00
parent 73e1d1a71a
commit d437ff26c0
3 changed files with 14 additions and 5 deletions

View File

@@ -156,7 +156,8 @@ To error instead, call `p->no_unrecognized()`.
- [x] `--` to stop parsing options and flags
- [x] modify `argc`/`argv` (disable with `Parser::no_consume()`)
- Option/Positional Argument Types
- [x] `int`
- [x] `int32_t`
- [x] `int64_t`
- [x] `size_t`
- [x] `float`
- [x] `double`

View File

@@ -80,7 +80,10 @@ private:
void set_val(float *, const std::string &val) { // convert to float
*val_ = std::stof(val);
}
void set_val(int *, const std::string &val) { // convert to int
void set_val(int32_t *, const std::string &val) { // convert to int32_t
*val_ = std::stoi(val);
}
void set_val(int64_t *, const std::string &val) { // convert to int64_t
*val_ = std::stoi(val);
}
void set_val(std::string *, const std::string &val) { // convert to string
@@ -162,7 +165,10 @@ private:
void set_val(float *, const std::string &val) { // convert to float
*val_ = std::stof(val);
}
void set_val(int *, const std::string &val) { // convert to int
void set_val(int32_t *, const std::string &val) { // convert to int32_t
*val_ = std::stoi(val);
}
void set_val(int64_t *, const std::string &val) { // convert to int64_t
*val_ = std::stoi(val);
}
void set_val(std::string *, const std::string &val) { // convert to string
@@ -248,8 +254,8 @@ public:
// '--' indicates only positional arguments follow
// the second '--' should be interpreted as a positional argument
if (argv[i] == std::string("--")) {
optsOkay = false;
continue;
optsOkay = false;
continue;
}
OptionBase *opt = match_opt(argv[i]);
if (opt) {

View File

@@ -36,6 +36,7 @@ TEST_CASE("argparse") {
double d;
float f;
int i;
int64_t i64;
std::string s;
p.add_flag(campi, "--campi");
p.add_positional(x);
@@ -43,6 +44,7 @@ TEST_CASE("argparse") {
p.add_positional(f);
p.add_positional(s);
p.add_positional(i);
p.add_positional(i64);
REQUIRE(p.parse(argc, argv));
REQUIRE(campi == true);