diff options
-rw-r--r-- | include/gras/CMakeLists.txt | 1 | ||||
-rw-r--r-- | include/gras/element.i | 22 | ||||
-rw-r--r-- | include/gras/tags.i | 44 | ||||
-rw-r--r-- | python/gras/GRAS_Block.i | 58 |
4 files changed, 55 insertions, 70 deletions
diff --git a/include/gras/CMakeLists.txt b/include/gras/CMakeLists.txt index 1e416e1..8a7ad70 100644 --- a/include/gras/CMakeLists.txt +++ b/include/gras/CMakeLists.txt @@ -13,6 +13,7 @@ install(FILES sbuffer.hpp sbuffer.ipp tags.hpp + tags.i thread_pool.hpp top_block.hpp work_buffer.hpp diff --git a/include/gras/element.i b/include/gras/element.i index e2da4ae..72d9f25 100644 --- a/include/gras/element.i +++ b/include/gras/element.i @@ -19,24 +19,20 @@ %include <gras/element.hpp> //////////////////////////////////////////////////////////////////////// -// Create a __str__ for this object +// Operator overloads for Element //////////////////////////////////////////////////////////////////////// - -namespace gras +%extend gras::Element { - %extend Element + std::string __str__(void) const { - std::string __str__(void) - { - return ($self)->to_string(); - } - - bool __eq__(const Element &rhs) - { - return ($self)->get() == rhs.get(); - } + return ($self)->to_string(); + } + bool __eq__(const Element &rhs) const + { + return ($self)->get() == rhs.get(); } + } #endif /*INCLUDED_GRAS_ELEMENT_I*/ diff --git a/include/gras/tags.i b/include/gras/tags.i new file mode 100644 index 0000000..1df9cd2 --- /dev/null +++ b/include/gras/tags.i @@ -0,0 +1,44 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +#ifndef INCLUDED_GRAS_TAGS_I +#define INCLUDED_GRAS_TAGS_I + +%{ +#include <gras/tags.hpp> +%} + +%include <gras/tags.hpp> +%include <PMC/PMC.i> + +//////////////////////////////////////////////////////////////////////// +// Turn TagIter into a python iterable object +//////////////////////////////////////////////////////////////////////// +namespace gras +{ + struct TagIter + { + //declared empty + }; +} + +%extend gras::TagIter +{ + %insert("python") + %{ + def __iter__(self): + for i in range(len(self)): + yield self[i] + %} + + size_t __len__(void) const + { + return ($self)->size(); + } + + const Tag & __getitem__(const size_t i) const + { + return (*($self))[i]; + } +} + +#endif /*INCLUDED_GRAS_TAGS_I*/ diff --git a/python/gras/GRAS_Block.i b/python/gras/GRAS_Block.i index ddb5811..718829f 100644 --- a/python/gras/GRAS_Block.i +++ b/python/gras/GRAS_Block.i @@ -83,58 +83,8 @@ struct PyGILPhondler %include <gras/element.i> %include <gras/io_signature.i> %include <gras/sbuffer.hpp> -%include <gras/tags.hpp> +%include <gras/tags.i> %include <gras/block.hpp> -%include <PMC/PMC.i> - -//////////////////////////////////////////////////////////////////////// -// Create a python iterator class -//////////////////////////////////////////////////////////////////////// -%typemap(throws) Stop_Iteration -%{ - PyErr_SetNone(PyExc_StopIteration); - SWIG_fail; -%} - -%extend gras::TagIterPython -{ -%insert("python") -%{ - def __iter__(self): return self -%} -} - -%inline %{ - -struct Stop_Iteration -{ - Stop_Iteration(void){} -}; - -namespace gras -{ - -struct TagIterPython -{ - TagIterPython(const TagIter &iter): - _iter(iter), _it(iter.begin()) - { - //NOP - } - - const Tag &next(void) throw (Stop_Iteration) - { - if (_it == _iter.end()) throw Stop_Iteration(); - return *(_it++); - } - - TagIter _iter; - TagIter::const_iterator _it; -}; - -} - -%} //////////////////////////////////////////////////////////////////////// // Make a special block with safe overloads @@ -220,12 +170,6 @@ struct BlockPython : Block const std::vector<void *> &, const std::vector<size_t> & ) = 0; - - TagIterPython get_input_tags(const size_t which_input) - { - const TagIter it = Block::get_input_tags(which_input); - return TagIterPython(it); - } }; } |