From 4a56b453e43a53508f13d263cde7cf083f00cd26 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 2 Apr 2013 16:06:06 +0200 Subject: Added new factory for SPObject tree objects. (bzr r11608.1.68) --- src/sp-factory.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/sp-factory.cpp (limited to 'src/sp-factory.cpp') 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 + +#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::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)(); +} -- cgit v1.2.3