summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/gras/CMakeLists.txt2
-rw-r--r--python/gras/GRAS_Factory.i41
-rw-r--r--python/gras/__init__.py1
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