template for engine registry; refs #11

This commit is contained in:
Marc Wäckerlin
2011-05-03 11:57:40 +00:00
parent 95efe61822
commit 1db5a9ab69
2 changed files with 13 additions and 7 deletions

View File

@@ -279,25 +279,31 @@ namespace openssl {
//! Scoped Engine Registry
/*! Engine will be deregistered and freed at destruction */
class RegisterEngine {
template <class ENGINE=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;
};
//@}