From 443293aaf09eca7c3b88d621d056c4effee2c248 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 10 May 2012 17:54:18 +0200 Subject: Implement option class inheritance For now multiple, non-virtual inheritance is supported. An option class can now also be declared abstract using the class c = 0 {...}; syntax. New option, --exclude-base, controls whether base class information is present in usage and documentation. --- cli/options.hxx | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) (limited to 'cli/options.hxx') diff --git a/cli/options.hxx b/cli/options.hxx index a7a7094..8042669 100644 --- a/cli/options.hxx +++ b/cli/options.hxx @@ -8,6 +8,7 @@ #include #include #include +#include #include namespace cli @@ -239,13 +240,37 @@ namespace cli public: argv_file_scanner (int& argc, char** argv, - const std::string& file_option, + const std::string& option, + bool erase = false); + + argv_file_scanner (int start, + int& argc, + char** argv, + const std::string& option, bool erase = false); + struct option_info + { + // If search_func is not NULL, it is called, with the arg + // value as the second argument, to locate the options file. + // If it returns an empty string, then the file is ignored. + // + const char* option; + std::string (*search_func) (const char*, void* arg); + void* arg; + }; + + argv_file_scanner (int& argc, + char** argv, + const option_info* options, + std::size_t options_count, + bool erase = false); + argv_file_scanner (int start, int& argc, char** argv, - const std::string& file_option, + const option_info* options, + std::size_t options_count, bool erase = false); virtual bool @@ -261,12 +286,19 @@ namespace cli skip (); private: + const option_info* + find (const char*) const; + void - load (const char* file); + load (const std::string& file); typedef argv_scanner base; const std::string option_; + option_info option_info_; + const option_info* options_; + std::size_t options_count_; + std::string hold_; std::deque args_; bool skip_; @@ -284,7 +316,6 @@ namespace cli class options { public: - options (int& argc, char** argv, bool erase = false, @@ -319,7 +350,6 @@ class options // Option accessors. // - const bool& help () const; @@ -356,6 +386,9 @@ class options const std::size_t& option_length () const; + const bool& + exclude_base () const; + const std::string& cli_namespace () const; @@ -427,6 +460,14 @@ class options static void print_usage (::std::ostream&); + // Implementation details. + // + protected: + options (); + + bool + _parse (const char*, ::cli::scanner&); + private: void _parse (::cli::scanner&, @@ -446,6 +487,7 @@ class options bool suppress_usage_; bool long_usage_; std::size_t option_length_; + bool exclude_base_; std::string cli_namespace_; bool generate_cxx_; bool generate_man_; -- cgit v1.1