From 7c83b407648f1ef919218d8965d4c21378910755 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 2 Sep 2015 17:06:10 +0200 Subject: Add --generate-parse option When specified, CLI will generate parse() functions instead of parsing constructors. This is primarily useful for being able to parse into an already initialized options class instance, for example, to implement merging/overriding. --- cli/source.cxx | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'cli/source.cxx') diff --git a/cli/source.cxx b/cli/source.cxx index 6a8ea76..1e0be15 100644 --- a/cli/source.cxx +++ b/cli/source.cxx @@ -535,12 +535,18 @@ namespace if (!abst) { - os << name << "::" << endl - << name << " (int& argc," << endl + bool p (options.generate_parse ()); + string n ( + p + ? "void " + name + "::\n" + (name != "parse" ? "parse" : "parse_") + : name + "::\n" + name); + + os << n << " (int& argc," << endl << "char** argv," << endl << "bool erase," << endl << um << " opt," << endl << um << " arg)"; + if (!p) { option_init init (*this); traversal::names names_init (init); @@ -551,13 +557,13 @@ namespace << "_parse (s, opt, arg);" << "}"; - os << name << "::" << endl - << name << " (int start," << endl + os << n << " (int start," << endl << "int& argc," << endl << "char** argv," << endl << "bool erase," << endl << um << " opt," << endl << um << " arg)"; + if (!p) { option_init init (*this); traversal::names names_init (init); @@ -568,13 +574,13 @@ namespace << "_parse (s, opt, arg);" << "}"; - os << name << "::" << endl - << name << " (int& argc," << endl + os << n << " (int& argc," << endl << "char** argv," << endl << "int& end," << endl << "bool erase," << endl << um << " opt," << endl << um << " arg)"; + if (!p) { option_init init (*this); traversal::names names_init (init); @@ -586,14 +592,14 @@ namespace << "end = s.end ();" << "}"; - os << name << "::" << endl - << name << " (int start," << endl + os << n << " (int start," << endl << "int& argc," << endl << "char** argv," << endl << "int& end," << endl << "bool erase," << endl << um << " opt," << endl << um << " arg)"; + if (!p) { option_init init (*this); traversal::names names_init (init); @@ -605,10 +611,10 @@ namespace << "end = s.end ();" << "}"; - os << name << "::" << endl - << name << " (" << cli << "::scanner& s," << endl + os << n << " (" << cli << "::scanner& s," << endl << um << " opt," << endl << um << " arg)"; + if (!p) { option_init init (*this); traversal::names names_init (init); -- cgit v1.1