From 032afa5657bd600476cde256b6d7db84fde7d038 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 29 Aug 2004 03:23:55 -0400 Subject: a bit of a reorg; still much more to go --- option.h | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) (limited to 'option.h') diff --git a/option.h b/option.h index b93f50ab..44ca5b3b 100644 --- a/option.h +++ b/option.h @@ -1,11 +1,14 @@ #ifndef _OPTION_H #define _OPTION_H -#include #include #include -struct option_handler; +struct option_handler { + bool handled; + option_handler() : handled(false) {} + virtual void operator()(const char * arg = NULL) = 0; +}; struct option_t { char short_opt; @@ -13,38 +16,14 @@ struct option_t { bool wants_arg; option_handler * handler; - option_t() : short_opt(0), wants_arg(false) {} -}; - -typedef std::map option_handler_map; -typedef std::pair option_handler_pair; - -struct option_handler { - bool handled; - - static std::deque options; - static option_handler_map handlers; - - option_handler(const std::string& label, - const std::string& opt_chars); - - virtual void handle_option(const char * arg = NULL) = 0; + option_t() : short_opt(0), wants_arg(false), handler(NULL) {} }; +void register_option(const std::string& label, + const std::string& opt_chars, option_handler& option); bool process_option(const std::string& opt, const char * arg = NULL); void process_arguments(int argc, char ** argv, const bool anywhere, std::deque& args); void process_environment(char ** envp, const std::string& tag); -#define DEF_OPT_HANDLERS() \ - std::deque option_handler::options; \ - option_handler_map option_handler::handlers - -#define OPT_BEGIN(tag, chars) \ - static struct opt_ ## tag ## _handler : public option_handler { \ - opt_ ## tag ## _handler() : option_handler(#tag, chars) {} \ - virtual void handle_option(const char * optarg) - -#define OPT_END(tag) } opt_ ## tag ## _handler_obj - #endif // _OPTION_H -- cgit v1.2.3