diff options
-rw-r--r-- | include/gras/detail/factory.hpp | 8 | ||||
-rw-r--r-- | include/gras/factory.hpp | 10 | ||||
-rw-r--r-- | lib/factory.cpp | 2 | ||||
-rw-r--r-- | python/gras/CMakeLists.txt | 2 | ||||
-rw-r--r-- | python/gras/GRAS_Factory.i | 41 | ||||
-rw-r--r-- | python/gras/__init__.py | 1 |
6 files changed, 54 insertions, 10 deletions
diff --git a/include/gras/detail/factory.hpp b/include/gras/detail/factory.hpp index 0487e76..632e09d 100644 --- a/include/gras/detail/factory.hpp +++ b/include/gras/detail/factory.hpp @@ -116,7 +116,7 @@ inline Element *Factory::make(const std::string &name) { PMCList args(0); - return Factory::_make(name, PMC_M(args)); + return Factory::_handle_make(name, PMC_M(args)); } template <typename Arg0> @@ -124,7 +124,7 @@ Element *Factory::make(const std::string &name, const Arg0 &a0) { PMCList args(1); args[0] = PMC_M(a0); - return Factory::_make(name, PMC_M(args)); + return Factory::_handle_make(name, PMC_M(args)); } template <typename Arg0, typename Arg1> @@ -133,7 +133,7 @@ Element *Factory::make(const std::string &name, const Arg0 &a0, const Arg1 &a1) PMCList args(2); args[0] = PMC_M(a0); args[1] = PMC_M(a1); - return Factory::_make(name, PMC_M(args)); + return Factory::_handle_make(name, PMC_M(args)); } template <typename Arg0, typename Arg1, typename Arg2> @@ -143,7 +143,7 @@ Element *Factory::make(const std::string &name, const Arg0 &a0, const Arg1 &a1, args[0] = PMC_M(a0); args[1] = PMC_M(a1); args[2] = PMC_M(a2); - return Factory::_make(name, PMC_M(args)); + return Factory::_handle_make(name, PMC_M(args)); } } diff --git a/include/gras/factory.hpp b/include/gras/factory.hpp index 926025e..13d1c2b 100644 --- a/include/gras/factory.hpp +++ b/include/gras/factory.hpp @@ -39,10 +39,8 @@ namespace gras * Example call into the factory: * gras::Element *my_block = gras::Factory::make("make_my_block", arg0, arg1); */ -class GRAS_API Factory : Callable +struct GRAS_API Factory { -public: - /******************************************************************* * Register API - don't look here, template magic, not helpful ******************************************************************/ @@ -73,9 +71,11 @@ public: template <typename Arg0, typename Arg1, typename Arg2> static Element *make(const std::string &name, const Arg0 &a0, const Arg1 &a1, const Arg2 &a2); -private: + /******************************************************************* + * Private registration hooks + ******************************************************************/ static void _register_make(const std::string &, void *); - static Element *_make(const std::string &, const PMCC &); + static Element *_handle_make(const std::string &, const PMCC &); }; } diff --git a/lib/factory.cpp b/lib/factory.cpp index 1c634fd..5c405f3 100644 --- a/lib/factory.cpp +++ b/lib/factory.cpp @@ -38,7 +38,7 @@ void Factory::_register_make(const std::string &name, void *entry) get_factory_registry()[name].reset(reinterpret_cast<FactoryRegistryEntry *>(entry)); } -Element *Factory::_make(const std::string &name, const PMCC &args) +Element *Factory::_handle_make(const std::string &name, const PMCC &args) { boost::mutex::scoped_lock l(mutex); if (get_factory_registry().count(name) == 0) diff --git a/python/gras/CMakeLists.txt b/python/gras/CMakeLists.txt index 8a301d0..273e06d 100644 --- a/python/gras/CMakeLists.txt +++ b/python/gras/CMakeLists.txt @@ -20,6 +20,7 @@ file(GLOB GR_SWIG_SOURCE_DEPS "${GRAS_SOURCE_DIR}/include/gras/*.i") GR_SWIG_MAKE(GRAS_Tags GRAS_Tags.i) GR_SWIG_MAKE(GRAS_TimeTag GRAS_TimeTag.i) +GR_SWIG_MAKE(GRAS_Factory GRAS_Factory.i) GR_SWIG_MAKE(GRAS_Element GRAS_Element.i) GR_SWIG_MAKE(GRAS_Block GRAS_Block.i) GR_SWIG_MAKE(GRAS_HierBlock GRAS_HierBlock.i) @@ -33,6 +34,7 @@ GR_SWIG_INSTALL( GRAS_Tags GRAS_TimeTag GRAS_Element + GRAS_Factory GRAS_Block GRAS_HierBlock GRAS_PyBlock diff --git a/python/gras/GRAS_Factory.i b/python/gras/GRAS_Factory.i new file mode 100644 index 0000000..e324d27 --- /dev/null +++ b/python/gras/GRAS_Factory.i @@ -0,0 +1,41 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +%include <gras/exception.i> +%module (package="gras") GRAS_Factory + +%{ +#include <gras/factory.hpp> +%} + +namespace gras +{ + %ignore Factory::register_make; + %ignore Factory::make; +} + +//////////////////////////////////////////////////////////////////////// +// Export swig element comprehension +//////////////////////////////////////////////////////////////////////// +%include <std_string.i> +%import <PMC/PMC.i> +%import <gras/element.i> +%include <gras/gras.hpp> +%include <gras/factory.hpp> + +//////////////////////////////////////////////////////////////////////// +// Create python methods for factories +//////////////////////////////////////////////////////////////////////// +%pythoncode%{ + +class StaticPyFactory(object): + + def __getattr__(self, name): + def make(name, *args): + from PMC import PMC_M + pmcargs = PMC_M(list(args)) + return Factory._handle_make(name, pmcargs) + return lambda *args: make(name, *args) + +PyFactory = StaticPyFactory() + +%} diff --git a/python/gras/__init__.py b/python/gras/__init__.py index 1871a27..4add913 100644 --- a/python/gras/__init__.py +++ b/python/gras/__init__.py @@ -10,6 +10,7 @@ from GRAS_SBuffer import SBufferConfig, SBuffer from GRAS_Tags import Tag, StreamTag, PacketMsg from GRAS_TimeTag import TimeTag from GRAS_Element import Element +from GRAS_Factory import PyFactory as Factory import GRAS_Block import GRAS_HierBlock import GRAS_TopBlock |