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/header.cxx | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'cli/header.cxx') diff --git a/cli/header.cxx b/cli/header.cxx index ddf0895..6ff1f6b 100644 --- a/cli/header.cxx +++ b/cli/header.cxx @@ -129,14 +129,23 @@ namespace // if (!abst) { - os << name << " (int& argc," << endl + os << name << " ();" + << endl; + + // Are we generating parsing constructors or parse() functions? + // + string n (options.generate_parse () + ? string ("void\n") + (name != "parse" ? "parse" : "parse_") + : name); + + os << n << " (int& argc," << endl << "char** argv," << endl << "bool erase = false," << endl << um << " option = " << um << "::fail," << endl << um << " argument = " << um << "::stop);" << endl; - os << name << " (int start," << endl + os << n << " (int start," << endl << "int& argc," << endl << "char** argv," << endl << "bool erase = false," << endl @@ -144,7 +153,7 @@ namespace << um << " argument = " << um << "::stop);" << endl; - os << name << " (int& argc," << endl + os << n << " (int& argc," << endl << "char** argv," << endl << "int& end," << endl << "bool erase = false," << endl @@ -152,7 +161,7 @@ namespace << um << " argument = " << um << "::stop);" << endl; - os << name << " (int start," << endl + os << n << " (int start," << endl << "int& argc," << endl << "char** argv," << endl << "int& end," << endl @@ -161,13 +170,10 @@ namespace << um << " argument = " << um << "::stop);" << endl; - os << name << " (" << cli << "::scanner&," << endl + os << n << " (" << cli << "::scanner&," << endl << um << " option = " << um << "::fail," << endl << um << " argument = " << um << "::stop);" << endl; - - os << name << " ();" - << endl; } // -- cgit v1.1