Skip to content

Commit

Permalink
getOptOr
Browse files Browse the repository at this point in the history
  • Loading branch information
ifsmirnov committed Mar 22, 2017
1 parent 5c449e1 commit 59ee3f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions jngen.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,18 @@ bool getOpt(const std::string& name, T& var) {
return readVariable(vmap[name], var);
}

template<typename T>
T getOptOr(size_t index, T def) {
getOpt(index, def);
return def;
}

template<typename T>
T getOptOr(const std::string& name, T def) {
getOpt(name, def);
return def;
}

inline void parseArgs(int argc, char *argv[]) {
vmap = parseArguments(std::vector<std::string>(argv + 1, argv + argc));
}
Expand Down Expand Up @@ -316,6 +328,7 @@ int getPositional(Args&... args) {

using jngen::parseArgs;
using jngen::getOpt;
using jngen::getOptOr;

using jngen::getPositional;

Expand Down
13 changes: 13 additions & 0 deletions options.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ bool getOpt(const std::string& name, T& var) {
return readVariable(vmap[name], var);
}

template<typename T>
T getOptOr(size_t index, T def) {
getOpt(index, def);
return def;
}

template<typename T>
T getOptOr(const std::string& name, T def) {
getOpt(name, def);
return def;
}

inline void parseArgs(int argc, char *argv[]) {
vmap = parseArguments(std::vector<std::string>(argv + 1, argv + argc));
}
Expand Down Expand Up @@ -204,6 +216,7 @@ int getPositional(Args&... args) {

using jngen::parseArgs;
using jngen::getOpt;
using jngen::getOptOr;

using jngen::getPositional;

Expand Down

0 comments on commit 59ee3f2

Please sign in to comment.