Option++
2.0
C++ library for reading command-line options
|
Go to the documentation of this file.
25 #ifndef OPTIONPP_OPTION_HPP
26 #define OPTIONPP_OPTION_HPP
108 const std::string& arg_name =
"",
109 bool arg_required =
false);
131 std::string
name() const noexcept {
132 if (!m_long_name.empty())
134 else if (m_short_name !=
'\0')
135 return std::string{m_short_name};
153 const std::string&
long_name() const noexcept {
return m_long_name; }
181 bool required =
true);
339 const std::string&
description() const noexcept {
return m_desc; }
342 std::string m_long_name;
343 char m_short_name{
'\0'};
346 std::string m_arg_name;
347 bool m_arg_required{
false};
349 bool* m_is_option_set =
nullptr;
350 void* m_bound_variable =
nullptr;
void write_uint(unsigned int value) const
Writes to the bound unsigned integer variable that was specified in bind_uint.
Definition: option.cpp:111
bool is_argument_required() const noexcept
Return true if the argument is mandatory.
Definition: option.hpp:194
void write_bool(bool value) const noexcept
Writes to the bound boolean variable that was specified in bind_bool.
Definition: option.cpp:92
Describes a valid program command-line option.
Definition: option.hpp:67
option(char short_name)
Construct an option with a given short name.
Definition: option.hpp:92
option & short_name(char name) noexcept
Set the option's short name.
Definition: option.hpp:160
void write_double(double value) const
Writes to the bound double variable that was specified in bind_double.
Definition: option.cpp:118
option & bind_string(std::string *var) noexcept
Designates that the option should take a string argument which should be stored in *var.
Definition: option.cpp:52
void write_string(const std::string &value) const
Writes to the bound string variable that was specified in bind_string.
Definition: option.cpp:97
option() noexcept
Default constructor.
Definition: option.hpp:84
void write_int(int value) const
Writes to the bound integer variable that was specified in bind_int.
Definition: option.cpp:104
option & bind_uint(unsigned int *var) noexcept
Designates that the option should take an unsigned integer argument which should be stored in *var.
Definition: option.cpp:72
option & bind_int(int *var) noexcept
Designates that the option should take an integer argument which should be stored in *var.
Definition: option.cpp:62
std::string name() const noexcept
Returns a name for the option.
Definition: option.hpp:131
option & name(const std::string &long_name, char short_name='\0')
Sets the long and short name for the option.
Definition: option.hpp:117
const std::string & argument_name() const noexcept
Retrieve the option's argument name.
Definition: option.hpp:189
option & argument(const std::string &name, bool required=true)
Set the option's argument information.
Definition: option.cpp:38
option & bind_bool(bool *var) noexcept
Designates a location to store whether the option was set.
Definition: option.cpp:45
arg_type argument_type() const noexcept
Return the type of argument.
Definition: option.hpp:199
const std::string & description() const noexcept
Retrieve the option description.
Definition: option.hpp:339
Library namespace.
Definition: error.hpp:31
const std::string & long_name() const noexcept
Retrieve the option's long name.
Definition: option.hpp:153
bool has_bound_argument_variable() const noexcept
Returns true if a variable has been bound to the option's argument.
Definition: option.hpp:263
char short_name() const noexcept
Retrieve the option's short name.
Definition: option.hpp:168
option & bind_double(double *var) noexcept
Designates that the option should take a double-precision floating point argument which should be sto...
Definition: option.cpp:82
option & long_name(const std::string &name)
Set the option's long name.
Definition: option.hpp:145
arg_type
Holds the possible argument types.
Definition: option.hpp:73
option & description(const std::string &desc)
Set the option description.
Definition: option.hpp:331