You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CBLib/include/cb/argparser/argument.h

65 lines
1.0 KiB
C++

#ifndef CBLIB_ARGUMENT_H
#define CBLIB_ARGUMENT_H
#include <string>
#include <cassert>
namespace cb::argparser {
enum class Mode {
POSITIONAL_MODE,
REQUIRED_MODE,
OPTIONAL_MODE,
};
enum class Type {
STRING_TYPE,
BOOL_TYPE,
INTEGER_TYPE,
};
struct ParseArgument {
std::string short_name;
std::string name;
std::string description;
std::string default_value;
Type type;
Mode mode;
bool is_present{false};
};
class Argument {
private:
std::string content;
Type type{Type::STRING_TYPE};
public:
Argument() = default;
explicit Argument(std::string content, Type type = Type::STRING_TYPE);
[[nodiscard]] const std::string &as_str() const {
return content;
}
[[nodiscard]] bool as_bool() const {
return !content.empty();
}
int as_int() {
assert(type == Type::INTEGER_TYPE);
return std::stoi(content);
}
explicit operator bool() const {
return as_bool();
}
};
}
#endif //CBLIB_ARGUMENT_H