22 #ifndef GEARS_OPTPARSE_OPTION_HPP
23 #define GEARS_OPTPARSE_OPTION_HPP
26 #include "../enums/operators.hpp"
28 using namespace gears::enums::operators;
55 using value_type = std::unique_ptr<value_base>;
67 option(std::string name, std::string help =
"", value_type value = constant(
true),
trait flags = trait::none):
68 ptr(std::move(value)), name(std::move(name)), help(std::move(help)), flags(std::move(flags)) {}
72 option(std::string name,
char alias, std::string help =
"", value_type value = constant(
true),
trait flags = trait::none):
73 ptr(std::move(value)), name(std::move(name)), help(std::move(help)), flags(std::move(flags)), alias(alias) {}
78 option(
char alias, std::string help =
"", value_type value = constant(
true),
trait flags = trait::none):
79 ptr(std::move(value)), help(std::move(help)), flags(std::move(flags)), alias(alias) {}
85 ptr(other.ptr == nullptr ? nullptr : other.ptr->clone()),
86 name(other.name), help(other.help), flags(other.flags), alias(other.alias) {}
92 ptr = other.ptr ==
nullptr ?
nullptr : other.ptr->clone();
119 return ptr !=
nullptr && ptr->nargs > 0;
129 return takes_value() ? ptr->nargs : 0;
153 bool is(
char arg)
const noexcept {
157 bool is(
const std::string& arg)
const noexcept {
172 const T&
get()
const {
174 throw std::invalid_argument(
"option does not take value");
179 throw std::invalid_argument(
"invalid cast for option");
193 const T&
get_or(
const typename std::remove_reference<T>::type& def)
const noexcept {
199 return val ==
nullptr ? def : val->
get_or(def);
206 return ptr !=
nullptr && ptr->is_active();
216 return takes_value() ? ptr->metavar :
"";
222 #endif // GEARS_OPTPARSE_OPTION_HPP