diff options
author | Josh Blum | 2013-07-07 12:21:36 -0700 |
---|---|---|
committer | Josh Blum | 2013-07-07 12:21:36 -0700 |
commit | cfd9e8146f7589f3f04fea979c741267b0454546 (patch) | |
tree | db46f578e2ff93b104ed9270623926732ee5eb83 /python/gras | |
parent | c6373f53f4690d667e553ed7258e13c3b45aa323 (diff) | |
download | sandhi-cfd9e8146f7589f3f04fea979c741267b0454546.tar.gz sandhi-cfd9e8146f7589f3f04fea979c741267b0454546.tar.bz2 sandhi-cfd9e8146f7589f3f04fea979c741267b0454546.zip |
gras: python hooks for factory
Diffstat (limited to 'python/gras')
-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 |
3 files changed, 44 insertions, 0 deletions
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 |