clipp.h File Reference
#include <cstring>
#include <string>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <memory>
#include <vector>
#include <limits>
#include <stack>
#include <algorithm>
#include <sstream>
#include <utility>
#include <iterator>
#include <functional>
Include dependency graph for clipp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  clipp::subrange
 (start,size) index range More...
 
struct  clipp::traits::is_callable< Fn, Ret >
 
struct  clipp::traits::is_callable< Fn, Ret(Args...)>
 
struct  clipp::traits::is_callable< Fn, void(Args...)>
 
struct  clipp::traits::is_input_range< T >
 
struct  clipp::traits::has_size_getter< T >
 
struct  clipp::detail::limits_clamped< T, V, bool >
 value limits clamping More...
 
struct  clipp::detail::limits_clamped< T, V, false >
 
struct  clipp::detail::make< T >
 type conversion helpers More...
 
struct  clipp::detail::make< bool >
 
struct  clipp::detail::make< unsigned char >
 
struct  clipp::detail::make< unsigned short int >
 
struct  clipp::detail::make< unsigned int >
 
struct  clipp::detail::make< unsigned long int >
 
struct  clipp::detail::make< unsigned long long int >
 
struct  clipp::detail::make< char >
 
struct  clipp::detail::make< short int >
 
struct  clipp::detail::make< int >
 
struct  clipp::detail::make< long int >
 
struct  clipp::detail::make< long long int >
 
struct  clipp::detail::make< float >
 
struct  clipp::detail::make< double >
 
struct  clipp::detail::make< long double >
 
struct  clipp::detail::make< std::string >
 
class  clipp::detail::assign_value< T, V >
 assigns boolean constant to one or multiple target objects More...
 
class  clipp::detail::flip_bool
 flips bools More...
 
class  clipp::detail::increment< T >
 increments using operator ++ More...
 
class  clipp::detail::decrement< T >
 decrements using operator – More...
 
class  clipp::detail::increment_by< T >
 increments by a fixed amount using operator += More...
 
class  clipp::detail::map_arg_to< T >
 makes a value from a string and assigns it to an object More...
 
class  clipp::detail::map_arg_to< std::vector< T > >
 specialization for vectors: append element More...
 
class  clipp::detail::map_arg_to< bool >
 specialization for bools: set to true regardless of string content More...
 
class  clipp::detail::action_provider< Derived >
 mixin that provides action definition and execution More...
 
class  clipp::detail::token< Derived >
 mixin that provides basic common settings of parameters and groups More...
 
class  clipp::match::numbers
 predicate that returns the first substring match within the input string that rmeepresents a number (with at maximum one decimal point and digit separators) More...
 
class  clipp::match::integers
 predicate that returns true if the input string represents an integer (with optional digit separators) More...
 
class  clipp::match::positive_integers
 predicate that returns true if the input string represents a non-negative integer (with optional digit separators) More...
 
class  clipp::match::substring
 predicate that returns true if the input string contains a given substring More...
 
class  clipp::match::prefix
 predicate that returns true if the input string starts with a given prefix More...
 
class  clipp::match::prefix_not
 predicate that returns true if the input string does not start with a given prefix More...
 
class  clipp::match::length
 predicate that returns true if the length of the input string is wihtin a given interval More...
 
class  clipp::parameter
 command line parameter that can match one or many arguments. More...
 
class  clipp::group
 group of parameters and/or other groups; can be configured to act as a group of alternatives (exclusive match) More...
 
class  clipp::group::depth_first_traverser
 recursively iterates over all nodes More...
 
struct  clipp::group::depth_first_traverser::context
 
class  clipp::group::depth_first_traverser::memento
 
class  clipp::detail::scoped_dfs_traverser
 DFS traverser that keeps track of 'scopes' scope = all parameters that are either bounded by two blocking parameters on the same depth level or the beginning/end of the outermost group. More...
 
struct  clipp::detail::select_all
 
struct  clipp::detail::select_flags
 
struct  clipp::detail::select_values
 
class  clipp::detail::match_t
 result of a matching operation More...
 
class  clipp::parser
 default command line arguments parser More...
 
class  clipp::parser::arg_mapping
 arg -> parameter mapping More...
 
class  clipp::parser::missing_event
 references a non-matched, required parameter More...
 
class  clipp::parsing_result
 contains argument -> parameter mappings and missing parameters More...
 
class  clipp::param_filter
 filter predicate for parameters and groups; Can be used to limit documentation generation to parameter subsets. More...
 
class  clipp::doc_formatting
 documentation formatting options More...
 
class  clipp::usage_lines
 generates usage lines More...
 
class  clipp::documentation
 generates parameter and group documentation from docstrings More...
 
class  clipp::man_page
 stores strings for man page sections More...
 
class  clipp::man_page::section
 man page section More...
 

Namespaces

 clipp
 primary namespace
 
 clipp::traits
 type traits (NOT FOR DIRECT USE IN CLIENT CODE!) no interface guarantees; might be changed or removed in the future
 
 clipp::detail
 helpers (NOT FOR DIRECT USE IN CLIENT CODE!) no interface guarantees; might be changed or removed in the future
 
 clipp::str
 string matching and processing tools
 
 clipp::match
 contains parameter matching functions and function classes
 
 clipp::debug
 printing methods for debugging command line interfaces
 

Typedefs

using clipp::arg_index = int
 
using clipp::arg_string = std::string
 
using clipp::doc_string = std::string
 
using clipp::arg_list = std::vector< arg_string >
 
using clipp::match_predicate = std::function< bool(const arg_string &)>
 match predicates More...
 
using clipp::match_function = std::function< subrange(const arg_string &)>
 
using clipp::match::noprefix = prefix_not
 alias for prefix_not More...
 
using clipp::pattern = group::child
 group or parameter More...
 

Enumerations

enum  clipp::tri : char { clipp::tri::no, clipp::tri::yes, clipp::tri::either }
 tristate More...
 

Functions

constexpr bool clipp::operator== (tri t, bool b) noexcept
 
constexpr bool clipp::operator== (bool b, tri t) noexcept
 
constexpr bool clipp::operator!= (tri t, bool b) noexcept
 
constexpr bool clipp::operator!= (bool b, tri t) noexcept
 
template<class Fn , class Ret , class... Args>
constexpr auto clipp::traits::check_is_callable (int) -> decltype(std::declval< Fn >()(std::declval< Args >()...), std::integral_constant< bool, std::is_same< Ret, typename std::result_of< Fn(Args...)>::type >::value >
 function (class) signature type trait More...
 
template<class , class , class... >
constexpr auto clipp::traits::check_is_callable (long) -> std::false_type
 
template<class Fn , class Ret >
constexpr auto clipp::traits::check_is_callable_without_arg (int) -> decltype(std::declval< Fn >()(), std::integral_constant< bool, std::is_same< Ret, typename std::result_of< Fn()>::type >::value >
 
template<class , class >
constexpr auto clipp::traits::check_is_callable_without_arg (long) -> std::false_type
 
template<class Fn , class... Args>
constexpr auto clipp::traits::check_is_void_callable (int) -> decltype(std::declval< Fn >()(std::declval< Args >()...), std::true_type
 
template<class , class , class... >
constexpr auto clipp::traits::check_is_void_callable (long) -> std::false_type
 
template<class Fn >
constexpr auto clipp::traits::check_is_void_callable_without_arg (int) -> decltype(std::declval< Fn >()(), std::true_type
 
template<class >
constexpr auto clipp::traits::check_is_void_callable_without_arg (long) -> std::false_type
 
template<class T >
constexpr auto clipp::traits::check_is_input_range (int) -> decltype(begin(std::declval< T >()), end(std::declval< T >()), std::true_type
 input range type trait More...
 
template<class T >
constexpr auto clipp::traits::check_is_input_range (char) -> decltype(std::begin(std::declval< T >()), std::end(std::declval< T >()), std::true_type
 
template<class >
constexpr auto clipp::traits::check_is_input_range (long) -> std::false_type
 
template<class T >
constexpr auto clipp::traits::check_has_size_getter (int) -> decltype(std::declval< T >().size(), std::true_type
 size() member type trait More...
 
template<class >
constexpr auto clipp::traits::check_has_size_getter (long) -> std::false_type
 
bool clipp::detail::fwd_to_unsigned_int (const char *&s)
 forwards string to first non-whitespace char; std string -> unsigned conv yields max value, but we want 0; also checks for nullptr More...
 
template<class T , class V >
clipp::detail::clamped_on_limits (const V &v)
 returns value of v as a T, clamped at T's maximum More...
 
template<class T >
clipp::str::make (const arg_string &s)
 converts string to value of target type 'T' More...
 
template<class C , class T , class A >
void clipp::str::trimr (std::basic_string< C, T, A > &s)
 removes trailing whitespace from string More...
 
template<class C , class T , class A >
void clipp::str::triml (std::basic_string< C, T, A > &s)
 removes leading whitespace from string More...
 
template<class C , class T , class A >
void clipp::str::trim (std::basic_string< C, T, A > &s)
 removes leading and trailing whitespace from string More...
 
template<class C , class T , class A >
void clipp::str::remove_ws (std::basic_string< C, T, A > &s)
 removes all whitespaces from string More...
 
template<class C , class T , class A >
bool clipp::str::has_prefix (const std::basic_string< C, T, A > &subject, const std::basic_string< C, T, A > &prefix)
 returns true, if the 'prefix' argument is a prefix of the 'subject' argument More...
 
template<class C , class T , class A >
bool clipp::str::has_postfix (const std::basic_string< C, T, A > &subject, const std::basic_string< C, T, A > &postfix)
 returns true, if the 'postfix' argument is a postfix of the 'subject' argument More...
 
template<class InputRange >
auto clipp::str::longest_common_prefix (const InputRange &strs) -> typename std::decay< decltype(*begin(strs))>::type
 returns longest common prefix of several sequential random access containers More...
 
template<class C , class T , class A , class InputRange >
subrange clipp::str::longest_substring_match (const std::basic_string< C, T, A > &arg, const InputRange &substrings)
 returns longest substring range that could be found in 'arg' More...
 
template<class C , class T , class A , class InputRange >
subrange clipp::str::longest_prefix_match (const std::basic_string< C, T, A > &arg, const InputRange &prefixes)
 returns longest prefix range that could be found in 'arg' More...
 
template<class C , class T , class A >
subrange clipp::str::substring_match (const std::basic_string< C, T, A > &subject, const std::basic_string< C, T, A > &query)
 returns the first occurrence of 'query' within 'subject' More...
 
template<class C , class T , class A >
subrange clipp::str::first_number_match (std::basic_string< C, T, A > s, C digitSeparator=C(','), C decimalPoint=C('.'), C exponential=C('e'))
 returns first substring match (pos,len) within the input string that represents a number (with at maximum one decimal point and digit separators) More...
 
template<class C , class T , class A >
subrange clipp::str::first_integer_match (std::basic_string< C, T, A > s, C digitSeparator=C(','))
 returns first substring match (pos,len) that represents an integer (with optional digit separators) More...
 
template<class C , class T , class A >
bool clipp::str::represents_number (const std::basic_string< C, T, A > &candidate, C digitSeparator=C(','), C decimalPoint=C('.'), C exponential=C('e'))
 returns true if candidate string represents a number More...
 
template<class C , class T , class A >
bool clipp::str::represents_integer (const std::basic_string< C, T, A > &candidate, C digitSeparator=C(','))
 returns true if candidate string represents an integer More...
 
template<class T , class V >
detail::assign_value< T, V > clipp::set (T &target, V value)
 makes function object with a const char* parameter that assigns a value to a ref-captured object More...
 
template<class T >
detail::map_arg_to< T > clipp::set (T &target)
 makes parameter-less function object that assigns value(s) to a ref-captured object; value(s) are obtained by converting the const char* argument to the captured object types; bools are always set to true if the argument is not nullptr More...
 
detail::assign_value< boolclipp::set (bool &target)
 makes function object that sets a bool to true More...
 
detail::assign_value< boolclipp::unset (bool &target)
 makes function object that sets a bool to false More...
 
detail::flip_bool clipp::flip (bool &b)
 makes function object that flips the value of a ref-captured bool More...
 
template<class T >
detail::increment< T > clipp::increment (T &target)
 makes function object that increments using operator ++ More...
 
template<class T >
detail::increment_by< T > clipp::increment (T &target, T by)
 makes function object that decrements using operator – More...
 
template<class T >
detail::decrement< T > clipp::decrement (T &target)
 makes function object that increments by a fixed amount using operator += More...
 
template<class T >
T & clipp::detail::operator% (doc_string docstr, token< T > &p)
 sets documentation strings on a token More...
 
template<class T >
T && clipp::detail::operator% (doc_string docstr, token< T > &&p)
 
template<class T >
T & clipp::detail::operator% (token< T > &p, doc_string docstr)
 
template<class T >
T && clipp::detail::operator% (token< T > &&p, doc_string docstr)
 
template<class T >
T & clipp::detail::doc (doc_string docstr, token< T > &p)
 sets documentation strings on a token More...
 
template<class T >
T && clipp::detail::doc (doc_string docstr, token< T > &&p)
 
bool clipp::match::any (const arg_string &)
 predicate that is always true More...
 
bool clipp::match::none (const arg_string &)
 predicate that is always false More...
 
bool clipp::match::nonempty (const arg_string &s)
 predicate that returns true if the argument string is non-empty string More...
 
bool clipp::match::alphanumeric (const arg_string &s)
 predicate that returns true if the argument is a non-empty string that consists only of alphanumeric characters More...
 
bool clipp::match::alphabetic (const arg_string &s)
 predicate that returns true if the argument is a non-empty string that consists only of alphabetic characters More...
 
length clipp::match::min_length (std::size_t min)
 makes function object that returns true if the input string has a given minimum length More...
 
length clipp::match::max_length (std::size_t max)
 makes function object that returns true if the input string is not longer than a given maximum length More...
 
template<class String , class... Strings>
parameter clipp::command (String &&flag, Strings &&... flags)
 makes required non-blocking exact match parameter More...
 
template<class String , class... Strings>
parameter clipp::required (String &&flag, Strings &&... flags)
 makes required non-blocking exact match parameter More...
 
template<class String , class... Strings>
parameter clipp::option (String &&flag, Strings &&... flags)
 makes optional, non-blocking exact match parameter More...
 
template<class... Targets>
parameter clipp::value (const doc_string &label, Targets &&... tgts)
 makes required, blocking, repeatable value parameter; matches any non-empty string More...
 
template<class Filter , class... Targets, class = typename std::enable_if< traits::is_callable<Filter,bool(const char*)>::value || traits::is_callable<Filter,subrange(const char*)>::value>::type>
parameter clipp::value (Filter &&filter, doc_string label, Targets &&... tgts)
 
template<class... Targets>
parameter clipp::values (const doc_string &label, Targets &&... tgts)
 makes required, blocking, repeatable value parameter; matches any non-empty string More...
 
template<class Filter , class... Targets, class = typename std::enable_if< traits::is_callable<Filter,bool(const char*)>::value || traits::is_callable<Filter,subrange(const char*)>::value>::type>
parameter clipp::values (Filter &&filter, doc_string label, Targets &&... tgts)
 
template<class... Targets>
parameter clipp::opt_value (const doc_string &label, Targets &&... tgts)
 makes optional, blocking value parameter; matches any non-empty string More...
 
template<class Filter , class... Targets, class = typename std::enable_if< traits::is_callable<Filter,bool(const char*)>::value || traits::is_callable<Filter,subrange(const char*)>::value>::type>
parameter clipp::opt_value (Filter &&filter, doc_string label, Targets &&... tgts)
 
template<class... Targets>
parameter clipp::opt_values (const doc_string &label, Targets &&... tgts)
 makes optional, blocking, repeatable value parameter; matches any non-empty string More...
 
template<class Filter , class... Targets, class = typename std::enable_if< traits::is_callable<Filter,bool(const char*)>::value || traits::is_callable<Filter,subrange(const char*)>::value>::type>
parameter clipp::opt_values (Filter &&filter, doc_string label, Targets &&... tgts)
 
template<class... Targets>
parameter clipp::word (const doc_string &label, Targets &&... tgts)
 makes required, blocking value parameter; matches any string consisting of alphanumeric characters More...
 
template<class... Targets>
parameter clipp::words (const doc_string &label, Targets &&... tgts)
 makes required, blocking, repeatable value parameter; matches any string consisting of alphanumeric characters More...
 
template<class... Targets>
parameter clipp::opt_word (const doc_string &label, Targets &&... tgts)
 makes optional, blocking value parameter; matches any string consisting of alphanumeric characters More...
 
template<class... Targets>
parameter clipp::opt_words (const doc_string &label, Targets &&... tgts)
 makes optional, blocking, repeatable value parameter; matches any string consisting of alphanumeric characters More...
 
template<class... Targets>
parameter clipp::number (const doc_string &label, Targets &&... tgts)
 makes required, blocking value parameter; matches any string that represents a number More...
 
template<class... Targets>
parameter clipp::numbers (const doc_string &label, Targets &&... tgts)
 makes required, blocking, repeatable value parameter; matches any string that represents a number More...
 
template<class... Targets>
parameter clipp::opt_number (const doc_string &label, Targets &&... tgts)
 makes optional, blocking value parameter; matches any string that represents a number More...
 
template<class... Targets>
parameter clipp::opt_numbers (const doc_string &label, Targets &&... tgts)
 makes optional, blocking, repeatable value parameter; matches any string that represents a number More...
 
template<class... Targets>
parameter clipp::integer (const doc_string &label, Targets &&... tgts)
 makes required, blocking value parameter; matches any string that represents an integer More...
 
template<class... Targets>
parameter clipp::integers (const doc_string &label, Targets &&... tgts)
 makes required, blocking, repeatable value parameter; matches any string that represents an integer More...
 
template<class... Targets>
parameter clipp::opt_integer (const doc_string &label, Targets &&... tgts)
 makes optional, blocking value parameter; matches any string that represents an integer More...
 
template<class... Targets>
parameter clipp::opt_integers (const doc_string &label, Targets &&... tgts)
 makes optional, blocking, repeatable value parameter; matches any string that represents an integer More...
 
template<class... Targets>
parameter clipp::any_other (Targets &&... tgts)
 makes catch-all value parameter More...
 
group clipp::operator, (parameter a, parameter b)
 makes a group of parameters and/or groups More...
 
group clipp::operator, (parameter a, group b)
 
group clipp::operator, (group a, parameter b)
 
group clipp::operator, (group a, group b)
 
template<class Param , class... Params>
group clipp::one_of (Param param, Params... params)
 makes a group of alternative parameters or groups More...
 
group clipp::operator| (parameter a, parameter b)
 makes a group of alternative parameters or groups More...
 
group clipp::operator| (parameter a, group b)
 
group clipp::operator| (group a, parameter b)
 
group clipp::operator| (group a, group b)
 
void clipp::detail::set_blocking (bool)
 
template<class P , class... Ps>
void clipp::detail::set_blocking (bool yes, P &p, Ps &... ps)
 
template<class Param , class... Params>
group clipp::in_sequence (Param param, Params... params)
 makes a parameter/group sequence by making all input objects blocking More...
 
group clipp::operator& (parameter a, parameter b)
 makes a parameter/group sequence by making all input objects blocking More...
 
group clipp::operator& (parameter a, group b)
 
group clipp::operator& (group a, parameter b)
 
group clipp::operator& (group a, group b)
 
group & clipp::joinable (group &param)
 makes a group of parameters and/or groups where all single char flag params ("-a", "b", ...) are joinable More...
 
group && clipp::joinable (group &&param)
 
template<class... Params>
group clipp::joinable (parameter param, Params... params)
 
template<class P2 , class... Ps>
group clipp::joinable (group p1, P2 p2, Ps... ps)
 
template<class Param , class... Params>
group clipp::joinable (doc_string docstr, Param param, Params... params)
 
parameter clipp::repeatable (parameter p)
 makes a repeatable copy of a parameter More...
 
group clipp::repeatable (group g)
 makes a repeatable copy of a group More...
 
template<class P2 , class... Ps>
group clipp::repeatable (parameter p1, P2 p2, Ps... ps)
 makes a group of parameters and/or groups that is repeatable as a whole Note that a repeatable group consisting entirely of non-blocking children is equivalent to a non-repeatable group of repeatable children. More...
 
template<class P2 , class... Ps>
group clipp::repeatable (group p1, P2 p2, Ps... ps)
 
parameter && clipp::with_prefix (const arg_string &prefix, parameter &&p)
 recursively prepends a prefix to all flags More...
 
group & clipp::with_prefix (const arg_string &prefix, group &params)
 
group && clipp::with_prefix (const arg_string &prefix, group &&params)
 
template<class Param , class... Params>
group clipp::with_prefix (arg_string prefix, Param &&param, Params &&... params)
 
parameter && clipp::with_prefixes_short_long (const arg_string &shortpfx, const arg_string &longpfx, parameter &&p)
 recursively prepends a prefix to all flags More...
 
group & clipp::with_prefixes_short_long (const arg_string &shortFlagPrefix, const arg_string &longFlagPrefix, group &params)
 
group && clipp::with_prefixes_short_long (const arg_string &shortFlagPrefix, const arg_string &longFlagPrefix, group &&params)
 
template<class Param , class... Params>
group clipp::with_prefixes_short_long (const arg_string &shortFlagPrefix, const arg_string &longFlagPrefix, Param &&param, Params &&... params)
 
template<class Predicate >
match_t clipp::detail::full_match (scoped_dfs_traverser pos, const arg_string &arg, const Predicate &select)
 finds the first parameter that matches a given string candidate parameters are traversed using a scoped DFS traverser More...
 
template<class Predicate >
match_t clipp::detail::prefix_match (scoped_dfs_traverser pos, const arg_string &arg, const Predicate &select)
 finds the first parameter that matches any (non-empty) prefix of a given string; candidate parameters are traversed using a scoped DFS traverser More...
 
template<class Predicate >
match_t clipp::detail::partial_match (scoped_dfs_traverser pos, const arg_string &arg, const Predicate &select)
 finds the first parameter that partially matches a given string; candidate parameters are traversed using a scoped DFS traverser More...
 
parsing_result clipp::parse (arg_list args, const group &cli)
 parses vector of arg strings and executes actions More...
 
parsing_result clipp::parse (std::initializer_list< const char * > arglist, const group &cli)
 parses initializer_list of C-style arg strings and executes actions More...
 
template<class InputIterator >
parsing_result clipp::parse (InputIterator first, InputIterator last, const group &cli)
 parses range of arg strings and executes actions More...
 
parsing_result clipp::parse (const int argc, char *argv[], const group &cli, arg_index offset=1)
 parses the standard array of command line arguments; omits argv[0] More...
 
man_page clipp::make_man_page (const group &params, doc_string progname="", const doc_formatting &fmt=doc_formatting{})
 generates man sections from command line parameters with sections "synopsis" and "options" More...
 
template<class OStream >
OStream & clipp::operator<< (OStream &os, const man_page &man)
 generates man page based on command line parameters More...
 
doc_string clipp::debug::doc_label (const parameter &p)
 prints first flag or value label of a parameter More...
 
doc_string clipp::debug::doc_label (const group &)
 
doc_string clipp::debug::doc_label (const pattern &p)
 
template<class OStream >
void clipp::debug::print (OStream &os, const parsing_result &result)
 prints parsing result More...
 
template<class OStream >
void clipp::debug::print (OStream &os, const parameter &p)
 prints parameter label and some properties More...
 
template<class OStream >
void clipp::debug::print (OStream &os, const group &g, int level)
 prints group and its contents; uses indentation More...
 
template<class OStream >
void clipp::debug::print (OStream &os, const pattern &param, int level=0)
 prints group or parameter; uses indentation More...