From a376ccf37122f0768fce8e3c5a16561e01ee2351 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 22 Nov 2009 16:58:56 +0200 Subject: Implement option value modifiers generation --- NEWS | 3 +++ cli/context.cxx | 2 ++ cli/context.hxx | 1 + cli/header.cxx | 7 +++++- cli/inline.cxx | 9 +++++++- cli/options.cli | 5 +++++ cli/options.cxx | 9 ++++++++ cli/options.hxx | 4 ++++ cli/options.ixx | 60 ++++++++++++++++++++++++++++----------------------- doc/cli.1 | 3 +++ doc/cli.xhtml | 3 +++ doc/guide/index.xhtml | 17 ++++++++------- 12 files changed, 86 insertions(+), 37 deletions(-) diff --git a/NEWS b/NEWS index f43c04c..0d5f8f8 100644 --- a/NEWS +++ b/NEWS @@ -25,6 +25,9 @@ Version 1.1.0 The CLI compiler usage, HTML documentation, and man page are auto-generated using this feature. + * New option, --generate-modifier, triggers generation of the option value + modifiers in addition to the accessors. + Version 1.0.0 * First public release. diff --git a/cli/context.cxx b/cli/context.cxx index 05e15cc..76a97a4 100644 --- a/cli/context.cxx +++ b/cli/context.cxx @@ -99,6 +99,7 @@ context (ostream& os_, os (os_), unit (unit_), options (ops), + modifier (options.generate_modifier ()), usage (!options.suppress_usage ()), inl (data_->inl_), opt_prefix (options.option_prefix ()), @@ -119,6 +120,7 @@ context (context& c) os (c.os), unit (c.unit), options (c.options), + modifier (c.modifier), usage (c.usage), inl (c.inl), opt_prefix (c.opt_prefix), diff --git a/cli/context.hxx b/cli/context.hxx index 30539af..2b0c128 100644 --- a/cli/context.hxx +++ b/cli/context.hxx @@ -38,6 +38,7 @@ public: semantics::cli_unit& unit; options_type const& options; + bool modifier; bool usage; string const& inl; diff --git a/cli/header.cxx b/cli/header.cxx index b06c2bf..2749b6d 100644 --- a/cli/header.cxx +++ b/cli/header.cxx @@ -22,6 +22,11 @@ namespace os << "const " << type << "&" << endl << name << " () const;" << endl; + + if (modifier) + os << "void" << endl + << name << " (const " << type << "&);" + << endl; } }; @@ -98,7 +103,7 @@ namespace // // - os << "// Option accessors." << endl + os << "// Option accessors" << (modifier ? " and modifiers." : ".") << endl << "//" << endl << endl; diff --git a/cli/inline.cxx b/cli/inline.cxx index 23a87ff..a4db1da 100644 --- a/cli/inline.cxx +++ b/cli/inline.cxx @@ -23,8 +23,15 @@ namespace os << inl << "const " << type << "& " << scope << "::" << endl << name << " () const" << "{" - << "return " << emember (o) << ";" + << "return this->" << emember (o) << ";" << "}"; + + if (modifier) + os << inl << "void " << scope << "::" << endl + << name << "(const " << type << "& x)" + << "{" + << "this->" << emember (o) << " = x;" + << "}"; } }; diff --git a/cli/options.cli b/cli/options.cli index 085a26a..b9df64f 100644 --- a/cli/options.cli +++ b/cli/options.cli @@ -23,6 +23,11 @@ class options "Write the generated files to instead of the current directory." }; + bool --generate-modifier + { + "Generate option value modifiers in addition to accessors." + }; + bool --suppress-inline { "Generate all functions non-inline. By default simple functions are diff --git a/cli/options.cxx b/cli/options.cxx index 38ed14d..78b3f5f 100644 --- a/cli/options.cxx +++ b/cli/options.cxx @@ -241,6 +241,7 @@ options (int argc, : help_ (), version_ (), output_dir_ (), + generate_modifier_ (), suppress_inline_ (), suppress_usage_ (), long_usage_ (), @@ -278,6 +279,7 @@ options (int start, : help_ (), version_ (), output_dir_ (), + generate_modifier_ (), suppress_inline_ (), suppress_usage_ (), long_usage_ (), @@ -315,6 +317,7 @@ options (int argc, : help_ (), version_ (), output_dir_ (), + generate_modifier_ (), suppress_inline_ (), suppress_usage_ (), long_usage_ (), @@ -353,6 +356,7 @@ options (int start, : help_ (), version_ (), output_dir_ (), + generate_modifier_ (), suppress_inline_ (), suppress_usage_ (), long_usage_ (), @@ -391,6 +395,9 @@ print_usage (::std::ostream& os) os << "--output-dir|-o Write the generated files to instead of the" << ::std::endl << " current directory." << ::std::endl; + os << "--generate-modifier Generate option value modifiers in addition to" << ::std::endl + << " accessors." << ::std::endl; + os << "--suppress-inline Generate all functions non-inline." << ::std::endl; os << "--suppress-usage Suppress the generation of the usage printing code." << ::std::endl; @@ -477,6 +484,8 @@ struct _cli_options_map_init &::cli::thunk< options, std::string, &options::output_dir_ >; _cli_options_map_["-o"] = &::cli::thunk< options, std::string, &options::output_dir_ >; + _cli_options_map_["--generate-modifier"] = + &::cli::thunk< options, bool, &options::generate_modifier_ >; _cli_options_map_["--suppress-inline"] = &::cli::thunk< options, bool, &options::suppress_inline_ >; _cli_options_map_["--suppress-usage"] = diff --git a/cli/options.hxx b/cli/options.hxx index fdf7627..d5712d1 100644 --- a/cli/options.hxx +++ b/cli/options.hxx @@ -184,6 +184,9 @@ class options output_dir () const; const bool& + generate_modifier () const; + + const bool& suppress_inline () const; const bool& @@ -272,6 +275,7 @@ class options bool help_; bool version_; std::string output_dir_; + bool generate_modifier_; bool suppress_inline_; bool suppress_usage_; bool long_usage_; diff --git a/cli/options.ixx b/cli/options.ixx index 1745d4a..60afbda 100644 --- a/cli/options.ixx +++ b/cli/options.ixx @@ -91,162 +91,168 @@ namespace cli inline const bool& options:: help () const { - return help_; + return this->help_; } inline const bool& options:: version () const { - return version_; + return this->version_; } inline const std::string& options:: output_dir () const { - return output_dir_; + return this->output_dir_; +} + +inline const bool& options:: +generate_modifier () const +{ + return this->generate_modifier_; } inline const bool& options:: suppress_inline () const { - return suppress_inline_; + return this->suppress_inline_; } inline const bool& options:: suppress_usage () const { - return suppress_usage_; + return this->suppress_usage_; } inline const bool& options:: long_usage () const { - return long_usage_; + return this->long_usage_; } inline const std::size_t& options:: option_length () const { - return option_length_; + return this->option_length_; } inline const bool& options:: generate_cxx () const { - return generate_cxx_; + return this->generate_cxx_; } inline const bool& options:: generate_man () const { - return generate_man_; + return this->generate_man_; } inline const bool& options:: generate_html () const { - return generate_html_; + return this->generate_html_; } inline const std::string& options:: man_prologue () const { - return man_prologue_; + return this->man_prologue_; } inline const std::string& options:: man_epilogue () const { - return man_epilogue_; + return this->man_epilogue_; } inline const std::string& options:: html_prologue () const { - return html_prologue_; + return this->html_prologue_; } inline const std::string& options:: html_epilogue () const { - return html_epilogue_; + return this->html_epilogue_; } inline const std::string& options:: class_ () const { - return class__; + return this->class__; } inline const bool& options:: stdout () const { - return stdout_; + return this->stdout_; } inline const std::string& options:: hxx_suffix () const { - return hxx_suffix_; + return this->hxx_suffix_; } inline const std::string& options:: ixx_suffix () const { - return ixx_suffix_; + return this->ixx_suffix_; } inline const std::string& options:: cxx_suffix () const { - return cxx_suffix_; + return this->cxx_suffix_; } inline const std::string& options:: man_suffix () const { - return man_suffix_; + return this->man_suffix_; } inline const std::string& options:: html_suffix () const { - return html_suffix_; + return this->html_suffix_; } inline const std::string& options:: option_prefix () const { - return option_prefix_; + return this->option_prefix_; } inline const std::string& options:: option_separator () const { - return option_separator_; + return this->option_separator_; } inline const bool& options:: include_with_brackets () const { - return include_with_brackets_; + return this->include_with_brackets_; } inline const std::string& options:: include_prefix () const { - return include_prefix_; + return this->include_prefix_; } inline const std::string& options:: guard_prefix () const { - return guard_prefix_; + return this->guard_prefix_; } inline const std::map& options:: reserved_name () const { - return reserved_name_; + return this->reserved_name_; } diff --git a/doc/cli.1 b/doc/cli.1 index 2e9f180..7c89ace 100644 --- a/doc/cli.1 +++ b/doc/cli.1 @@ -70,6 +70,9 @@ Print version and exit\. .IP "\fB--output-dir\fP|\fB-o\fP \fIdir\fP" Write the generated files to \fIdir\fP instead of the current directory\. +.IP "\fB--generate-modifier\fP" +Generate option value modifiers in addition to accessors\. + .IP "\fB--suppress-inline\fP" Generate all functions non-inline\. By default simple functions are made inline\. This option suppresses creation of the inline file\. diff --git a/doc/cli.xhtml b/doc/cli.xhtml index 85dd4b9..e431f97 100644 --- a/doc/cli.xhtml +++ b/doc/cli.xhtml @@ -93,6 +93,9 @@
--output-dir|-o dir
Write the generated files to dir instead of the current directory.
+
--generate-modifier
+
Generate option value modifiers in addition to accessors.
+
--suppress-inline
Generate all functions non-inline. By default simple functions are made inline. This option suppresses creation of the inline file.
diff --git a/doc/guide/index.xhtml b/doc/guide/index.xhtml index a7ae6e7..89f56e7 100644 --- a/doc/guide/index.xhtml +++ b/doc/guide/index.xhtml @@ -607,9 +607,10 @@ public:

An option class is mapped to a C++ class with the same name. The C++ class defines a set of public overloaded constructors, a public copy constructor and an assignment operator, as well as a set of public - accessor functions corresponding to option definitions. It also - defines a public static print_usage() function that - can be used to print the usage information for the options + accessor functions and, if the --generate-modifier CLI + compiler option is specified, modifier functions corresponding to option + definitions. It also defines a public static print_usage() + function that can be used to print the usage information for the options defined by the class.

The argc/argv arguments in the overloaded constructors @@ -779,11 +780,11 @@ namespace cli

The name component specifies the option name as it will be entered in the command line. A name can contain any number of aliases separated - by |. The C++ accessor function name is derived from the - first name by removing any leading special characters, such as - -, /, etc., and replacing special characters - in other places with underscores. For example, the following option - definition:

+ by |. The C++ accessor and modifier function names are + derived from the first name by removing any leading special characters, + such as -, /, etc., and replacing special + characters in other places with underscores. For example, the following + option definition:

 class options
-- 
cgit v1.1