From 0b4fcbeae101f2a5171217f65bab9c6545e853ba Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 19 Nov 2010 10:12:22 +0200 Subject: Add option description that can be examined at runtime. New option: --generate-description. --- cli/header.cxx | 13 +++++- cli/options.cli | 5 +++ cli/options.cxx | 10 +++++ cli/options.hxx | 4 ++ cli/options.ixx | 6 +++ cli/runtime-header.cxx | 57 ++++++++++++++++++++++++++ cli/runtime-inline.cxx | 54 ++++++++++++++++++++++++ cli/runtime-source.cxx | 19 +++++++++ cli/source.cxx | 109 +++++++++++++++++++++++++++++++++++++++++++++++-- 9 files changed, 273 insertions(+), 4 deletions(-) (limited to 'cli') diff --git a/cli/header.cxx b/cli/header.cxx index 7905b22..d1b078f 100644 --- a/cli/header.cxx +++ b/cli/header.cxx @@ -135,7 +135,7 @@ namespace names (c, names_option_); - // usage + // Usage. // if (usage) { @@ -146,6 +146,17 @@ namespace << endl; } + // Description. + // + if (options.generate_description ()) + { + os << "// Option description." << endl + << "//" << endl + << "static const " << cli << "::options&" << endl + << "description ();" + << endl; + } + // _parse() // os << "private:" << endl diff --git a/cli/options.cli b/cli/options.cli index ccafa68..a1cc3b4 100644 --- a/cli/options.cli +++ b/cli/options.cli @@ -34,6 +34,11 @@ class options on the command line." }; + bool --generate-description + { + "Generate the option description list that can be examined at runtime." + }; + bool --generate-file-scanner { "Generate the \c{argv_file_scanner} implementation. This scanner is diff --git a/cli/options.cxx b/cli/options.cxx index 093fd55..c8a83df 100644 --- a/cli/options.cxx +++ b/cli/options.cxx @@ -527,6 +527,7 @@ options (int& argc, output_dir_ (), generate_modifier_ (), generate_specifier_ (), + generate_description_ (), generate_file_scanner_ (), suppress_inline_ (), suppress_undocumented_ (), @@ -572,6 +573,7 @@ options (int start, output_dir_ (), generate_modifier_ (), generate_specifier_ (), + generate_description_ (), generate_file_scanner_ (), suppress_inline_ (), suppress_undocumented_ (), @@ -617,6 +619,7 @@ options (int& argc, output_dir_ (), generate_modifier_ (), generate_specifier_ (), + generate_description_ (), generate_file_scanner_ (), suppress_inline_ (), suppress_undocumented_ (), @@ -664,6 +667,7 @@ options (int start, output_dir_ (), generate_modifier_ (), generate_specifier_ (), + generate_description_ (), generate_file_scanner_ (), suppress_inline_ (), suppress_undocumented_ (), @@ -707,6 +711,7 @@ options (::cli::scanner& s, output_dir_ (), generate_modifier_ (), generate_specifier_ (), + generate_description_ (), generate_file_scanner_ (), suppress_inline_ (), suppress_undocumented_ (), @@ -755,6 +760,9 @@ print_usage (::std::ostream& os) os << "--generate-specifier Generate functions for determining whether the" << ::std::endl << " option was specified on the command line." << ::std::endl; + os << "--generate-description Generate the option description list that can be" << ::std::endl + << " examined at runtime." << ::std::endl; + os << "--generate-file-scanner Generate the 'argv_file_scanner' implementation." << ::std::endl; os << "--suppress-inline Generate all functions non-inline." << ::std::endl; @@ -857,6 +865,8 @@ struct _cli_options_map_init &::cli::thunk< options, bool, &options::generate_modifier_ >; _cli_options_map_["--generate-specifier"] = &::cli::thunk< options, bool, &options::generate_specifier_ >; + _cli_options_map_["--generate-description"] = + &::cli::thunk< options, bool, &options::generate_description_ >; _cli_options_map_["--generate-file-scanner"] = &::cli::thunk< options, bool, &options::generate_file_scanner_ >; _cli_options_map_["--suppress-inline"] = diff --git a/cli/options.hxx b/cli/options.hxx index d8a880d..a7a7094 100644 --- a/cli/options.hxx +++ b/cli/options.hxx @@ -336,6 +336,9 @@ class options generate_specifier () const; const bool& + generate_description () const; + + const bool& generate_file_scanner () const; const bool& @@ -436,6 +439,7 @@ class options std::string output_dir_; bool generate_modifier_; bool generate_specifier_; + bool generate_description_; bool generate_file_scanner_; bool suppress_inline_; bool suppress_undocumented_; diff --git a/cli/options.ixx b/cli/options.ixx index 9c9afda..f2072fe 100644 --- a/cli/options.ixx +++ b/cli/options.ixx @@ -192,6 +192,12 @@ generate_specifier () const } inline const bool& options:: +generate_description () const +{ + return this->generate_description_; +} + +inline const bool& options:: generate_file_scanner () const { return this->generate_file_scanner_; diff --git a/cli/runtime-header.cxx b/cli/runtime-header.cxx index 99da036..de24073 100644 --- a/cli/runtime-header.cxx +++ b/cli/runtime-header.cxx @@ -15,6 +15,10 @@ generate_runtime_header (context& ctx) if (ctx.options.generate_file_scanner ()) os << "#include " << endl; + if (ctx.options.generate_description ()) + os << "#include " << endl + << "#include " << endl; + os << "#include " << endl << "#include " << endl << "#include " << endl @@ -299,5 +303,58 @@ generate_runtime_header (context& ctx) os << "};"; } + // Option description. + // + if (ctx.options.generate_description ()) + { + os << "typedef std::vector option_names;" + << endl; + + os << "class option" + << "{" + << "public:" << endl + << endl + << "const std::string&" << endl + << "name () const;" + << endl + << "const option_names&" << endl + << "aliases () const;" + << endl + << "bool" << endl + << "flag () const;" + << endl + << "const std::string&" << endl + << "default_value () const;" + << endl + << "public:" + << "option ();" + << "option (const std::string& name," << endl + << "const option_names& aliases," << endl + << "bool flag," << endl + << "const std::string& default_value);" + << endl + << "private:" + << "std::string name_;" + << "option_names aliases_;" + << "bool flag_;" + << "std::string default_value_;" + << "};"; + + os << "class options: public std::vector