18 T ParseValue(std::string value)
49 return std::stoll(value,
nullptr, 0);
51 catch(std::invalid_argument& a)
53 Linker::Error <<
"Error: Unable to parse " << value <<
", ignoring" << std::endl;
72 return value !=
"0" && value !=
"false" && value !=
"no" && value ==
"off";
89 std::vector<T> result;
90 size_t string_offset = 0;
92 while((comma = value.find(
',', string_offset)) != std::string::npos)
94 result.push_back(Linker::ParseValue<T>(value.substr(string_offset, comma - string_offset)));
95 string_offset = comma + 1;
97 result.push_back(Linker::ParseValue<T>(value.substr(string_offset)));
104 std::ostringstream oss;
111 template <
typename T>
117 return std::optional<T>(Linker::ParseValue<T>(value));
123 std::ostringstream oss;
129 template <
typename T>
130 class OptionDescription;
143 : name(name), description(description)
161 template <
typename T>
170 std::string type_name()
override
176 template <
typename T>
187 Option(std::string name, std::string description)
194 template <
typename T>
206 std::string type_name()
override
214 auto option_it = options->find(name);
215 if(option_it != options->end())
217 return ParseValue<T>(option_it->second);
231 Option(std::string name, std::string description)
244 return options->find(name) != options->end();
249 template <
typename T>
253 Option(std::string name, std::string description)
266 auto option_it = options->find(name);
267 if(option_it == options->end())
269 return std::vector<T>();
272 return ParseValue<std::vector<T>>(option_it->second);
277 template <
typename T>
281 Option(std::string name, std::string description)
294 auto option = options->find(name);
295 if(option != options->end())
297 return ParseValue<T>(option->second);
301 return std::optional<T>();
310 std::vector<Option<void> *> option_list;
315 void InitializeFields()
319 template <
typename ... Args>
320 void InitializeFields(
Option<void>& option, Args& ... args)
322 option_list.push_back(&option);
323 InitializeFields(args...);
327 void ConsiderOptions(std::map<std::string, std::string>& option_map)
329 for(
auto option : option_list)
331 option->options = &option_map;
Helper class that contains the options interpreted by the format.
Definition options.h:308
std::string name
The name of a command line option, as provided on the command line.
Definition options.h:138
virtual std::string type_name()
Returns a textual representation of the type, to be displayed to the user.
Definition options.h:154
std::string description
Description printed when -h is issued.
Definition options.h:140
A typed option description, used for documenting options.
Definition options.h:163
bool operator()()
Retrieve the provided value, parsed.
Definition options.h:242
std::string type_name() override
Returns a textual representation of the type, to be displayed to the user.
Definition options.h:236
std::string type_name() override
Returns a textual representation of the type, to be displayed to the user.
Definition options.h:286
std::optional< T > operator()()
Retrieve the provided value, parsed.
Definition options.h:292
std::string type_name() override
Returns a textual representation of the type, to be displayed to the user.
Definition options.h:258
std::vector< T > operator()()
Retrieve the provided value, parsed.
Definition options.h:264
std::map< std::string, std::string > * options
Reference to the collection of command line options, to be accessed by the Option instance.
Definition options.h:185
Documents and handles command line options.
Definition options.h:196
T operator()()
Retrieve the provided value, parsed.
Definition options.h:212
T default_value
Value of the option if not provided on the command line.
Definition options.h:199
static std::string GetTypeName()
Returns a textual representation of the type, to be displayed to the user.
Definition options.h:76
static bool ParseValue(std::string value)
Parses a string value.
Definition options.h:70
static offset_t ParseValue(std::string value)
Parses a string value.
Definition options.h:45
static std::string GetTypeName()
Returns a textual representation of the type, to be displayed to the user.
Definition options.h:59
static std::optional< T > ParseValue(std::string value)
Parses a string value.
Definition options.h:115
static std::string GetTypeName()
Returns a textual representation of the type, to be displayed to the user.
Definition options.h:121
static std::string ParseValue(std::string value)
Parses a string value.
Definition options.h:28
static std::string GetTypeName()
Returns a textual representation of the type, to be displayed to the user.
Definition options.h:34
static std::vector< T > ParseValue(std::string value)
Parses a string value.
Definition options.h:87
static std::string GetTypeName()
Returns a textual representation of the type, to be displayed to the user.
Definition options.h:102
Helper template to parse and display type of command line options.
Definition options.h:14