licornea_tools
args.h
Go to the documentation of this file.
1 #ifndef LICORNEA_ARGS_H_
2 #define LICORNEA_ARGS_H_
3 
4 #include "common.h"
5 #include <string>
6 #include <vector>
7 #include <memory>
8 
9 namespace tlz {
10 
11 class args_list {
12 private:
13  const char* executable_name_;
14  std::vector<const char*> args_;
15  std::string usage_;
16  std::ptrdiff_t arg_index_ = 0;
17 
18 public:
19  static std::unique_ptr<args_list> instance;
20  args_list(int argc, const char* argv[], const std::string& usage);
21 
22  [[noreturn]] void usage_fail(const std::string& error = "") const;
23 
24  bool next_arg_is(const std::string& val) const;
25  bool has_next_arg() const;
26  const char* next_arg();
27 };
28 
29 
30 args_list& args();
31 void get_args(int argc, const char* argv[], const std::string& usage);
32 
33 bool batch_mode();
34 
35 std::string string_arg();
36 inline std::string string_opt_arg(const std::string& def = "")
37  { return (args().has_next_arg() ? string_arg() : def); }
38 
39 std::string in_filename_arg();
40 inline std::string in_filename_opt_arg(const std::string& def = "")
41  { return (args().has_next_arg() ? in_filename_arg() : def); }
42 
43 std::string out_filename_arg();
44 std::string out_filename_opt_arg(const std::string& def = "");
45 
46 std::string out_dirname_arg();
47 std::string out_dirname_opt_arg(const std::string& def = "");
48 
49 long int_arg();
50 inline long int_opt_arg(long def)
51  { return (args().has_next_arg() ? int_arg() : def); }
52 
53 double real_arg();
54 inline double real_opt_arg(double def)
55  { return (args().has_next_arg() ? real_arg() : def); }
56 
57 std::string enum_arg(const std::vector<std::string>& options);
58 inline std::string enum_opt_arg(const std::vector<std::string>& options, const std::string& def)
59  { return (args().has_next_arg() ? enum_arg(options) : def); }
60 
61 bool bool_arg(const std::string& expected);
62 inline bool bool_opt_arg(const std::string& expected, bool def = false)
63  { return (args().has_next_arg() ? bool_arg(expected) : def); }
64 
66 
67 }
68 
69 #endif
args_list(int argc, const char *argv[], const std::string &usage)
Definition: args.cc:64
long int_opt_arg(long def)
Definition: args.h:50
double real_opt_arg(double def)
Definition: args.h:54
bool bool_arg(const std::string &expected)
Definition: args.cc:161
bool has_next_arg() const
Definition: args.cc:90
void usage_fail(const std::string &error="") const
Definition: args.cc:72
const char * next_arg()
Definition: args.cc:78
std::string in_filename_arg()
Definition: args.cc:98
std::string enum_arg(const std::vector< std::string > &options)
Definition: args.cc:154
static std::unique_ptr< args_list > instance
Definition: args.h:19
std::string enum_opt_arg(const std::vector< std::string > &options, const std::string &def)
Definition: args.h:58
std::string out_filename_opt_arg(const std::string &def)
Definition: args.cc:110
std::string out_dirname_arg()
Definition: args.cc:121
long int_arg()
Definition: args.cc:138
bool batch_mode()
Definition: args.cc:58
std::string string_arg()
Definition: args.cc:94
double real_arg()
Definition: args.cc:146
std::string out_dirname_opt_arg(const std::string &def)
Definition: args.cc:127
std::string out_filename_arg()
Definition: args.cc:104
bool next_arg_is(const std::string &val) const
Definition: args.cc:84
args_list & args()
Definition: args.cc:43
bool bool_opt_arg(const std::string &expected, bool def=false)
Definition: args.h:62
std::string in_filename_opt_arg(const std::string &def="")
Definition: args.h:40
view_index view_index_arg()
Definition: args.cc:166
std::string string_opt_arg(const std::string &def="")
Definition: args.h:36
void get_args(int argc, const char *argv[], const std::string &usage)
Definition: args.cc:49