From aa33636c20b65dbf87e2189dc3d8759b883e7909 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 11 May 2012 12:25:53 +0200 Subject: Add support for specifying multiple classes with --class option --- cli/html.cxx | 40 ++++++++++++++++++++++++++++------------ cli/man.cxx | 40 ++++++++++++++++++++++++++++------------ cli/options.cli | 12 +++++++----- cli/options.cxx | 4 ++-- cli/options.hxx | 4 ++-- cli/options.ixx | 2 +- 6 files changed, 68 insertions(+), 34 deletions(-) diff --git a/cli/html.cxx b/cli/html.cxx index 1f0c328..8897f4e 100644 --- a/cli/html.cxx +++ b/cli/html.cxx @@ -3,8 +3,13 @@ // copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC // license : MIT; see accompanying LICENSE file +#include +#include + #include "html.hxx" +using namespace std; + namespace { struct option: traversal::option, context @@ -169,17 +174,6 @@ namespace virtual void traverse (type& c) { - string const& n (options.class_ ()); - - if (!n.empty ()) - { - string fqn (fq_name (c, false)); - fqn = string (fqn, 2, fqn.size () - 2); // Get rid of leading ::. - - if (n != fqn) - return; - } - if (!options.exclude_base ()) inherits (c, inherits_base_); @@ -213,7 +207,29 @@ generate_html (context& ctx) ctx.os << "
" << endl; - unit.dispatch (ctx.unit); + if (ctx.options.class_ ().empty ()) + unit.dispatch (ctx.unit); + else + { + for (vector::const_iterator i (ctx.options.class_ ().begin ()); + i != ctx.options.class_ ().end (); ++i) + { + string n (*i); + + // Strip leading :: if present. + // + if (n.size () > 2 && n[0] == ':' && n[1] == ':') + n = string (n, 2, string::npos); + + if (semantics::class_* c = ctx.unit.lookup ("", n)) + cl.traverse (*c); + else + { + cerr << "error: class '" << *i << "' not found" << endl; + throw generation_failed (); + } + } + } ctx.os << "
" << endl; } diff --git a/cli/man.cxx b/cli/man.cxx index ac5d9b1..576ee04 100644 --- a/cli/man.cxx +++ b/cli/man.cxx @@ -3,8 +3,13 @@ // copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC // license : MIT; see accompanying LICENSE file +#include +#include + #include "man.hxx" +using namespace std; + namespace { struct option: traversal::option, context @@ -129,17 +134,6 @@ namespace virtual void traverse (type& c) { - string const& n (options.class_ ()); - - if (!n.empty ()) - { - string fqn (fq_name (c, false)); - fqn = string (fqn, 2, fqn.size () - 2); // Get rid of leading ::. - - if (n != fqn) - return; - } - if (!options.exclude_base ()) inherits (c, inherits_base_); @@ -171,5 +165,27 @@ generate_man (context& ctx) ns >> ns_names >> ns; ns_names >> cl; - unit.dispatch (ctx.unit); + if (ctx.options.class_ ().empty ()) + unit.dispatch (ctx.unit); + else + { + for (vector::const_iterator i (ctx.options.class_ ().begin ()); + i != ctx.options.class_ ().end (); ++i) + { + string n (*i); + + // Strip leading :: if present. + // + if (n.size () > 2 && n[0] == ':' && n[1] == ':') + n = string (n, 2, string::npos); + + if (semantics::class_* c = ctx.unit.lookup ("", n)) + cl.traverse (*c); + else + { + cerr << "error: class '" << *i << "' not found" << endl; + throw generation_failed (); + } + } + } } diff --git a/cli/options.cli b/cli/options.cli index 074e7a9..ad91ddc 100644 --- a/cli/options.cli +++ b/cli/options.cli @@ -20,7 +20,7 @@ class options std::vector --include-path | -I { "", - "Search for bracket-included (\cb{<>}) option files." + "Search for bracket-included (\cb{<>}) options files." }; std::string --output-dir | -o @@ -138,14 +138,16 @@ class options "Insert the content of at the end of the HTML file." }; - std::string --class + std::vector --class { "", "Generate the man page or HTML documentation only for the options class. The name should be a fully-qualified options class name, - for example, \cb{app::options}. This functionality is useful if you need - to insert custom documentation between options belonging to different - classes." + for example, \cb{app::options}. To generate documentation for multiple + classes, repeat this option and the documentation will be produced in + the order specified. This functionality is useful if you need to assemble + documentation from multiple classes in a specific order or to insert + custom documentation between options belonging to different classes." }; bool --stdout diff --git a/cli/options.cxx b/cli/options.cxx index a720a2a..ed9645b 100644 --- a/cli/options.cxx +++ b/cli/options.cxx @@ -833,7 +833,7 @@ print_usage (::std::ostream& os) os << "--version Print version and exit." << ::std::endl; - os << "--include-path|-I Search for bracket-included ('<>') option" << ::std::endl + os << "--include-path|-I Search for bracket-included ('<>') options" << ::std::endl << " files." << ::std::endl; os << "--output-dir|-o Write the generated files to instead of the" << ::std::endl @@ -991,7 +991,7 @@ struct _cli_options_map_init _cli_options_map_["--html-epilogue"] = &::cli::thunk< options, std::string, &options::html_epilogue_ >; _cli_options_map_["--class"] = - &::cli::thunk< options, std::string, &options::class__ >; + &::cli::thunk< options, std::vector, &options::class__ >; _cli_options_map_["--stdout"] = &::cli::thunk< options, bool, &options::stdout__ >; _cli_options_map_["--hxx-suffix"] = diff --git a/cli/options.hxx b/cli/options.hxx index 748e7bb..61674fc 100644 --- a/cli/options.hxx +++ b/cli/options.hxx @@ -416,7 +416,7 @@ class options const std::string& html_epilogue () const; - const std::string& + const std::vector& class_ () const; const bool& @@ -500,7 +500,7 @@ class options std::string man_epilogue_; std::string html_prologue_; std::string html_epilogue_; - std::string class__; + std::vector class__; bool stdout__; std::string hxx_suffix_; std::string ixx_suffix_; diff --git a/cli/options.ixx b/cli/options.ixx index 34efe21..8d8a35f 100644 --- a/cli/options.ixx +++ b/cli/options.ixx @@ -328,7 +328,7 @@ html_epilogue () const return this->html_epilogue_; } -inline const std::string& options:: +inline const std::vector& options:: class_ () const { return this->class__; -- cgit v1.1