27 #include <type_traits>
31 template<
typename T,
bool multi = false>
35 template<
typename T,
bool multi>
47 template<
typename T,
bool multi>
49 static_assert(!std::is_void<T>::value,
"Cannot make void arguments, use plain Argument");
50 static_assert(!std::is_const<T>::value,
"Cannot make const arguments");
51 static_assert(!std::is_volatile<T>::value,
"Cannot make volatile arguments");
52 static_assert(!std::is_reference<T>::value,
"Cannot make reference arguments");
53 static_assert(!std::is_pointer<T>::value,
"Cannot make pointer arguments");
58 using ST =
typename std::conditional< !multi, T, std::vector<T> >::type;
122 void set()
const override = 0;
148 std::unique_ptr<BaseArgument>
clone() const & override = 0;
159 template<
bool m = multi>
160 typename std::enable_if<!m>::type
170 template<
bool m = multi>
171 typename std::enable_if<m>::type
183 template<
typename T,
bool multi = false>
185 static_assert(!std::is_void<T>::value,
"Cannot make void arguments, use Argument");
214 TypedArgument<T, multi>(std::move(description), flag, storage) {
226 TypedArgument<T, multi>(std::move(description), name, storage) {
239 TypedArgument<T, multi>(std::move(description), flag, name, storage) {
261 TypedArgument<T, multi>(std::move(description), flag, &storage) {
273 TypedArgument<T, multi>(std::move(description), name, &storage) {
286 TypedArgument<T, multi>(std::move(description), flag, name, &storage) {
317 std::unique_ptr<BaseArgument>
clone() const &
override {
324 std::unique_ptr<BaseArgument>
clone() &&
override {
325 return std::unique_ptr<BaseArgument>(
new VariableArgument(std::move(*
this)));
352 return !std::is_same<bool, T>::value;
358 void set()
const override;
363 void set(
const std::string&
value)
const override;
368 std::string
usage()
const override;
373 std::string
ident()
const override;
388 template<
typename T,
bool multi = false>
404 template<
typename... U,
typename =
typename std::enable_if< std::is_constructible<
ST, U...>
::value >::type >
406 VariableArgument<T, multi>(std::move(description), new
ST(std::forward<U>(params)...)),
419 template<
typename... U,
typename =
typename std::enable_if< std::is_constructible<
ST, U...>
::value >::type>
421 VariableArgument<T, multi>(std::move(description), flag, new
ST(std::forward<U>(params)...)),
434 template<
typename... U,
typename =
typename std::enable_if< std::is_constructible<
ST, U...>
::value >::type >
436 VariableArgument<T, multi>(std::move(description), name, new
ST(std::forward<U>(params)...)),
450 template<
typename... U,
typename =
typename std::enable_if< std::is_constructible<
ST, U...>
::value >::type >
452 VariableArgument<T, multi>(std::move(description), flag, name, new
ST(std::forward<U>(params)...)),
487 std::unique_ptr<BaseArgument>
clone() const &
override {
488 return std::unique_ptr<BaseArgument>(
new ValueArgument(*
this));
494 std::unique_ptr<BaseArgument>
clone() &&
override {
495 return std::unique_ptr<BaseArgument>(
new ValueArgument(std::move(*
this)));
529 TypedArgument<T, false>(std::move(description), &storage), m_value(value) {
541 ConstArgument(std::string description,
char flag, T& storage,
const T& value) :
542 TypedArgument<T, false>(std::move(description), flag, &storage), m_value(value) {
553 ConstArgument(std::string description,
const std::string& name, T& storage,
const T& value) :
554 TypedArgument<T, false>(std::move(description), name, &storage), m_value(value) {
566 ConstArgument(std::string description,
char flag,
const std::string& name, T& storage,
const T& value) :
567 TypedArgument<T, false>(std::move(description), flag, name, &storage), m_value(value) {
605 void set()
const override {
613 std::unique_ptr<BaseArgument>
clone() const &
override {
614 return std::unique_ptr<BaseArgument>(
new ConstArgument(*
this));
620 std::unique_ptr<BaseArgument>
clone() &&
override {
621 return std::unique_ptr<BaseArgument>(
new ConstArgument(std::move(*
this)));
649 TypedArgument<bool, false>(std::move(description), &storage) {
661 TypedArgument<bool, false>(std::move(description), flag, &storage) {
671 SwitchArgument(std::string description,
const std::string& name,
bool& storage) :
672 TypedArgument<bool, false>(std::move(description), name, &storage) {
683 SwitchArgument(std::string description,
char flag,
const std::string& name,
bool& storage) :
684 TypedArgument<bool, false>(std::move(description), flag, name, &storage) {
698 TypedArgument<bool, false>(std::move(description), new bool()) {
709 TypedArgument<bool, false>(std::move(description), flag, new bool()),
720 TypedArgument<bool, false>(std::move(description), name, new bool()),
732 TypedArgument<bool, false>(std::move(description), flag, name, new bool()),
771 void set()
const override {
779 std::unique_ptr<BaseArgument>
clone() const &
override {
786 std::unique_ptr<BaseArgument>
clone() &&
override {
787 return std::unique_ptr<BaseArgument>(
new SwitchArgument(std::move(*
this)));
bool takes_value() const override
See Argument::takes_value()
Definition: TypedArgument.hpp:764
VariableArgument(std::string description, char flag, const std::string &name, ST *storage)
Create a VariableArgument with given description and storage pointer, aliased to the given flag and n...
Definition: TypedArgument.hpp:238
SwitchArgument(std::string description)
Create a switch argument with aliases defined by the description, using an internal variable to store...
Definition: TypedArgument.hpp:697
const std::string & valuename()
Return a human readable description for the value, used when describing the argument.
Definition: TypedArgument.hpp:344
VariableArgument(std::string description, const std::string &name, ST *storage)
Create a VariableArgument with given description and storage pointer, aliased to the given name...
Definition: TypedArgument.hpp:225
TypedArgument(std::string description, const std::string &name, ST *storage)
Create a TypedArgument with given description and storage pointer, aliased to the given name...
Definition: TypedArgument.hpp:99
virtual TypedArgument & check(TypedArgumentCheckFunc< T, multi > typedCheckFunc)
See Argument::check()
Definition: TypedArgument.hpp:140
ConstArgument(std::string description, const std::string &name, T &storage, const T &value)
Create a constant argument that is identified by a name, using an external variable to store a predef...
Definition: TypedArgument.hpp:553
virtual ~ValueArgument()=default
ValueArgument destructor.
virtual ~ConstArgument()
ConstArgument destructor.
Definition: TypedArgument.hpp:582
bool takes_value() const override=0
See Argument::takes_value()
TypedArgument(std::string description, ST *storage)
Create a TypedArgument with given description and storage pointer.
Definition: TypedArgument.hpp:73
ValueArgument(std::string description, U &&...params)
Create a positional ValueArgument using an internal variable to store the value.
Definition: TypedArgument.hpp:405
std::enable_if< m >::type check() const override
See Argument::check()
Definition: TypedArgument.hpp:172
VariableArgument(std::string description, char flag, const std::string &name, ST &storage)
Create a VariableArgument with given description and storage reference, aliased to the given flag and...
Definition: TypedArgument.hpp:285
std::string ident() const override
See Argument::ident()
std::unique_ptr< BaseArgument > clone() const &override=0
See BaseArgument::clone().
SwitchArgument(std::string description, char flag, bool &storage)
Create a switch argument that is identified by a flag, using an external variable to store the value...
Definition: TypedArgument.hpp:660
std::shared_ptr< ST > m_ownStorage
If the ValueArgument owns the variable storage, it is stored here.
Definition: TypedArgument.hpp:395
std::unique_ptr< BaseArgument > clone() const &override
See BaseArgument::clone().
Definition: TypedArgument.hpp:317
VariableArgument(std::string description, ST *storage)
Create a VariableArgument with given description and storage pointer.
Definition: TypedArgument.hpp:201
VariableArgument(std::string description, char flag, ST &storage)
Create a VariableArgument with given description and storage reference, aliased to the given flag...
Definition: TypedArgument.hpp:260
ValueArgument(std::string description, const std::string &name, U &&...params)
Create a ValueArgument using an internal variable to store the value, aliased to the given flag...
Definition: TypedArgument.hpp:435
Base argument class, used both by actual Argument classes and constraints (ArgumentConstraint).
Definition: BaseArgument.hpp:40
std::unique_ptr< BaseArgument > clone()&&override
See BaseArgument::clone().
Definition: TypedArgument.hpp:620
ST * m_storage
Pointer to value storage.
Definition: TypedArgument.hpp:61
SwitchArgument(std::string description, char flag)
Create a switch argument that is identified by a flag, using an external variable to store the value...
Definition: TypedArgument.hpp:708
std::unique_ptr< BaseArgument > clone() const &override
See BaseArgument::clone().
Definition: TypedArgument.hpp:779
Simple argument class.
Definition: Argument.hpp:48
unsigned int m_max
Maximum number of occurrences.
Definition: Argument.hpp:64
typename VariableArgument< T, multi >::ST ST
Make TypedArgument::ST accessible.
Definition: TypedArgument.hpp:392
SwitchArgument(std::string description, const std::string &name, bool &storage)
Create a switch argument that is identified by a name, using an external variable to store the value...
Definition: TypedArgument.hpp:671
TypedArgument(std::string description, char flag, const std::string &name, ST *storage)
Create a TypedArgument with given description and storage pointer, aliased to the given flag and name...
Definition: TypedArgument.hpp:113
SwitchArgument(std::string description, char flag, const std::string &name)
Create a switch argument that is identified by both a flag and a name, using an external variable to ...
Definition: TypedArgument.hpp:731
std::unique_ptr< BaseArgument > clone()&&override
See BaseArgument::clone().
Definition: TypedArgument.hpp:786
std::function< void(const TypedArgument< T, multi > &, const T &value)> TypedArgumentCheckFunc
Function pointer that is used by ValueArgument::check()
Definition: TypedArgument.hpp:36
VariableArgument & valuename(const std::string &valueName)
Assign a human readable description for the value, used when describing the argument.
Definition: TypedArgument.hpp:334
bool takes_value() const override
See Argument::takes_value()
Definition: TypedArgument.hpp:598
std::shared_ptr< bool > m_ownStorage
If the SwitchArgument owns the variable storage, it is stored here.
Definition: TypedArgument.hpp:634
std::enable_if<!m >::type check() const override
See Argument::check()
Definition: TypedArgument.hpp:161
T m_value
Constant to store.
Definition: TypedArgument.hpp:516
ConstArgument(std::string description, char flag, T &storage, const T &value)
Create a constant argument that is identified by a flag, using an external variable to store a predef...
Definition: TypedArgument.hpp:541
void set() const override=0
See Argument::set()
const ST & value() const
Returns the value of this argument.
Definition: TypedArgument.hpp:133
Interface class for arguments that accept a value when takes_value() is true.
Definition: Argument.hpp:535
std::string m_valueName
Name of the accepted value, used in the identifier.
Definition: TypedArgument.hpp:192
bool takes_value() const override
See Argument::takes_value()
Definition: TypedArgument.hpp:351
virtual ~VariableArgument()=default
VariableArgument destructor.
std::unique_ptr< BaseArgument > clone()&&override
See BaseArgument::clone().
Definition: TypedArgument.hpp:494
ValueArgument(std::string description, char flag, const std::string &name, U &&...params)
Create a ValueArgument using an internal variable to store the value, aliased to the given flag and n...
Definition: TypedArgument.hpp:451
const std::string & description() const
Returns the description of this argument.
Definition: Argument.hpp:208
typename TypedArgument< T, multi >::ST ST
Make TypedArgument::ST accessible.
Definition: TypedArgument.hpp:189
Base class for arguments that hold a typed value.
Definition: TypedArgument.hpp:32
std::unique_ptr< BaseArgument > clone()&&override
See BaseArgument::clone().
Definition: TypedArgument.hpp:324
virtual ~SwitchArgument()
SwitchArgument destructor.
Definition: TypedArgument.hpp:749
std::unique_ptr< BaseArgument > clone() const &override
See BaseArgument::clone().
Definition: TypedArgument.hpp:487
std::string usage() const override
See Argument::usage()
VariableArgument(std::string description, char flag, ST *storage)
Create a VariableArgument with given description and storage pointer, aliased to the given flag...
Definition: TypedArgument.hpp:213
Concrete implementation of TypedArgument.
Definition: TypedArgument.hpp:184
TypedArgumentCheckFunc< T, multi > m_typedCheckFunc
Callback for typed check.
Definition: TypedArgument.hpp:64
VariableArgument(std::string description, const std::string &name, ST &storage)
Create a VariableArgument with given description and storage reference, aliased to the given name...
Definition: TypedArgument.hpp:272
std::unique_ptr< BaseArgument > clone() const &override
See BaseArgument::clone().
Definition: TypedArgument.hpp:613
ConstArgument(std::string description, T &storage, const T &value)
Create a constant argument with aliases defined by the description, using an external variable to sto...
Definition: TypedArgument.hpp:528
SwitchArgument(std::string description, bool &storage)
Create a switch argument with aliases defined by the description, using an external variable to store...
Definition: TypedArgument.hpp:648
SwitchArgument(std::string description, const std::string &name)
Create a switch argument that is identified by a name, using an external variable to store the value...
Definition: TypedArgument.hpp:719
ValueArgument(std::string description, char flag, U &&...params)
Create a ValueArgument using an internal variable to store the value, aliased to the given flag...
Definition: TypedArgument.hpp:420
VariableArgument & operator=(const VariableArgument &)=default
VariableArgument copy assignment operator.
SwitchArgument(std::string description, char flag, const std::string &name, bool &storage)
Create a switch argument that is identified by both a flag and a name, using an external variable to ...
Definition: TypedArgument.hpp:683
ValueArgument & operator=(const ValueArgument &)=default
ValueArgument copy assignment operator.
typename std::conditional< !multi, T, std::vector< T > >::type ST
Alias for the storage type (which is a vector for MultiValueArgument types)
Definition: TypedArgument.hpp:58
TypedArgument(std::string description, char flag, ST *storage)
Create a TypedArgument with given description and storage pointer, aliased to the given flag...
Definition: TypedArgument.hpp:86
Specialization of TypedArgument that acts as a switch on the command line, but stores an arbitrary co...
Definition: TypedArgument.hpp:513
VariableArgument(std::string description, ST &storage)
Create a VariableArgument with given description and storage reference.
Definition: TypedArgument.hpp:248
Implementation of TypedArgument that stores a value by itself, based on VariableArgument.
Definition: TypedArgument.hpp:389
void set() const override
See Argument::set()
Definition: TypedArgument.hpp:605
SwitchArgument is a specialization for TypedArgument, which does not accept values (it switches)...
Definition: TypedArgument.hpp:631
ConstArgument(std::string description, char flag, const std::string &name, T &storage, const T &value)
Create a constant argument that is identified by both a flag and a name, using an external variable t...
Definition: TypedArgument.hpp:566
virtual void set() const
Set the argument (mark as occurred).
Definition: Argument.hpp:370
void set() const override
Calling this function is an error, call set(std::string) instead.
void set() const override
See Argument::set()
Definition: TypedArgument.hpp:771