k1a  1.1
Accelerated functionalities for k1lib
StrIterInter.cpp
Go to the documentation of this file.
1 #define PY_SSIZE_T_CLEAN
2 #include "StrIterInter.h"
3 
4 #include <Python.h>
5 
6 #include <string>
7 
8 #include "utils.h"
9 
10 namespace k1a {
11 
12 StrIterInter::StrIterInter(PyObject *pyObj, StrIter *og, transformF f) : StrIter(pyObj) {
13  this->f = f;
14  this->og = og;
15  Py_XINCREF(og->pyObj);
16 }
17 
19  PyStrIterInter *pyObj = PyObject_New(PyStrIterInter, &PyStrIterInter_Type);
20  char *fileName;
21  if (debug) log_println("PyStrIterInter_new");
22  pyObj->val = new StrIterInter((PyObject *)pyObj, og, f);
23  return (PyObject *)pyObj;
24 }
25 
26 std::string StrIterInter::next() {
27  std::string res = og->next();
28  if (og->done) {
29  done = true;
30  return "";
31  } else
32  return f(res);
33 }
34 
36  Py_XDECREF(og->pyObj);
37 }
38 
39 PyTypeObject PyStrIterInter_Type = {
40  PyVarObject_HEAD_INIT(&PyType_Type, 0) "StrIterInter",
41  sizeof(PyStrIterInter),
42  0,
43  (destructor)StrIter::Py_dealloc<PyStrIterInter>, /* tp_dealloc (destructor)str_iter_dealloc */
44  0, /* tp_vectorcall_offset */
45  0, /* tp_getattr */
46  0, /* tp_setattr */
47  0, /* tp_as_async */
48  (reprfunc)StrIter::Py_repr<PyStrIterInter>, /* tp_repr */
49  0, /* tp_as_number */
50  StrIter::Py_as_sequence<PyStrIterInter>(), /* tp_as_sequence */
51  0, /* tp_as_mapping */
52  0, /* tp_hash */
53  0, /* tp_call */
54  0, /* tp_str */
55  PyObject_GenericGetAttr, /* tp_getattro */
56  0, /* tp_setattro */
57  0, /* tp_as_buffer */
58  Py_TPFLAGS_DEFAULT, /* tp_flags */
59  "StrIterInter, intermediate object", /* tp_doc */
60  0, /* tp_traverse */
61  0, /* tp_clear */
62  0, /* tp_richcompare */
63  0, /* tp_weaklistoffset */
64  PyObject_SelfIter, /* tp_iter */
65  (iternextfunc)StrIter::Py_next<PyStrIterInter>, /* tp_iternext */
66  0, /* tp_methods */
67  0, /* tp_members */
68  0, /* tp_getset */
69  0, /* tp_base */
70  0, /* tp_dict */
71  0, /* tp_descr_get */
72  0, /* tp_descr_set */
73  0, /* tp_dictoffset */
74  0, /* tp_init */
75  PyType_GenericAlloc, /* tp_alloc */
76  0, /* tp_new */
77  PyObject_Del, /* tp_free PyObject_Del */
78 };
79 
80 } // namespace k1a
Intermediate string iterator.
Definition: StrIterInter.h:18
std::string next()
StrIterInter(PyObject *pyObj, StrIter *og, transformF f)
String iterator.
Definition: StrIter.h:79
bool done
Whether the iterator has any elements left.
Definition: StrIter.h:82
virtual std::string next()
Definition: StrIter.cpp:51
PyObject * pyObj
Associated python object.
Definition: StrIter.h:81
Definition: funcs.cpp:15
bool debug
Definition: utils.cpp:14
PyObject * PyStrIterInter_new(StrIter *og, transformF f)
PyTypeObject PyStrIterInter_Type
std::string(* transformF)(std::string)
Definition: StrIter.h:13
void log_println(T s)
Definition: utils.h:21
StrIterInter * val
Definition: StrIterInter.h:32