ArKanjo 0.5.1
A tool for find code duplicated functions in codebases
ParsedOptions Struct Reference

#include <parser_options.hpp>

Public Member Functions

bool has (const std::string &name) const
 Checks whether an option exists. More...
 
std::optional< std::string_view > get (const std::string &name) const
 Returns the value of an option. More...
 
template<typename T >
std::optional< T > get_as (const std::string &name) const
 Returns the value of an option converted to the requested type. More...
 

Public Attributes

std::map< std::string, std::string > args
 Map from option name to value. More...
 
std::vector< std::string > extra_args
 List of extra arguments that are not options. More...
 

Detailed Description

Definition at line 29 of file parser_options.hpp.

Member Function Documentation

◆ get()

std::optional< std::string_view > ParsedOptions::get ( const std::string &  name) const

Returns the value of an option.

Parameters
nameOption name.
Returns
The option value, or std::nullopt if it does not exist.

Definition at line 64 of file parser_options.hpp.

◆ get_as()

template<typename T >
std::optional< T > ParsedOptions::get_as ( const std::string &  name) const

Returns the value of an option converted to the requested type.

Template Parameters
TTarget type.
Parameters
nameOption name.
Returns
The converted value, or std::nullopt if the option does not exist.
Exceptions
std::invalid_argumentIf the value cannot be converted.
std::out_of_rangeIf the value is outside the supported range.

Definition at line 83 of file parser_options.hpp.

◆ has()

bool ParsedOptions::has ( const std::string &  name) const

Checks whether an option exists.

Parameters
nameOption name.
Returns
true if the option exists, otherwise false.

Definition at line 54 of file parser_options.hpp.

Member Data Documentation

◆ args

std::map<std::string, std::string> ParsedOptions::args

Map from option name to value.

  • For flags without arguments, the value is the string "true".
  • For options with arguments, the value is the argument passed by the user. eg: { "config": "config.json", "verbose": "true" }

Definition at line 37 of file parser_options.hpp.

◆ extra_args

std::vector<std::string> ParsedOptions::extra_args

List of extra arguments that are not options.

Includes everything after a -- separator: getopt stops option parsing at --, so those tokens are kept unchanged here and can be forwarded directly to a method-specific backend.

Definition at line 46 of file parser_options.hpp.


The documentation for this struct was generated from the following file: