1 #ifndef OOKII_COMMAND_LINE_BUILDER_H_
6 #define OOKII_COMMAND_LINE_BUILDER_H_
34 template<
typename CharType = details::default_
char_type,
typename Traits = std::
char_traits<CharType>,
typename Alloc = std::allocator<CharType>>
37 using parser_storage_type = details::parser_storage<CharType, Traits, Alloc>;
54 template<
typename ArgumentType,
typename BaseType>
65 using storage_type =
typename argument_base_type::storage_type;
91 return _parser_builder.
build();
97 return this->_storage.name;
123 return _parser_builder.get_next_position();
127 storage_type _storage;
135 template<
typename ArgumentType,
typename BaseType>
138 using typed_storage_type =
typename ArgumentType::typed_storage_type;
139 using value_type =
typename ArgumentType::value_type;
140 using element_type =
typename ArgumentType::element_type;
141 using converter_type =
typename typed_storage_type::converter_type;
150 _typed_storage{value}
206 if (!this->storage().position)
208 this->storage().position = this->get_next_position();
222 this->storage().is_required =
true;
258 this->_typed_storage.converter =
converter;
273 this->storage().aliases.push_back(
alias);
301 return make_owned_ptr<ArgumentType>(std::move(this->storage()), std::move(_typed_storage));
304 typed_storage_type _typed_storage;
349 : _storage{command_name}
417 if (_storage.prefixes.empty())
420 return parser_type{_arguments, std::move(_storage), _case_sensitive};
444 _storage.locale = loc;
461 template<
typename Range>
467 _storage.prefixes = std::vector<string_type>{ begin(
prefixes), end(
prefixes) };
487 return this->prefixes<std::initializer_list<T>>(
prefixes);
502 _storage.allow_white_space_separator = allow;
518 _storage.allow_duplicate_arguments = allow;
534 _storage.argument_value_separator = separator;
549 size_t get_next_position() noexcept
551 return _next_position++;
554 std::vector<std::unique_ptr<argument_builder_base>> _arguments;
555 size_t _next_position{};
556 bool _case_sensitive{};
558 parser_storage_type _storage;
Parses command line arguments into strongly-typed values.
Definition: command_line_core.h:92
command_line_argument_base< CharType, Traits, Alloc > argument_base_type
The specialized type of command_line_argument_base used.
Definition: command_line_core.h:95
static constexpr std::vector< string_type > get_default_prefixes()
Gets the default prefixes accepted by the parser.
Definition: command_line_core.h:126
typename argument_base_type::string_type string_type
The specialized type of std::basic_string used.
Definition: command_line_core.h:97
Abstract base class with common functionality for the argument builders.
Definition: command_line_builder.h:64
storage_type & storage()
Provides access to the argument's options storage.
Definition: command_line_builder.h:115
size_t get_next_position()
Gets the next position for a positional argument.
Definition: command_line_builder.h:121
const string_type & name() const
Returns the name of the argument.
Definition: command_line_builder.h:95
parser_type build()
Creates a basic_command_line_parser using the current options and arguments.
Definition: command_line_builder.h:89
virtual owned_or_borrowed_ptr< argument_base_type > to_argument()=0
Converts the argument_builder_base into a command_line_argument_base that can be used by the basic_co...
virtual ~argument_builder_base()=default
Default destructor.
multi_value_argument_builder< T >::builder_type & add_multi_value_argument(T &value, string_type name)
Adds a new multi-value argument, and returns an argument_builder that can be used to further customiz...
Definition: command_line_builder.h:83
argument_builder_base(basic_parser_builder &basic_parser_builder, string_type name)
Initializes a new instance of the argument_builder_base class.
Definition: command_line_builder.h:108
argument_builder< typed_argument_type< T >, argument_builder_base > & add_argument(T &value, string_type name)
Adds a new argument, and returns an argument_builder that can be used to further customize it.
Definition: command_line_builder.h:76
Specifies options for an argument under construction.
Definition: command_line_builder.h:137
argument_builder & value_description(string_type value_description)
Sets the value description for the argument.
Definition: command_line_builder.h:174
argument_builder & alias(string_type alias)
Adds an alias to the argument.
Definition: command_line_builder.h:271
argument_builder & cancel_parsing()
Indicates that supplying this argument will cancel parsing.
Definition: command_line_builder.h:289
argument_builder & converter(converter_type converter)
Supplies a custom function to convert strings to the argument's type.
Definition: command_line_builder.h:256
argument_builder & required()
Indicates that the argument is required.
Definition: command_line_builder.h:220
argument_builder & default_value(element_type default_value)
Sets a default value for the argument, which will be used if the argument is not supplied....
Definition: command_line_builder.h:240
argument_builder(basic_parser_builder &basic_parser_builder, string_type name, value_type &value)
Initializes a new instance of the argument_builder class.
Definition: command_line_builder.h:148
argument_builder & positional()
Indicates that the argument can be specified by position.
Definition: command_line_builder.h:204
argument_builder & description(string_type description)
Sets the long description for the argument.
Definition: command_line_builder.h:189
Base class for argument_builder for multi-value arguments.
Definition: command_line_builder.h:311
multi_value_argument_builder(basic_parser_builder &basic_parser_builder, string_type name)
Initializes a new instance of the multi_value_argument_builder class.
Definition: command_line_builder.h:339
builder_type & separator(CharType separator)
Specifies a separator that separates multiple values in a single argument value.
Definition: command_line_builder.h:329
Provides functionality to specify options and arguments to create a new basic_command_line_parser.
Definition: command_line_builder.h:36
basic_parser_builder & prefixes(const Range &prefixes)
Sets the argument name prefixes accepted by the basic_command_line_parser.
Definition: command_line_builder.h:462
basic_parser_builder & allow_whitespace_separator(bool allow) noexcept
Sets a value that indicates whether argument names and values can be separated by whitespace.
Definition: command_line_builder.h:500
basic_parser_builder & allow_duplicate_arguments(bool allow) noexcept
Sets a value that indicates whether arguments may be specified multiple times.
Definition: command_line_builder.h:516
basic_parser_builder & argument_value_separator(CharType separator) noexcept
Sets the character used to separate argument names and values.
Definition: command_line_builder.h:532
basic_parser_builder & case_sensitive(bool case_sensitive) noexcept
Sets a value that indicates whether argument names are case sensitive.
Definition: command_line_builder.h:432
basic_parser_builder & locale(std::locale loc)
Sets the locale to use when converting argument values and writing usage help.
Definition: command_line_builder.h:442
basic_parser_builder & description(string_type description)
Sets a description for the application.
Definition: command_line_builder.h:542
basic_parser_builder(string_type command_name)
Initializes a new instance of the basic_parser_builder class.
Definition: command_line_builder.h:348
typename parser_type::argument_base_type argument_base_type
The specialized type of command_line_argument_base used.
Definition: command_line_builder.h:45
basic_parser_builder & prefixes(std::initializer_list< T > prefixes)
Sets the argument name prefixes accepted by the basic_command_line_parser.
Definition: command_line_builder.h:485
typename parser_type::string_type string_type
The specialized type of std::basic_string used.
Definition: command_line_builder.h:43
multi_value_argument_builder< T >::builder_type & add_multi_value_argument(T &value, string_type name)
Adds a new multi-value argument, and returns an argument_builder that can be used to further customiz...
Definition: command_line_builder.h:403
parser_type build()
Creates a basic_command_line_parser using the current options and arguments.
Definition: command_line_builder.h:415
argument_builder< typed_argument_type< T >, argument_builder_base > & add_argument(T &value, string_type name)
Adds a new argument, and returns an argument_builder that can be used to further customize it.
Definition: command_line_builder.h:383
Class that provides information about arguments that are not multi-value arguments.
Definition: command_line_argument.h:313
Smart pointer that may or may not own the contained pointer.
Definition: owned_or_borrowed_ptr.h:28
Provides the ookii::basic_command_line_parser class.
Namespace containing the core Ookii.CommandLine.Cpp types.
Definition: command_line_argument.h:16
Template used to specify the default value description for a type.
Definition: value_description.h:30
static std::basic_string< CharType, Traits, Alloc > get()
Gets the value description for the type.
Definition: value_description.h:32