From 2d89c9d6aa0f2fcdd6403c4973f7e7005a6796a0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 9 Apr 2015 17:01:45 +0200 Subject: Reimplement apache::service without using virtual functions --- services.cxx | 4 ++-- web/apache/service | 31 +++++++++++++++---------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/services.cxx b/services.cxx index 746aefa..2da5bca 100644 --- a/services.cxx +++ b/services.cxx @@ -11,7 +11,7 @@ using namespace brep; using web::apache::service; static const search search_mod; -service AP_MODULE_DECLARE_DATA search_srv ("search", search_mod); +service AP_MODULE_DECLARE_DATA search_srv ("search", search_mod); static const view view_mod; -service AP_MODULE_DECLARE_DATA view_srv ("view", view_mod); +service AP_MODULE_DECLARE_DATA view_srv ("view", view_mod); diff --git a/web/apache/service b/web/apache/service index 3c7a398..2b97108 100644 --- a/web/apache/service +++ b/web/apache/service @@ -13,32 +13,31 @@ namespace web { namespace apache { - class service_common - { - //@@ Implementation that calls handle() below goes here. - // - - virtual void - handle (request&, response&, log&) = 0; - }; - - template - class service: public service_common + class service { public: // Note that the module exemplar is stored by-reference. // - service (const std::string& name, const M& exemplar); + template + service (const std::string& name, const M& exemplar) + : exemplar_ (exemplar), handle_ (&handle_impl) {} - virtual void - handle (request& rq, response& rs, log& l) + //@@ Implementation calls handle_ function pointer below: + // + // handle_ (rq, rs, l, exemplar_); + // + + private: + template + static void + handle_impl (request& rq, response& rs, log& l, const module& exemplar) { - M m (exemplar_); + M m (static_cast (exemplar)); m.handle (rq, rs, l); } - private: const M& exemplar_; + void (*handle_) (request&, response&, log&, const module&); }; } } -- cgit v1.1