diff options
| author | Markus Engel <markus.engel@tum.de> | 2013-04-02 14:06:06 +0000 |
|---|---|---|
| committer | Markus Engel <markus.engel@tum.de> | 2013-04-02 14:06:06 +0000 |
| commit | 4a56b453e43a53508f13d263cde7cf083f00cd26 (patch) | |
| tree | bec14d62085ac818a0e89744c8febb75c7c88222 /src/sp-factory.cpp | |
| parent | Added constructors to SP classes. (diff) | |
| download | inkscape-4a56b453e43a53508f13d263cde7cf083f00cd26.tar.gz inkscape-4a56b453e43a53508f13d263cde7cf083f00cd26.zip | |
Added new factory for SPObject tree objects.
(bzr r11608.1.68)
Diffstat (limited to 'src/sp-factory.cpp')
| -rw-r--r-- | src/sp-factory.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/sp-factory.cpp b/src/sp-factory.cpp new file mode 100644 index 000000000..192f092ed --- /dev/null +++ b/src/sp-factory.cpp @@ -0,0 +1,28 @@ +#include "sp-factory.h" + +#include <stdexcept> + +#include "sp-object.h" + +SPFactory& SPFactory::instance() { + static SPFactory factory; + return factory; +} + +bool SPFactory::registerObject(std::string id, CreateObjectMethod* createFunction) { + return this->objectMap.insert(std::make_pair(id, createFunction)).second; +} + +SPObject* SPFactory::createObject(std::string id) const { + std::map<std::string, CreateObjectMethod*>::const_iterator entry = this->objectMap.find(id); + + if (entry == objectMap.end()) { + //g_warning("Factory: Type \"%s\" not registered!", id.c_str()); +// SPObject* o = new SPObject(); +// +// return o; + return 0; + } + + return (entry->second)(); +} |
