Loading...
Searching...
No Matches
argagg.hpp File Reference
`#include <algorithm>`
`#include <array>`
`#include <cctype>`
`#include <cstdlib>`
`#include <cstring>`
`#include <iterator>`
`#include <ostream>`
`#include <sstream>`
`#include <stdexcept>`
`#include <string>`
`#include <unordered_map>`
`#include <utility>`
`#include <vector>`

Go to the source code of this file.

## Classes

struct | argagg::unexpected_argument_error
| This exception is thrown when a long option is parsed and is given an argument using the "=" syntax but the option doesn't expect an argument. More...
struct | argagg::unexpected_option_error
| This exception is thrown when an option is parsed unexpectedly such as when an argument was expected for a previous option or if an option was found that has not been defined. More...
struct | argagg::option_lacks_argument_error
| This exception is thrown when an option requires an argument but is not provided one. This can happen if another flag was found after the option or if we simply reach the end of the command line arguments. More...
struct | argagg::invalid_flag
| This exception is thrown when an option's flag is invalid. This can be the case if the flag is not prefixed by one or two hyphens or contains non alpha-numeric characters after the hyphens. See is_valid_flag_definition() for more details. More...
struct | argagg::unknown_option
| This exception is thrown when an unknown option is requested by name from an argagg::parser_results through the indexing operator ([]). More...
struct | argagg::convert::converter< T >
| For simple types the main extension point for adding argument conversions is argagg::convert::arg<T>(). However, for complex types such as templated types partial specialization of a helper struct is required. This struct provides that extension point. The default, generic implementation of argagg::convert::arg<T>() calls converter<T>::convert(). More...
struct | argagg::option_result
| Represents a single option parse result. More...
struct | argagg::option_results
| Represents multiple option parse results for a single option. If treated as a single parse result it defaults to the last parse result. Note that an instance of this struct is always created even if no option results are parsed for a given definition. In that case it will simply be empty. More...
struct | argagg::parser_results
| Represents all results of the parser including options and positional arguments. More...
struct | argagg::definition
| An option definition which essentially represents what an option is. More...
struct | argagg::parser_map
| Contains two maps which aid in option parsing. The first map, short_map, maps from a short flag (just a character) to a pointer to the original definition that the flag represents. The second map, long_map, maps from a long flag (an std::string) to a pointer to the original definition that the flag represents. More...
struct | argagg::parser
| A list of option definitions used to inform how to parse arguments. More...
struct | argagg::fmt_ostream
| A convenience output stream that will accumulate what is streamed to it and then, on destruction, format the accumulated string (via the argagg::fmt_string() function) to the provided std::ostream. More...

## Namespaces

namespace | argagg
| There are only two hard things in Computer Science: cache invalidation and naming things (Phil Karlton).
namespace | argagg::convert
| The set of template instantiations that convert C-strings to other types for the option_result::as(), option_results::as(), parser_results::as(), and parser_results::all_as() methods are placed in this namespace.

## Macros

#define | ARGAGG_ARGAGG_ARGAGG_HPP
#define | DEFINE_CONVERSION_FROM_LONG_(TYPE)
#define | DEFINE_CONVERSION_FROM_LONG_LONG_(TYPE)

## Functions

template<typename T>
T | argagg::convert::arg (const char *arg)
| Explicit instantiations of this function are used to convert arguments to types.
template<typename T>
bool | argagg::convert::parse_next_component (const char *&s, T &out_arg, const char delim=',')

A utility function for parsing an argument as a delimited list. To use, initialize a const char* pointer to the start of argument string. Then call parse_next_component(), providing that pointer, a mutable reference to where the parsed argument will go, and optionally the delimiting character. The argument string will be read up to the next delimiting character and then converted using argagg::convert::arg<decltype(out_arg)>(). The pointer is then incremented accordingly. If the delimiting character is no longer found then false is returned meaning that parsing the list can be considered finished.

bool | argagg::cmd_line_arg_is_option_flag (const char *s)
| Checks whether or not a command line argument should be processed as an option flag. This is very similar to is_valid_flag_definition() but must allow for short flag groups (e.g. "-abc") and equal-assigned long flag arguments (e.g. "--output=foo.txt").
bool | argagg::is_valid_flag_definition (const char *s)
| Checks whether a flag in an option definition is valid. I suggest reading through the function source to understand what dictates a valid.
bool | argagg::flag_is_short (const char *s)
| Tests whether or not a valid flag is short. Assumes the provided cstring is already a valid flag.
parser_map | argagg::validate_definitions (const std::vector< definition > &definitions)
| Validates a collection (specifically an std::vector) of definition objects by checking if the contained flags are valid. If the set of definition objects is not valid then an exception is thrown. Upon successful validation a parser_map object is returned.
std::string | argagg::fmt_string (const std::string &s)
| Processes the provided string using the fmt utility and returns the resulting output as a string. Not the most efficient (in time or space) but gets the job done.
std::ostream & | operator<< (std::ostream &os, const argagg::parser &x)
| Writes the option help to the given stream.
template<typename T>
T | argagg::convert::long_ (const char *arg)
| Templated function for conversion to T using the std::strtol() function. This is used for anything long length or shorter (long, int, short, char).
template<typename T>
T | argagg::convert::long_long_ (const char *arg)
| Templated function for conversion to T using the std::strtoll() function. This is used for anything long long length or shorter (long long).
template<>
bool | argagg::convert::arg (const char *arg)
template<>
float | argagg::convert::arg (const char *arg)
template<>
double | argagg::convert::arg (const char *arg)
template<>
const char * | argagg::convert::arg (const char *arg)
template<>
std::string | argagg::convert::arg (const char *arg)
std::string | argagg::lstrip (const std::string &text)
std::string | argagg::rstrip (const std::string &text)
std::string | argagg::construct_line (const std::string &indent, const std::string &contents)
std::string | argagg::wrap_line (const std::string &single_line, const std::size_t wrap_width)
| Return a wrapped version of a single line of text.

## Macro Definition Documentation

## ARGAGG_ARGAGG_ARGAGG_HPP

#define ARGAGG_ARGAGG_ARGAGG_HPP

Definition at line 32 of file argagg.hpp.

## DEFINE_CONVERSION_FROM_LONG_

#define DEFINE_CONVERSION_FROM_LONG_ | ( |  | TYPE | ) |

Value:
template <> inline \
TYPE arg(const char* arg) \
{ \
return long_<TYPE>(arg); \
}

Definition at line 1454 of file argagg.hpp.

## DEFINE_CONVERSION_FROM_LONG_LONG_

#define DEFINE_CONVERSION_FROM_LONG_LONG_ | ( |  | TYPE | ) |

Value:
template <> inline \
TYPE arg(const char* arg) \
{ \
return long_long_<TYPE>(arg); \
}

Definition at line 1474 of file argagg.hpp.

## Function Documentation

## operator<<()

std::ostream & operator<< | ( | std::ostream & | os,
|  | const argagg::parser & | x )

inline

Writes the option help to the given stream.

Definition at line 1692 of file argagg.hpp.