50using namespace boost::placeholders;
75 DEBUG(
"option.names",
"Option: " <<
name);
94 void report(std::ostream& out)
const {
97 out << std::right <<
desc();
101 out << std::left <<
value;
106 out << std::left << *
source << std::endl;
111 std::ostringstream out;
113 for (
const char *
p =
name; *
p;
p++) {
122 out <<
" (-" <<
ch <<
")";
133 throw_(std::runtime_error,
_f(
"No argument provided for %1%") %
desc());
137 void on(
const char * whence) {
147 void on(
const char * whence,
const string&
str) {
148 on(
string(whence),
str);
174 throw_(std::runtime_error,
_f(
"No argument provided for %1%") %
desc());
175 else if (args.
size() > 2)
176 throw_(std::runtime_error,
_f(
"Too many arguments provided for %1%") %
desc());
177 else if (! args[0].is_string())
178 throw_(std::runtime_error,
_f(
"Context argument for %1% not a string") %
desc());
179 on(args.
get<
string>(0), args.
get<
string>(1));
181 else if (args.
size() < 1) {
182 throw_(std::runtime_error,
_f(
"No argument provided for %1%") %
desc());
184 else if (! args[0].is_string()) {
185 throw_(std::runtime_error,
_f(
"Context argument for %1% not a string") %
desc());
188 on(args.
get<
string>(0));
194 if (! args.
empty()) {
207#define BEGIN(type, name) \
208 struct name ## option_t : public option_t<type>
210#define CTOR(type, name) \
211 name ## option_t() : option_t<type>(#name)
212#define CTOR_(type, name, base) \
213 name ## option_t() : option_t<type>(#name), base
214#define DECL1(type, name, vartype, var, value) \
216 name ## option_t() : option_t<type>(#name), var value
218#define DO() virtual void handler_thunk(const optional<string>& whence)
219#define DO_(var) virtual void handler_thunk(const optional<string>& whence, \
222#define END(name) name ## handler
224#define COPY_OPT(name, other) name ## handler(other.name ## handler)
226#define MAKE_OPT_HANDLER(type, x) \
227 expr_t::op_t::wrap_functor(bind(&option_t<type>::handler, x, _1))
229#define MAKE_OPT_FUNCTOR(type, x) \
230 expr_t::op_t::wrap_functor(bind(&option_t<type>::operator(), x, _1))
232inline bool is_eq(
const char *
p,
const char *
n) {
234 for (; *
p && *
n;
p++,
n++) {
235 if (! (*
p ==
'-' && *
n ==
'_') && *
p != *
n)
239 return *
p == *
n || (! *
p && *
n ==
'_' && ! *(
n + 1));
243 if (is_eq(p, #name)) \
244 return ((name ## handler).parent = this, &(name ## handler))
246#define OPT_ALT(name, alt) \
247 if (is_eq(p, #name) || is_eq(p, #alt)) \
248 return ((name ## handler).parent = this, &(name ## handler))
252 ((name ## handler).wants_arg && \
253 *(p + 1) == '_' && ! *(p + 2)) || \
255 return ((name ## handler).parent = this, &(name ## handler))
257#define OPT_CH(name) \
259 ((name ## handler).wants_arg && \
260 *(p + 1) == '_' && ! *(p + 2))) \
261 return ((name ## handler).parent = this, &(name ## handler))
263#define HANDLER(name) name ## handler
264#define HANDLED(name) HANDLER(name)
266#define OPTION(type, name) \
269 CTOR(type, name) {} \
273#define OPTION_(type, name, body) \
276 CTOR(type, name) {} \
281#define OPTION__(type, name, body) \
289 parent->HANDLER(name).parent = parent; \
290 parent->HANDLER(name)
#define TRACE_CTOR(cls, args)
#define DECLARE_EXCEPTION(name, kind)
bool is_eq(const char *p, const char *n)
value_t string_value(const string &str="")
std::list< string > strings_list
strings_list process_arguments(strings_list args, scope_t &scope)
bool process_option(const string &whence, const string &name, scope_t &scope, const char *arg, const string &varname)
void process_environment(const char **envp, const string &tag, scope_t &scope)
virtual void handler_thunk(const optional< string > &)
value_t handler(call_scope_t &args)
option_t & operator=(const option_t &)
void on(const char *whence, const string &str)
string::size_type name_len
virtual value_t operator()(call_scope_t &args)
option_t(const option_t &other)
void on(const char *whence)
virtual void handler_thunk(const optional< string > &, const string &)
void on(const optional< string > &whence)
void report(std::ostream &out) const
option_t(const char *_name, const char _ch='\0')
optional< string > source
void on(const optional< string > &whence, const string &str)
T get(std::size_t index, bool convert=true)
void push_front(const value_t &val)
Dynamic type representing various numeric types.