From 63229f465aaea8dd5553814535220817319a64f5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 4 May 2015 21:22:14 +0200 Subject: Cleanup the code --- brep/module | 2 +- brep/module.cxx | 61 +++++++++++++------------------------------------------- brep/options.cli | 7 ++++--- brep/search | 4 ++-- brep/search.cxx | 6 +++--- brep/view | 4 ++-- brep/view.cxx | 6 +++--- 7 files changed, 29 insertions(+), 61 deletions(-) (limited to 'brep') diff --git a/brep/module b/brep/module index d1399fb..ef9154f 100644 --- a/brep/module +++ b/brep/module @@ -106,7 +106,7 @@ namespace brep // options. // virtual void - init (::cli::scanner& s) + init (cli::scanner& s) { // Just scan options to ensure there is no misspelled ones. // diff --git a/brep/module.cxx b/brep/module.cxx index fc239ba..612e521 100644 --- a/brep/module.cxx +++ b/brep/module.cxx @@ -7,7 +7,7 @@ #include #include -#include // unique_ptr +#include #include #include #include @@ -41,7 +41,7 @@ namespace brep try { static const char* sev_str[] = {"error", "warning", "info", "trace"}; - ostream& o = rs.content (500, "text/plain;charset=utf-8"); + ostream& o (rs.content (500, "text/plain;charset=utf-8")); for (const auto& d: e.data) { @@ -81,16 +81,16 @@ namespace brep init (const name_values& options, log& log) { log_ = &log; - - int argc = 0; - unique_ptr argv (new const char*[options.size () * 2]); + vector argv; for (const auto& nv: options) { - argv[argc++] = nv.name.c_str (); - argv[argc++] = nv.value.c_str (); + argv.push_back (nv.name.c_str ()); + argv.push_back (nv.value.c_str ()); } + int argc (argv.size()); + try { { @@ -98,7 +98,7 @@ namespace brep // cli::argv_file_scanner s (0, argc, - const_cast (argv.get ()), + const_cast (argv.data ()), "conf"); init (s); @@ -108,13 +108,10 @@ namespace brep // cli::argv_file_scanner s (0, argc, - const_cast (argv.get ()), + const_cast (argv.data ()), "conf"); - module_options o (s, - ::cli::unknown_mode::skip, - ::cli::unknown_mode::skip); - + module_options o (s, cli::unknown_mode::skip, cli::unknown_mode::skip); verb_ = o.verb (); } catch (const server_error& e) @@ -149,7 +146,7 @@ namespace brep string module:: func_name (const char* pretty_name) { - const char* e = strchr (pretty_name, ')'); + const char* e (strchr (pretty_name, ')')); if (e && e > pretty_name) { @@ -198,7 +195,9 @@ namespace brep if (log_ == nullptr) return; // No backend yet. - auto al = dynamic_cast<::web::apache::log*> (log_); + //@@ Cast log_ to apache::log and write the records. + // + auto al (dynamic_cast<::web::apache::log*> (log_)); if (al) { @@ -228,37 +227,5 @@ namespace brep e.msg.c_str ()); } } - - //@@ Cast log_ to apache::log and write the records. - // - - //@@ __PRETTY_FUNCTION__ contains a lot of fluff that we probably - // don't want in the logs (like return value and argument list; - // though the argument list would distinguish between several - // overloads). If that's the case, then this is probably the - // best place to process the name and convert something like: - // - // void module::handle(request, response) - // - // To just: - // - // module::handle - // - // Note to someone who is going to implement this: searching for a - // space to determine the end of the return type may not work if - // the return type is, say, a template id or a pointer to function - // type. It seems a more robust approach would be to scan backwards - // until we find the first ')' -- this got to be the end of the - // function argument list. Now we continue scanning backwards keeping - // track of the ')' vs '(' balance (arguments can also be of pointer - // to function type). Once we see an unbalanced '(', then we know this - // is the beginning of the argument list. Everything between it and - // the preceding space is the qualified function name. Good luck ;-). - // - // If we also use the name in handle() above (e.g., to return to - // the user as part of 505), then we should do it there as well - // (in which case factoring this functionality into a separate - // function seem to make a lot of sense). - // } } diff --git a/brep/options.cli b/brep/options.cli index cbd5d3a..8da666f 100644 --- a/brep/options.cli +++ b/brep/options.cli @@ -1,21 +1,22 @@ include ; +include ; namespace brep { class module_options { - unsigned int verb = 0; + std::uint16_t verb = 0; }; class db_options { std::string db-host = "localhost"; - unsigned short db-port = 3306; + std::uint16_t db-port = 3306; }; class search_options: module_options, db_options { - unsigned int results-on-page = 10; + size_t results-on-page = 10; }; class view_options: module_options, db_options diff --git a/brep/search b/brep/search index d744c30..b604db4 100644 --- a/brep/search +++ b/brep/search @@ -14,12 +14,12 @@ namespace brep { class search: public module { - public: + private: virtual void handle (request&, response&); virtual void - init (::cli::scanner&); + init (cli::scanner&); private: std::shared_ptr options_; diff --git a/brep/search.cxx b/brep/search.cxx index 5f9f507..e282f79 100644 --- a/brep/search.cxx +++ b/brep/search.cxx @@ -15,13 +15,13 @@ using namespace std; namespace brep { void search:: - init (::cli::scanner& s) + init (cli::scanner& s) { MODULE_DIAG; options_ = make_shared (s, - ::cli::unknown_mode::fail, - ::cli::unknown_mode::fail); + cli::unknown_mode::fail, + cli::unknown_mode::fail); if (options_->results_on_page () > 30) fail << "too many search results on page: " diff --git a/brep/view b/brep/view index da31481..a418872 100644 --- a/brep/view +++ b/brep/view @@ -14,12 +14,12 @@ namespace brep { class view: public module { - public: + private: virtual void handle (request&, response&); virtual void - init (::cli::scanner&); + init (cli::scanner&); private: std::shared_ptr options_; diff --git a/brep/view.cxx b/brep/view.cxx index a644aec..1402d1f 100644 --- a/brep/view.cxx +++ b/brep/view.cxx @@ -14,11 +14,11 @@ using namespace std; namespace brep { void view:: - init (::cli::scanner& s) + init (cli::scanner& s) { options_ = make_shared (s, - ::cli::unknown_mode::fail, - ::cli::unknown_mode::fail); + cli::unknown_mode::fail, + cli::unknown_mode::fail); } void view:: -- cgit v1.1