diff options
| author | Markus Engel <markus.engel@tum.de> | 2013-04-13 16:13:17 +0000 |
|---|---|---|
| committer | Markus Engel <markus.engel@tum.de> | 2013-04-13 16:13:17 +0000 |
| commit | fbdc8b84ff670c684dafc7d7d403ed01e7077e70 (patch) | |
| tree | 964a82e4e94d8d6602e90893ac51ac9e2f7ec362 /src/sp-factory.h | |
| parent | Made factory a template. (diff) | |
| download | inkscape-fbdc8b84ff670c684dafc7d7d403ed01e7077e70.tar.gz inkscape-fbdc8b84ff670c684dafc7d7d403ed01e7077e70.zip | |
Replaced casting macros for EventContext tree; added contructors.
(bzr r11608.1.96)
Diffstat (limited to 'src/sp-factory.h')
| -rw-r--r-- | src/sp-factory.h | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/sp-factory.h b/src/sp-factory.h index 111375415..7eed7b744 100644 --- a/src/sp-factory.h +++ b/src/sp-factory.h @@ -15,12 +15,8 @@ struct Singleton { } }; -/** - * A Factory for creating objects which can be identified by strings. - */ -template<class BaseObject> -class Factory : public Singleton< Factory<BaseObject> > { -public: + +namespace FactoryExceptions { class TypeNotRegistered : public std::exception { public: TypeNotRegistered(const std::string& typeString) : std::exception(), typeString(typeString) { @@ -36,18 +32,25 @@ public: private: const std::string typeString; }; +} +/** + * A Factory for creating objects which can be identified by strings. + */ +template<class BaseObject> +class Factory { +public: typedef BaseObject* CreateFunction(); bool registerObject(const std::string& id, CreateFunction* createFunction) { return this->objectMap.insert(std::make_pair(id, createFunction)).second; } - BaseObject* createObject(const std::string& id) const { + BaseObject* createObject(const std::string& id) const throw(FactoryExceptions::TypeNotRegistered) { typename std::map<const std::string, CreateFunction*>::const_iterator it = this->objectMap.find(id); if (it == this->objectMap.end()) { - throw TypeNotRegistered(id); + throw FactoryExceptions::TypeNotRegistered(id); } return it->second(); @@ -59,10 +62,10 @@ private: class SPObject; -typedef Factory<SPObject> SPFactory; +typedef Singleton< Factory<SPObject> > SPFactory; class SPEventContext; -typedef Factory<SPEventContext> ToolFactory; +typedef Singleton< Factory<SPEventContext> > ToolFactory; |
