summaryrefslogtreecommitdiff
path: root/cli/source.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-02 17:06:10 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-02 17:06:10 +0200
commit7c83b407648f1ef919218d8965d4c21378910755 (patch)
tree52f62723ccf07bb59a45737cb2d0fc89ae691f4f /cli/source.cxx
parent2eb28736a05c7083f2b30b501954a789bbd85f88 (diff)
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.
Diffstat (limited to 'cli/source.cxx')
-rw-r--r--cli/source.cxx26
1 files changed, 16 insertions, 10 deletions
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);