TAP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
BaseArgument.hpp
Go to the documentation of this file.
1 
25 #pragma once
26 
27 #include <string>
28 #include <vector>
29 #include <memory>
30 #include <stdexcept>
31 
32 namespace TAP {
33 
34 class Argument;
35 
40 class BaseArgument {
41 protected:
43  bool m_required = false;
44 
45 public:
50  }
51 
55  BaseArgument(const BaseArgument&) = default;
56 
60  BaseArgument(BaseArgument&&) = default;
61 
65  virtual ~BaseArgument() {
66  }
67 
71  BaseArgument& operator=(const BaseArgument&) = default;
72 
76  BaseArgument& operator=(BaseArgument&&) = default;
77 
83  virtual void find_all_arguments(std::vector<const Argument*>& collector) const = 0;
84 
90  explicit operator bool() const {
91  return count() > 0;
92  }
93 
94 
99  virtual unsigned int count() const = 0;
100 
102  // Test operations
104 
112  return *this;
113  }
114 
119  bool required() const {
120  return m_required;
121  }
122 
127  virtual void check_valid() const = 0;
128 
134  virtual std::string usage() const = 0;
135 
141  virtual std::unique_ptr<BaseArgument> clone() const & = 0;
142 
149  virtual std::unique_ptr<BaseArgument> clone() && = 0;
150 
151 };
152 
153 }
virtual void find_all_arguments(std::vector< const Argument * > &collector) const =0
Collect all Argument instances contained in this argument into the given vector.
virtual unsigned int count() const =0
Return the actual count of occurrences.
Base argument class, used both by actual Argument classes and constraints (ArgumentConstraint).
Definition: BaseArgument.hpp:40
BaseArgument & operator=(const BaseArgument &)=default
BaseArgument assignment operator.
bool required() const
Returns whether the argument is required.
Definition: BaseArgument.hpp:119
bool m_required
True if the argument has to be set.
Definition: BaseArgument.hpp:43
virtual void check_valid() const =0
Check if the argument constraints are satisfied.
virtual std::string usage() const =0
Returns a string representing how the argument may be used on the command line.
virtual std::unique_ptr< BaseArgument > clone() const &=0
Make a clone of the BaseArgument.
BaseArgument()
Base constructor.
Definition: BaseArgument.hpp:49
BaseArgument & set_required(bool required=true)
Mark the argument as required or not.
Definition: BaseArgument.hpp:110
virtual ~BaseArgument()
BaseArgument destructor.
Definition: BaseArgument.hpp:65