summaryrefslogtreecommitdiff
path: root/cli/header.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-05-10 17:54:18 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-05-10 17:54:18 +0200
commit443293aaf09eca7c3b88d621d056c4effee2c248 (patch)
treea35c7b2354295b5b73462c0806e04e2deef58171 /cli/header.cxx
parent4f9022f24c4591391637121c7274d9855b37bd93 (diff)
Implement option class inheritance
For now multiple, non-virtual inheritance is supported. An option class can now also be declared abstract using the class c = 0 {...}; syntax. New option, --exclude-base, controls whether base class information is present in usage and documentation.
Diffstat (limited to 'cli/header.cxx')
-rw-r--r--cli/header.cxx150
1 files changed, 104 insertions, 46 deletions
diff --git a/cli/header.cxx b/cli/header.cxx
index fb714ed..e16b592 100644
--- a/cli/header.cxx
+++ b/cli/header.cxx
@@ -65,6 +65,31 @@ namespace
//
//
+ struct base: traversal::class_, context
+ {
+ base (context& c): context (c), first_ (true) {}
+
+ virtual void
+ traverse (type& c)
+ {
+ if (first_)
+ {
+ os << ": ";
+ first_ = false;
+ }
+ else
+ os << "," << endl
+ << " ";
+
+ os << "public " << fq_name (c);
+ }
+
+ private:
+ bool first_;
+ };
+
+ //
+ //
struct class_: traversal::class_, context
{
class_ (context& c)
@@ -79,59 +104,67 @@ namespace
virtual void
traverse (type& c)
{
+ bool abst (c.abstract ());
string name (escape (c.name ()));
+ string um (cli + "::unknown_mode");
- os << "class " << name
- << "{"
- << "public:" << endl
- << endl;
+ os << "class " << name;
+
+ {
+ base b (*this);
+ traversal::inherits i (b);
+ inherits (c, i);
+ }
+
+ os << "{"
+ << "public:" << endl;
// c-tors
//
- string um (cli + "::unknown_mode");
-
- os << name << " (int& argc," << endl
- << "char** argv," << endl
- << "bool erase = false," << endl
- << um << " option = " << um << "::fail," << endl
- << um << " argument = " << um << "::stop);"
- << endl;
+ if (!abst)
+ {
+ os << name << " (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
- << "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
+ << "int& argc," << endl
+ << "char** argv," << endl
+ << "bool erase = false," << endl
+ << um << " option = " << um << "::fail," << endl
+ << um << " argument = " << um << "::stop);"
+ << endl;
- os << name << " (int& argc," << endl
- << "char** argv," << endl
- << "int& end," << endl
- << "bool erase = false," << endl
- << um << " option = " << um << "::fail," << endl
- << um << " argument = " << um << "::stop);"
- << endl;
+ os << name << " (int& argc," << endl
+ << "char** argv," << endl
+ << "int& end," << endl
+ << "bool erase = false," << endl
+ << um << " option = " << um << "::fail," << endl
+ << um << " argument = " << um << "::stop);"
+ << endl;
- os << name << " (int start," << endl
- << "int& argc," << endl
- << "char** argv," << endl
- << "int& end," << endl
- << "bool erase = false," << endl
- << um << " option = " << um << "::fail," << endl
- << um << " argument = " << um << "::stop);"
- << endl;
+ os << name << " (int start," << endl
+ << "int& argc," << endl
+ << "char** argv," << endl
+ << "int& end," << endl
+ << "bool erase = false," << endl
+ << um << " option = " << um << "::fail," << endl
+ << um << " argument = " << um << "::stop);"
+ << endl;
- os << name << " (" << cli << "::scanner&," << endl
- << um << " option = " << um << "::fail," << endl
- << um << " argument = " << um << "::stop);"
- << endl;
+ os << name << " (" << cli << "::scanner&," << endl
+ << um << " option = " << um << "::fail," << endl
+ << um << " argument = " << um << "::stop);"
+ << endl;
+ }
//
//
os << "// Option accessors" << (modifier ? " and modifiers." : ".") << endl
- << "//" << endl
- << endl;
+ << "//" << endl;
names (c, names_option_);
@@ -157,15 +190,40 @@ namespace
<< endl;
}
- // _parse()
+ os << "// Implementation details." << endl
+ << "//" << endl
+ << "protected:" << endl;
+
+ // default c-tor
+ //
+ os << name << " ();"
+ << endl;
+
+ // fill ()
+ //
+ if (options.generate_description ())
+ os << "friend struct _cli_" + name + "_desc_init;"
+ << endl
+ << "static void" << endl
+ << "fill (" << cli << "::options&);"
+ << endl;
+
+ // _parse ()
//
- os << "private:" << endl
- << "void" << endl
- << "_parse (" << cli << "::scanner&," << endl
- << um << " option," << endl
- << um << " argument);"
+ os << "bool" << endl
+ << "_parse (const char*, " << cli << "::scanner&);"
<< endl;
+ // _parse ()
+ //
+ if (!abst)
+ os << "private:" << endl
+ << "void" << endl
+ << "_parse (" << cli << "::scanner&," << endl
+ << um << " option," << endl
+ << um << " argument);"
+ << endl;
+
// Data members.
//
os << "public:" << endl; //@@ tmp