18 #ifndef SHEVEK_ARGS_HH
19 #define SHEVEK_ARGS_HH
25 #include <sigc++/sigc++.h>
26 #include <glibmm/ustring.h>
31 #define PACKAGE_NAME "[name not defined]"
33 #ifndef PACKAGE_TARNAME
34 #define PACKAGE_TARNAME PACKAGE_NAME
36 #ifndef PACKAGE_BUGREPORT
37 #define PACKAGE_BUGREPORT "[bug report e-mail not defined]"
39 #ifndef PACKAGE_VERSION
40 #define PACKAGE_VERSION "[version not defined]"
42 #ifndef COPYRIGHT_YEARS
43 #define COPYRIGHT_YEARS "[no time of copyright defined]"
45 #ifndef COPYRIGHT_EMAIL
46 #define COPYRIGHT_EMAIL ""
48 #ifndef COPYRIGHT_AUTHOR
49 #define COPYRIGHT_AUTHOR "[no author defined]"
71 args (
int &argc,
char **&argv,
int min_args,
int max_args, Glib::ustring
const &description,
76 Glib::ustring
const ©right_years = COPYRIGHT_YEARS,
77 Glib::ustring
const ©right_email = (COPYRIGHT_EMAIL[0] ==
'\0' ? PACKAGE_BUGREPORT : COPYRIGHT_EMAIL),
78 Glib::ustring
const &programmer = COPYRIGHT_AUTHOR,
79 Glib::ustring
const &email = PACKAGE_BUGREPORT,
80 char const *programname = PACKAGE_NAME,
81 char const *packagename = PACKAGE_TARNAME,
82 char const *version = PACKAGE_VERSION);
84 template <
unsigned size_>
85 args (
int &argc,
char **&argv,
option (&o)[size_],
int min_args,
86 int max_args, Glib::ustring
const &description);
88 unsigned size ()
const;
90 std::string
const &
operator[] (
unsigned idx)
const;
92 std::vector <std::string>::const_iterator
begin ()
const;
94 std::vector <std::string>::const_iterator
end ()
const;
96 std::vector <std::string> m_args;
97 void l_setup (
int &argc,
char **&argv,
option *o,
unsigned num_options,
98 int min_args,
int max_args,
99 Glib::ustring
const &description,
100 struct ::option *longopts,
101 Glib::ustring
const ©right_years = COPYRIGHT_YEARS,
102 Glib::ustring
const ©right_email = (COPYRIGHT_EMAIL[0] ==
'\0' ? PACKAGE_BUGREPORT : COPYRIGHT_EMAIL),
103 Glib::ustring
const &programmer = COPYRIGHT_AUTHOR,
104 Glib::ustring
const &email = PACKAGE_BUGREPORT,
105 char const *programname = PACKAGE_NAME,
106 char const *packagename = PACKAGE_TARNAME,
107 char const *version = PACKAGE_VERSION);
117 typedef sigc::slot2 <void, bool, Glib::ustring const &>
callback1;
119 option (
char shortopt, Glib::ustring
const &longopt, Glib::ustring
const &help_line, callback0 handle,
bool *used = NULL);
121 option (
char shortopt, Glib::ustring
const &longopt, Glib::ustring
const &help_line,
bool have_default, callback1 handle, Glib::ustring default_val = Glib::ustring (),
bool *used = NULL);
123 option (
char shortopt, Glib::ustring
const &longopt, Glib::ustring
const &help_line, callback0 handle0, callback1 handle1,
bool *used = NULL);
125 option (
char shortopt, Glib::ustring
const &longopt, Glib::ustring
const &help_line,
bool &var,
bool value,
bool *used = NULL);
127 option (
char shortopt, Glib::ustring
const &longopt, Glib::ustring
const &help_line,
bool have_default, Glib::ustring &var,
bool *used = NULL);
129 option (
char shortopt, Glib::ustring
const &longopt, Glib::ustring
const &help_line,
bool have_default, std::string &var,
bool *used = NULL);
131 option (
char shortopt, Glib::ustring
const &longopt, Glib::ustring
const &help_line,
bool have_default,
unsigned long &var,
bool *used = NULL);
133 option (
char shortopt, Glib::ustring
const &longopt, Glib::ustring
const &help_line,
bool have_default,
long &var,
bool *used = NULL);
135 option (
char shortopt, Glib::ustring
const &longopt, Glib::ustring
const &help_line,
bool have_default,
unsigned &var,
bool *used = NULL);
137 option (
char shortopt, Glib::ustring
const &longopt, Glib::ustring
const &help_line,
bool have_default,
int &var,
bool *used = NULL);
139 option (
char shortopt, Glib::ustring
const &longopt, Glib::ustring
const &help_line,
bool have_default,
unsigned short &var,
bool *used = NULL);
141 option (
char shortopt, Glib::ustring
const &longopt, Glib::ustring
const &help_line,
bool have_default,
short &var,
bool *used = NULL);
143 option (
char shortopt, Glib::ustring
const &longopt, Glib::ustring
const &help_line,
bool have_default,
float &var,
bool *used = NULL);
145 option (
char shortopt, Glib::ustring
const &longopt, Glib::ustring
const &help_line,
bool have_default,
double &var,
bool *used = NULL);
148 template <
typename _T>
option (
char shortopt, Glib::ustring
const &longopt, Glib::ustring
const &help_line, std::list <_T> &list);
151 enum opt_t {NEED_ARG, NO_ARG, OPT_ARG};
152 void setup (
char shortopt, Glib::ustring
const &longopt, Glib::ustring
const &help_line,
bool have_default, opt_t have_arg, callback0 handle0, callback1 handle1,
bool *used);
153 void call (
bool is_double,
char const *optarg);
155 Glib::ustring m_longopt;
156 Glib::ustring m_help;
158 Glib::ustring m_default;
164 static void l_set (
bool is_double, Glib::ustring
const &arg, Glib::ustring *var);
165 static void l_setstd (
bool is_double, Glib::ustring
const &arg, std::string *var);
166 static void l_setint (
bool is_double, Glib::ustring
const &arg,
int *var);
167 static void l_setuint (
bool is_double, Glib::ustring
const &arg,
unsigned *var);
168 static void l_setlint (
bool is_double, Glib::ustring
const &arg,
long *var);
169 static void l_setulint (
bool is_double, Glib::ustring
const &arg,
unsigned long *var);
170 static void l_setsint (
bool is_double, Glib::ustring
const &arg,
short *var);
171 static void l_setusint (
bool is_double, Glib::ustring
const &arg,
unsigned short *var);
172 static void l_setbool (
bool is_double,
bool val,
bool *var);
173 static void l_setfloat (
bool is_double, Glib::ustring
const &arg,
float *var);
174 static void l_setdfloat (
bool is_double, Glib::ustring
const &arg,
double *var);
175 template <
typename _T>
176 static void l_setlist (
bool is_double, Glib::ustring
const &arg, std::list <_T> *list);
179 template <
unsigned size_>
args::args (
int &argc,
char **&argv,
181 int min_args,
int max_args,
182 Glib::ustring
const &description)
185 struct ::option longopts[size_ + 4];
186 l_setup (argc, argv, o, size_, min_args, max_args, description, longopts);
190 template <
typename _T>
191 args::option::option (
char shortopt, Glib::ustring
const &longopt, Glib::ustring
const &help_line, std::list <_T> &list)
194 setup (shortopt, longopt, help_line,
false, NEED_ARG, callback0 (),
195 sigc::bind (sigc::ptr_fun (&l_setlist <_T>), &list), NULL);
198 template <
typename _T>
199 void args::option::l_setlist (
bool is_double, Glib::ustring
const &arg, std::list <_T> *list)
203 list->push_back (_T () );
204 option tmp (
'x',
"x",
"x",
false, list->back () );
205 tmp.m_handle1 (
false, arg);
sigc::slot2< void, bool, Glib::ustring const & > callback1
Callback for options with an argument.
Definition: args.hh:117
sigc::slot1< void, bool > callback0
Callback for options without an argument.
Definition: args.hh:115
Define an option which can be given to the program.
Definition: args.hh:111
unsigned size() const
The number of non-option arguments.
std::vector< std::string >::const_iterator begin() const
Iterate over the non-option arguments.
option(char shortopt, Glib::ustring const &longopt, Glib::ustring const &help_line, callback0 handle, bool *used=NULL)
Option has no argument and calls a function.
std::string const & operator[](unsigned idx) const
Get the non-option arguments.
std::vector< std::string >::const_iterator end() const
Iterate over the non-option arguments.
args(int &argc, char **&argv, int min_args, int max_args, Glib::ustring const &description, Glib::ustring const ©right_years=COPYRIGHT_YEARS, Glib::ustring const ©right_email=(COPYRIGHT_EMAIL[0]== '\0'?PACKAGE_BUGREPORT:COPYRIGHT_EMAIL), Glib::ustring const &programmer=COPYRIGHT_AUTHOR, Glib::ustring const &email=PACKAGE_BUGREPORT, char const *programname=PACKAGE_NAME, char const *packagename=PACKAGE_TARNAME, char const *version=PACKAGE_VERSION)
Commandline and configuration file parsing helper.
Definition: args.hh:65