From 1db5a9ab69df20c382979b3fa95050c27cc45a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Tue, 3 May 2011 11:57:40 +0000 Subject: [PATCH] template for engine registry; refs #11 --- doc/examples/openssl-engine-demo.cxx | 2 +- src/openssl-engine.hxx | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/doc/examples/openssl-engine-demo.cxx b/doc/examples/openssl-engine-demo.cxx index 9b626ad..0cd52ec 100644 --- a/doc/examples/openssl-engine-demo.cxx +++ b/doc/examples/openssl-engine-demo.cxx @@ -25,7 +25,7 @@ class TestEngine: virtual public openssl::Engine { int main(int, char**) { { - openssl::RegisterEngine testEngine(new TestEngine); + openssl::RegisterEngine<> testEngine(new TestEngine); for (ENGINE* e(ENGINE_get_first()); e; e = ENGINE_get_next(e)) { std::cout<<"Found Engine: "< class RegisterEngine { public: - RegisterEngine(Engine* e): _e(e) { + RegisterEngine(ENGINE* e = 0): _e(e) { if (_e) EngineMapper::add(_e); } ~RegisterEngine() { if (_e) EngineMapper::remove(_e); } - operator Engine*() { + RegisterEngine& operator=(ENGINE* e) { + if (_e) EngineMapper::remove(_e); + _e = e; + if (_e) EngineMapper::add(_e); + return *this; + } + operator ENGINE*() { return _e; } - Engine* operator->() { + ENGINE* operator->() { return _e; } - Engine& operator*() { + ENGINE& operator*() { return *_e; } private: - Engine* _e; + ENGINE* _e; }; //@}