aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-04-09 17:01:45 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-04-09 17:01:45 +0200
commit2d89c9d6aa0f2fcdd6403c4973f7e7005a6796a0 (patch)
tree1740bdeadd2cfb34f05d4f1f20f00f16b448592a /web
parent9d346aa8894e567d2871125826488c2ca181d0f5 (diff)
Reimplement apache::service without using virtual functions
Diffstat (limited to 'web')
-rw-r--r--web/apache/service31
1 files changed, 15 insertions, 16 deletions
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 <typename M>
- 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 <typename M>
+ service (const std::string& name, const M& exemplar)
+ : exemplar_ (exemplar), handle_ (&handle_impl<M>) {}
- virtual void
- handle (request& rq, response& rs, log& l)
+ //@@ Implementation calls handle_ function pointer below:
+ //
+ // handle_ (rq, rs, l, exemplar_);
+ //
+
+ private:
+ template <typename M>
+ static void
+ handle_impl (request& rq, response& rs, log& l, const module& exemplar)
{
- M m (exemplar_);
+ M m (static_cast<const M&> (exemplar));
m.handle (rq, rs, l);
}
- private:
const M& exemplar_;
+ void (*handle_) (request&, response&, log&, const module&);
};
}
}