From e2605ba3c9ca35524b0c86e74ffa37bee548aef3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 15 Jun 2012 11:00:52 +0200 Subject: Add support for specifying output stream type (--stream-type) --- cli/header.cxx | 2 +- cli/options.cli | 7 +++++++ cli/options.cxx | 12 ++++++++++++ cli/options.hxx | 4 ++++ cli/options.ixx | 6 ++++++ cli/runtime-header.cxx | 22 ++++++++++++---------- cli/runtime-inline.cxx | 5 +++-- cli/runtime-source.cxx | 34 +++++++++++++++++++--------------- cli/source.cxx | 3 ++- 9 files changed, 66 insertions(+), 29 deletions(-) (limited to 'cli') diff --git a/cli/header.cxx b/cli/header.cxx index e16b592..60d6c6a 100644 --- a/cli/header.cxx +++ b/cli/header.cxx @@ -175,7 +175,7 @@ namespace os << "// Print usage information." << endl << "//" << endl << "static void" << endl - << "print_usage (::std::ostream&);" + << "print_usage (" << options.ostream_type () << "&);" << endl; } diff --git a/cli/options.cli b/cli/options.cli index ad91ddc..fe48219 100644 --- a/cli/options.cli +++ b/cli/options.cli @@ -58,6 +58,13 @@ class options made inline. This option suppresses creation of the inline file." }; + std::string --ostream-type = "::std::ostream" + { + "", + "Output stream type instead of the default \cb{std::ostream} that + should be used to print usage and exception information." + }; + bool --suppress-undocumented { "Suppress the generation of documentation entries for undocumented diff --git a/cli/options.cxx b/cli/options.cxx index ed9645b..0b79417 100644 --- a/cli/options.cxx +++ b/cli/options.cxx @@ -558,6 +558,7 @@ options () generate_description_ (), generate_file_scanner_ (), suppress_inline_ (), + ostream_type_ ("::std::ostream"), suppress_undocumented_ (), suppress_usage_ (), long_usage_ (), @@ -603,6 +604,7 @@ options (int& argc, generate_description_ (), generate_file_scanner_ (), suppress_inline_ (), + ostream_type_ ("::std::ostream"), suppress_undocumented_ (), suppress_usage_ (), long_usage_ (), @@ -651,6 +653,7 @@ options (int start, generate_description_ (), generate_file_scanner_ (), suppress_inline_ (), + ostream_type_ ("::std::ostream"), suppress_undocumented_ (), suppress_usage_ (), long_usage_ (), @@ -699,6 +702,7 @@ options (int& argc, generate_description_ (), generate_file_scanner_ (), suppress_inline_ (), + ostream_type_ ("::std::ostream"), suppress_undocumented_ (), suppress_usage_ (), long_usage_ (), @@ -749,6 +753,7 @@ options (int start, generate_description_ (), generate_file_scanner_ (), suppress_inline_ (), + ostream_type_ ("::std::ostream"), suppress_undocumented_ (), suppress_usage_ (), long_usage_ (), @@ -795,6 +800,7 @@ options (::cli::scanner& s, generate_description_ (), generate_file_scanner_ (), suppress_inline_ (), + ostream_type_ ("::std::ostream"), suppress_undocumented_ (), suppress_usage_ (), long_usage_ (), @@ -852,6 +858,10 @@ print_usage (::std::ostream& os) os << "--suppress-inline Generate all functions non-inline." << ::std::endl; + os << "--ostream-type Output stream type instead of the default" << ::std::endl + << " 'std::ostream' that should be used to print usage" << ::std::endl + << " and exception information." << ::std::endl; + os << "--suppress-undocumented Suppress the generation of documentation entries" << ::std::endl << " for undocumented options." << ::std::endl; @@ -964,6 +974,8 @@ struct _cli_options_map_init &::cli::thunk< options, bool, &options::generate_file_scanner_ >; _cli_options_map_["--suppress-inline"] = &::cli::thunk< options, bool, &options::suppress_inline_ >; + _cli_options_map_["--ostream-type"] = + &::cli::thunk< options, std::string, &options::ostream_type_ >; _cli_options_map_["--suppress-undocumented"] = &::cli::thunk< options, bool, &options::suppress_undocumented_ >; _cli_options_map_["--suppress-usage"] = diff --git a/cli/options.hxx b/cli/options.hxx index 61674fc..64c52e7 100644 --- a/cli/options.hxx +++ b/cli/options.hxx @@ -377,6 +377,9 @@ class options const bool& suppress_inline () const; + const std::string& + ostream_type () const; + const bool& suppress_undocumented () const; @@ -487,6 +490,7 @@ class options bool generate_description_; bool generate_file_scanner_; bool suppress_inline_; + std::string ostream_type_; bool suppress_undocumented_; bool suppress_usage_; bool long_usage_; diff --git a/cli/options.ixx b/cli/options.ixx index 8d8a35f..1b56750 100644 --- a/cli/options.ixx +++ b/cli/options.ixx @@ -250,6 +250,12 @@ suppress_inline () const return this->suppress_inline_; } +inline const std::string& options:: +ostream_type () const +{ + return this->ostream_type_; +} + inline const bool& options:: suppress_undocumented () const { diff --git a/cli/runtime-header.cxx b/cli/runtime-header.cxx index f0b3cc1..4e9ba59 100644 --- a/cli/runtime-header.cxx +++ b/cli/runtime-header.cxx @@ -48,6 +48,8 @@ generate_runtime_header (context& ctx) // Exceptions. // + string const& os_type (ctx.options.ostream_type ()); + os << "// Exceptions." << endl << "//" << endl << endl; @@ -56,11 +58,11 @@ generate_runtime_header (context& ctx) << "{" << "public:" << endl << "virtual void" << endl - << "print (std::ostream&) const = 0;" + << "print (" << os_type << "&) const = 0;" << "};"; - os << "std::ostream&" << endl - << "operator<< (std::ostream&, const exception&);" + os << os_type << "&" << endl + << "operator<< (" << os_type << "&, const exception&);" << endl; os << "class unknown_option: public exception" @@ -75,7 +77,7 @@ generate_runtime_header (context& ctx) << "option () const;" << endl << "virtual void" << endl - << "print (std::ostream&) const;" + << "print (" << os_type << "&) const;" << endl << "virtual const char*" << endl << "what () const throw ();" @@ -96,7 +98,7 @@ generate_runtime_header (context& ctx) << "argument () const;" << endl << "virtual void" << endl - << "print (std::ostream&) const;" + << "print (" << os_type << "&) const;" << endl << "virtual const char*" << endl << "what () const throw ();" @@ -117,7 +119,7 @@ generate_runtime_header (context& ctx) << "option () const;" << endl << "virtual void" << endl - << "print (std::ostream&) const;" + << "print (" << os_type << "&) const;" << endl << "virtual const char*" << endl << "what () const throw ();" @@ -142,7 +144,7 @@ generate_runtime_header (context& ctx) << "value () const;" << endl << "virtual void" << endl - << "print (std::ostream&) const;" + << "print (" << os_type << "&) const;" << endl << "virtual const char*" << endl << "what () const throw ();" @@ -156,7 +158,7 @@ generate_runtime_header (context& ctx) << "{" << "public:" << endl << "virtual void" << endl - << "print (std::ostream&) const;" + << "print (" << os_type << "&) const;" << endl << "virtual const char*" << endl << "what () const throw ();" @@ -176,7 +178,7 @@ generate_runtime_header (context& ctx) << "file () const;" << endl << "virtual void" << endl - << "print (std::ostream&) const;" + << "print (" << os_type << "&) const;" << endl << "virtual const char*" << endl << "what () const throw ();" @@ -197,7 +199,7 @@ generate_runtime_header (context& ctx) << "argument () const;" << endl << "virtual void" << endl - << "print (std::ostream&) const;" + << "print (" << os_type << "&) const;" << endl << "virtual const char*" << endl << "what () const throw ();" diff --git a/cli/runtime-inline.cxx b/cli/runtime-inline.cxx index 4d95a78..cb0e0e4 100644 --- a/cli/runtime-inline.cxx +++ b/cli/runtime-inline.cxx @@ -12,6 +12,7 @@ generate_runtime_inline (context& ctx) { ostream& os (ctx.os); string const& inl (ctx.inl); + string const& os_type (ctx.options.ostream_type ()); ctx.cli_open (); @@ -31,8 +32,8 @@ generate_runtime_inline (context& ctx) os << "// exception" << endl << "//" << endl - << inl << "std::ostream&" << endl - << "operator<< (std::ostream& os, const exception& e)" + << inl << os_type << "&" << endl + << "operator<< (" << os_type << "& os, const exception& e)" << "{" << "e.print (os);" << "return os;" diff --git a/cli/runtime-source.cxx b/cli/runtime-source.cxx index 5964fdd..cff4e7b 100644 --- a/cli/runtime-source.cxx +++ b/cli/runtime-source.cxx @@ -29,6 +29,8 @@ generate_runtime_source (context& ctx, bool complete) if (complete) { + string const& os_type (ctx.options.ostream_type ()); + // unknown_option // os << "// unknown_option" << endl @@ -39,9 +41,9 @@ generate_runtime_source (context& ctx, bool complete) << "}" << "void unknown_option::" << endl - << "print (std::ostream& os) const" + << "print (" << os_type << "& os) const" << "{" - << "os << \"unknown option '\" << option () << \"'\";" + << "os << \"unknown option '\" << option ().c_str () << \"'\";" << "}" << "const char* unknown_option::" << endl @@ -60,9 +62,9 @@ generate_runtime_source (context& ctx, bool complete) << "}" << "void unknown_argument::" << endl - << "print (std::ostream& os) const" + << "print (" << os_type << "& os) const" << "{" - << "os << \"unknown argument '\" << argument () << \"'\";" + << "os << \"unknown argument '\" << argument ().c_str () << \"'\";" << "}" << "const char* unknown_argument::" << endl @@ -81,9 +83,9 @@ generate_runtime_source (context& ctx, bool complete) << "}" << "void missing_value::" << endl - << "print (std::ostream& os) const" + << "print (" << os_type << "& os) const" << "{" - << "os << \"missing value for option '\" << option () << \"'\";" + << "os << \"missing value for option '\" << option ().c_str () << \"'\";" << "}" << "const char* missing_value::" << endl @@ -102,10 +104,11 @@ generate_runtime_source (context& ctx, bool complete) << "}" << "void invalid_value::" << endl - << "print (std::ostream& os) const" + << "print (" << os_type << "& os) const" << "{" - << "os << \"invalid value '\" << value () << \"' for option '\"" << endl - << " << option () << \"'\";" + << "os << \"invalid value '\" << value ().c_str () << \"' for " << + "option '\"" << endl + << " << option ().c_str () << \"'\";" << "}" << "const char* invalid_value::" << endl @@ -119,7 +122,7 @@ generate_runtime_source (context& ctx, bool complete) os << "// eos_reached" << endl << "//" << endl << "void eos_reached::" << endl - << "print (std::ostream& os) const" + << "print (" << os_type << "& os) const" << "{" << "os << what ();" << "}" @@ -142,10 +145,10 @@ generate_runtime_source (context& ctx, bool complete) << "}" << "void file_io_failure::" << endl - << "print (std::ostream& os) const" + << "print (" << os_type << "& os) const" << "{" - << "os << \"unable to open file '\" << file () << \"' or read " << - "failure\";" + << "os << \"unable to open file '\" << file ().c_str () << " << + "\"' or read failure\";" << "}" << "const char* file_io_failure::" << endl @@ -164,9 +167,10 @@ generate_runtime_source (context& ctx, bool complete) << "}" << "void unmatched_quote::" << endl - << "print (std::ostream& os) const" + << "print (" << os_type << "& os) const" << "{" - << "os << \"unmatched quote in argument '\" << argument () << \"'\";" + << "os << \"unmatched quote in argument '\" << " << + "argument ().c_str () << \"'\";" << "}" << "const char* unmatched_quote::" << endl diff --git a/cli/source.cxx b/cli/source.cxx index 883e49d..7fb1391 100644 --- a/cli/source.cxx +++ b/cli/source.cxx @@ -690,7 +690,8 @@ namespace // If len is 0 then it means we have no options to print. // os << "void " << name << "::" << endl - << "print_usage (::std::ostream&" << (len != 0 || b ? " os)" : ")") + << "print_usage (" << options.ostream_type () << "&" << + (len != 0 || b ? " os)" : ")") << "{"; // Call our bases. -- cgit v1.1