22 using std::runtime_error;
24 using std::ostringstream;
34 using ushort =
unsigned short;
35 using ulong =
unsigned long int;
39 enum class alignment {
40 LEFTJUST, RIGHTJUST, CENTERED
43 template<
class T>
string widthify(
const T& x,
const ushort& width = 0,
44 const alignment& c = alignment::CENTERED,
const char& fill =
' ');
62 inline Arguments(
const short& type,
const string& short_name,
71 inline const short& get_type()
const {
75 inline const string& get_long_name()
const {
79 inline const string& get_meaning()
const {
83 inline const string& get_short_name()
const {
89 const string short_name;
95 return (arg1.get_long_name() == arg2.get_long_name());
98 inline bool operator<(
const Arguments& arg1,
const Arguments& arg2) {
99 return (arg1.get_long_name() < arg2.get_long_name());
104 inline Options(
const short& type,
const string& short_name,
106 const string& default_value) :
118 inline const string& get_value()
const {
122 inline void set_value(
const string& value) {
130 inline bool operator==(
const Options& arg1,
const Options& arg2) {
131 return (arg1.get_long_name() == arg2.get_long_name());
134 inline bool operator<(
const Options& arg1,
const Options& arg2) {
135 return (arg1.get_long_name() < arg2.get_long_name());
140 inline Switch(
const short& type,
const string& short_name,
149 inline virtual ~
Switch() {
153 bool is_value()
const {
157 void set_value(
bool value) {
165 inline bool operator==(
const Switch& arg1,
const Switch& arg2) {
166 return (arg1.get_long_name() == arg2.get_long_name());
169 inline bool operator<(
const Switch& arg1,
const Switch& arg2) {
170 return (arg1.get_long_name() < arg2.get_long_name());
173 enum class opt_type {
174 DEFAULT, PROB, SEQ, CON, OTHER
187 bool arg_bool(
const unsigned short& type,
const string& arg);
188 string arg_value(
const short& type,
const string& arg);
190 const vector<string>& get_types()
const {
194 void set_types(
const vector<string>& types) {
203 string SHORT_HELP_OPT;
204 string LONG_HELP_OPT;
205 string SHORT_VERSION_OPT;
206 string LONG_VERSION_OPT;
212 const string help_message;
215 map<short, deque<Options>> cmd_options;
216 map<short, deque<Switch>> cmd_switches;
217 vector<string> types;
219 void create_argument_list();
220 string create_version_info();
222 void add_option(
const short& type,
const string& short_name,
223 const string& long_name,
const string& meaning,
224 const string& default_value);
226 void add_switch(
const short& type,
const string& short_name,
227 const string& long_name,
const string& meaning);
231 void print_usage_info(
const string& prog_name,
const ushort& indent = 1,
232 ostream& out = cout)
const;
bool arg_bool(const unsigned short &type, const string &arg)
return bool value
Definition: cmd.cc:219
customized runtime_error class for command line class
Definition: cmd.hh:49
void get_command_line(const int argc, const char *const *const argv)
Definition: cmd.cc:110
string arg_value(const short &type, const string &arg)
return the value of argument
Definition: cmd.cc:234
static short get_opt_index(const opt_type &opt)
Definition: cmd.cc:75
const string meaning
the argument's short name
Definition: cmd.hh:91
const string long_name
the argument's long name
Definition: cmd.hh:90
string widthify(const T &x, const ushort &width, const alignment &c, const char &fill)
Definition: cmd.cc:21
static string get_opt_types(const opt_type &opt)
Definition: cmd.cc:56