From 443293aaf09eca7c3b88d621d056c4effee2c248 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 10 May 2012 17:54:18 +0200 Subject: 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. --- cli/header.cxx | 150 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 104 insertions(+), 46 deletions(-) (limited to 'cli/header.cxx') 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 -- cgit v1.1