diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/gras/CMakeLists.txt | 1 | ||||
-rw-r--r-- | include/gras/element.i | 22 | ||||
-rw-r--r-- | include/gras/tags.i | 44 |
3 files changed, 54 insertions, 13 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*/ |