2 #include "creativity/cmdargs/Validation.hpp" 3 #include "creativity/cmdargs/strings.hpp" 4 #include <boost/program_options/options_description.hpp> 5 #include <boost/program_options/positional_options.hpp> 6 #include <boost/program_options/value_semantic.hpp> 12 namespace boost {
namespace program_options {
class variables_map; } }
19 template <
typename T> constexpr T
inf_or_max() {
return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : std::numeric_limits<T>::max(); }
21 template <
typename T> constexpr T
neginf_or_lowest() {
return std::numeric_limits<T>::has_infinity ? -std::numeric_limits<T>::infinity() : std::numeric_limits<T>::lowest(); }
54 void parse(
int argc,
char const*
const* argv);
62 static typename std::enable_if<not std::is_unsigned<T>::value and not std::is_same<T, bool>::value,
63 boost::program_options::typed_value<T>*
66 return boost::program_options::value<T>(&store)->default_value(store)->value_name(type_string<T>());
75 static typename std::enable_if<std::is_unsigned<T>::value and not std::is_same<T, bool>::value,
76 boost::program_options::typed_value<Validation<T>>*>::type
78 return value<Validation<T>>(storage);
84 static boost::program_options::typed_value<bool>*
value(
bool& store) {
85 return boost::program_options::bool_switch(&store)->default_value(store);
97 static boost::program_options::typed_value<V>*
98 value(
typename V::value_type &store) {
99 return boost::program_options::value<V>()->default_value(store)->value_name(V::validationString())
100 ->notifier([&store](
const V &v) { store = v; });
112 template <
typename V,
typename A>
113 static boost::program_options::typed_value<std::vector<V>>*
114 value(std::vector<typename V::value_type, A> &store) {
115 return boost::program_options::value<std::vector<V>>()->value_name(
116 V::validationString() +
" [" + V::validationString() +
" ...]")
117 ->notifier([&store](
const std::vector<V> &v) {
119 store.reserve(v.size());
120 for (
const auto &val : v) store.push_back((
const typename V::value_type) val);
126 template <
typename T,
typename A>
127 typename std::enable_if<not std::is_unsigned<T>::value, boost::program_options::typed_value<std::vector<T, A>>*>::type
129 return boost::program_options::value<std::vector<T, A>>(&store)->value_name(
130 type_string<T>() +
" [" + type_string<T>() +
" ...]");
135 template <
typename T,
typename A>
136 typename std::enable_if<std::is_unsigned<T>::value, boost::program_options::typed_value<std::vector<Validation<T>>>*>::type
138 return value<Validation<T>>(store);
142 template <
long minimum,
long denom = 1,
typename T>
143 static inline boost::program_options::typed_value<Min<T, minimum, denom>>*
min(T &store) {
return value<Min<T, minimum, denom>>(store); }
146 template <
long maximum,
long denom = 1,
typename T>
147 static boost::program_options::typed_value<Max<T, maximum, denom>>*
max(T &store) {
return value<Max<T, maximum, denom>>(store); }
150 template <
long min,
long max,
long denom = 1,
typename T>
151 static boost::program_options::typed_value<Range<T, min, max, denom>>*
range(T &store) {
return value<Range<T, min, max, denom>>(store); }
154 template <
long lower,
long denom = 1,
typename T>
155 static boost::program_options::typed_value<Above<T, lower, denom>>*
above(T &store) {
return value<Above<T, lower, denom>>(store); }
158 template <
long upper,
long denom = 1,
typename T>
159 static boost::program_options::typed_value<Below<T, upper, denom>>*
below(T &store) {
return value<Below<T, upper, denom>>(store); }
162 virtual std::string version()
const;
168 virtual std::string versionSuffix()
const;
173 virtual std::string usage()
const;
176 virtual std::string help()
const;
184 virtual void addOptions();
190 boost::program_options::options_description
options_;
196 boost::program_options::positional_options_description
positional_;
203 virtual void postParse(boost::program_options::variables_map &vars);
static boost::program_options::typed_value< Min< T, minimum, denom > > * min(T &store)
Shortcut for value<Min<T, n, d>>(val) with T last (so that it can be inferred from val) ...
Definition: CmdArgs.hpp:143
This class handles command line argument parsing.
Definition: CmdArgs.hpp:31
constexpr T neginf_or_lowest()
constexpr that returns negative infinity, if T has such a value, or the lowest value T supports if it...
Definition: CmdArgs.hpp:21
static boost::program_options::typed_value< Below< T, upper, denom > > * below(T &store)
Shortcut for value<Below<T, b, d>>(val) with T last (so that it can be inferred from val) ...
Definition: CmdArgs.hpp:159
Primary namespace for all Creativity library code.
Definition: config.hpp:4
static boost::program_options::typed_value< bool > * value(bool &store)
Creates an option value for a boolean value, that is, for an switch without an argument, with default value as given in store.
Definition: CmdArgs.hpp:84
static boost::program_options::typed_value< V > * value(typename V::value_type &store)
Creates an option value object with explicit validation wrapper class V.
Definition: CmdArgs.hpp:98
static std::enable_if< not std::is_unsigned< T >::value and not std::is_same< T, bool >::value, boost::program_options::typed_value< T > *>::type value(T &store)
Creates an option value object without any special validation wrapper class.
Definition: CmdArgs.hpp:65
std::string prog_name_
The program name, populated by parse().
Definition: CmdArgs.hpp:187
constexpr T inf_or_max()
constexpr that returns positive infinity, if T has such a value, or the maximum value T supports if i...
Definition: CmdArgs.hpp:19
static boost::program_options::typed_value< Above< T, lower, denom > > * above(T &store)
Shortcut for value<Above<T, a, d>>(val) with T last (so that it can be inferred from val) ...
Definition: CmdArgs.hpp:155
static boost::program_options::typed_value< Max< T, maximum, denom > > * max(T &store)
Shortcut for value<Max<T, n, d>>(val) with T last (so that it can be inferred from val) ...
Definition: CmdArgs.hpp:147
boost::program_options::positional_options_description positional_
Positional options object.
Definition: CmdArgs.hpp:196
std::enable_if< not std::is_unsigned< T >::value, boost::program_options::typed_value< std::vector< T, A > > * >::type value(std::vector< T, A > &store)
Takes a std::vector of values for options that store multiple values.
Definition: CmdArgs.hpp:128
std::enable_if< std::is_unsigned< T >::value, boost::program_options::typed_value< std::vector< Validation< T > > > * >::type value(std::vector< T, A > &store)
Takes a std::vector of values for options that store multiple values.
Definition: CmdArgs.hpp:137
boost::program_options::options_description options_
The options descriptions variable for all options.
Definition: CmdArgs.hpp:190
static boost::program_options::typed_value< Range< T, min, max, denom > > * range(T &store)
Shortcut for value<Range<T, a, b, d>>(val) with T last (so that it can be inferred from val) ...
Definition: CmdArgs.hpp:151
boost::program_options::options_description invisible_
Like options_, but for hidden options that aren't to be displayed in –help output.
Definition: CmdArgs.hpp:193
static std::enable_if< std::is_unsigned< T >::value and not std::is_same< T, bool >::value, boost::program_options::typed_value< Validation< T > > * >::type value(T &storage)
Creates an option value object around an unsigned primitive type, with automatic value storage and de...
Definition: CmdArgs.hpp:77
static boost::program_options::typed_value< std::vector< V > > * value(std::vector< typename V::value_type, A > &store)
Creates an option value object around a vector of options with validation wrapper class V applied to ...
Definition: CmdArgs.hpp:114