1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus
3
* MAUS is free software: you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation, either version 3 of the License, or
6
* (at your option) any later version.
8
* MAUS is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with MAUS. If not, see <http://www.gnu.org/licenses/>.
17
#ifndef _SRC_COMMON_CPP_API_PYWRAPINPUTBASEEMITTER_
18
#define _SRC_COMMON_CPP_API_PYWRAPINPUTBASEEMITTER_
22
// These ifdefs are required to avoid cpp compiler warning
23
#ifdef _POSIX_C_SOURCE
24
#undef _POSIX_C_SOURCE
32
#include "structmember.h"
37
template <class INPUTCLASS>
38
class PyWrapInputBaseEmitter {
43
} PyWrappedInputEmitter;
46
static PyObject* Iter(PyObject *self);
47
static PyObject* Next(PyObject *self);
48
static PyTypeObject _class_type;
50
static std::string _class_name; // Class
51
static std::string _path_name; // module.Class
53
// only PyWrapInputBase can initialise/destruct PyWrapInputBaseEmitter
54
friend class PyWrapInputBase<INPUTCLASS>;
58
template <class INPUTCLASS>
59
PyObject* PyWrapInputBaseEmitter<INPUTCLASS>::Iter(PyObject *self) {
64
template <class INPUTCLASS>
65
PyObject* PyWrapInputBaseEmitter<INPUTCLASS>::Next(PyObject *self) {
66
PyWrappedInputEmitter *py_wrap_emitter =
67
reinterpret_cast<PyWrappedInputEmitter*>(self);
68
if (py_wrap_emitter) {
69
PyObject* out = py_wrap_emitter->input->emit_pyobj();
73
/* Raising of standard StopIteration exception with empty value. */
74
PyErr_SetNone(PyExc_StopIteration);
78
PyErr_SetString(PyExc_RuntimeError, "Failed to get the emitter");
83
template <class INPUTCLASS>
84
PyTypeObject PyWrapInputBaseEmitter<INPUTCLASS>::_class_type = {
85
PyObject_HEAD_INIT(NULL)
87
"PyWrapInputBaseIterator", /*tp_name*/
88
sizeof(PyWrappedInputEmitter), /*tp_basicsize*/
105
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
106
/* tp_flags: Py_TPFLAGS_HAVE_ITER tells python to
107
use tp_iter and tp_iternext fields. */
108
"PyWrapInputBase iterator object.", /* tp_doc */
111
0, /* tp_richcompare */
112
0, /* tp_weaklistoffset */
113
PyWrapInputBaseEmitter<INPUTCLASS>::Iter, /* tp_iter: __iter__() method */
114
PyWrapInputBaseEmitter<INPUTCLASS>::Next /* tp_iternext: next() method */
117
template <class INPUTCLASS>
118
std::string PyWrapInputBaseEmitter<INPUTCLASS>::_class_name = ""; // Class
119
template <class INPUTCLASS>
120
std::string PyWrapInputBaseEmitter<INPUTCLASS>::_path_name = ""; // module.Class