diff options
Diffstat (limited to 'include/astra/AstraObjectFactory.h')
-rw-r--r-- | include/astra/AstraObjectFactory.h | 58 |
1 files changed, 45 insertions, 13 deletions
diff --git a/include/astra/AstraObjectFactory.h b/include/astra/AstraObjectFactory.h index 1ed4955..6af9cd8 100644 --- a/include/astra/AstraObjectFactory.h +++ b/include/astra/AstraObjectFactory.h @@ -40,6 +40,10 @@ $Id$ #include "AlgorithmTypelist.h" +#ifdef ASTRA_PYTHON +#include "PluginAlgorithm.h" +#endif + namespace astra { @@ -59,20 +63,27 @@ public: */ ~CAstraObjectFactory(); - /** Create, but don't initialize, a new projector object. + /** Create, but don't initialize, a new object. * - * @param _sType Type of the new projector. - * @return Pointer to a new, unitialized projector. + * @param _sType Type of the new object. + * @return Pointer to a new, uninitialized object. */ T* create(std::string _sType); - /** Create and initialize a new projector object. + /** Create and initialize a new object. * - * @param _cfg Configuration object to create and initialize a new projector. + * @param _cfg Configuration object to create and initialize a new object. * @return Pointer to a new, initialized projector. */ T* create(const Config& _cfg); + /** Find a plugin. + * + * @param _sType Name of plugin to find. + * @return Pointer to a new, uninitialized object, or NULL if not found. + */ + T* findPlugin(std::string _sType); + }; @@ -93,6 +104,15 @@ CAstraObjectFactory<T, TypeList>::~CAstraObjectFactory() } + +//---------------------------------------------------------------------------------------- +// Hook for finding plugin in registered plugins. +template <typename T, typename TypeList> +T* CAstraObjectFactory<T, TypeList>::findPlugin(std::string _sType) +{ + return NULL; +} + //---------------------------------------------------------------------------------------- // Create template <typename T, typename TypeList> @@ -101,6 +121,9 @@ T* CAstraObjectFactory<T, TypeList>::create(std::string _sType) functor_find<T> finder = functor_find<T>(); finder.tofind = _sType; CreateObject<TypeList>::find(finder); + if (finder.res == NULL) { + finder.res = findPlugin(_sType); + } return finder.res; } @@ -109,14 +132,11 @@ T* CAstraObjectFactory<T, TypeList>::create(std::string _sType) template <typename T, typename TypeList> T* CAstraObjectFactory<T, TypeList>::create(const Config& _cfg) { - functor_find<T> finder = functor_find<T>(); - finder.tofind = _cfg.self.getAttribute("type"); - CreateObject<TypeList>::find(finder); - if (finder.res == NULL) return NULL; - if (finder.res->initialize(_cfg)) - return finder.res; - - delete finder.res; + T* object = create(_cfg.self.getAttribute("type")); + if (object == NULL) return NULL; + if (object->initialize(_cfg)) + return object; + delete object; return NULL; } //---------------------------------------------------------------------------------------- @@ -131,6 +151,18 @@ T* CAstraObjectFactory<T, TypeList>::create(const Config& _cfg) */ class _AstraExport CAlgorithmFactory : public CAstraObjectFactory<CAlgorithm, AlgorithmTypeList> {}; +#ifdef ASTRA_PYTHON +template <> +inline CAlgorithm* CAstraObjectFactory<CAlgorithm, AlgorithmTypeList>::findPlugin(std::string _sType) + { + CPluginAlgorithmFactory *fac = CPluginAlgorithmFactory::getFactory(); + if (fac) + return fac->getPlugin(_sType); + else + return 0; + } +#endif + /** * Class used to create 2D projectors from a string or a config object */ |