k1a  1.1
Accelerated functionalities for k1lib
StrIter.cpp
Go to the documentation of this file.
1 #define PY_SSIZE_T_CLEAN
2 #include "StrIter.h"
3 
4 #include <Python.h>
5 
6 #include <string>
7 #include <vector>
8 
9 #include "StrIterInter.h"
10 #include "utils.h"
11 
12 namespace k1a {
13 
15  done = false;
16  this->pyObj = NULL;
17 };
18 
19 StrIter::StrIter(PyObject *pyObj) {
20  done = false;
21  this->pyObj = pyObj;
22 };
23 
38 StrIter *StrIter::transform(std::vector<transformF> fs, bool decref) {
39  if (debug) log_println("StrIter::transform");
40  StrIter *answer = this;
41  PyObject *lastPyObj = NULL;
42  for (auto f : fs) {
43  answer = ((PyStrIterInter *)PyStrIterInter_new(answer, f))->val;
44  Py_XDECREF(lastPyObj);
45  lastPyObj = answer->pyObj;
46  }
47  if (decref) Py_XDECREF(pyObj);
48  return answer;
49 }
50 
51 std::string StrIter::next() {
52  if (debug) log_println("StrIter::next");
53  return "";
54 }
55 
57  int count = 0;
58  while (true) {
59  next();
60  if (done) break;
61  count += 1;
62  }
63  return count;
64 }
65 
67 
68 } // namespace k1a
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
StrIter * transform(std::vector< transformF > fs, bool decref=false)
Transforms StrIter into other iterators.
Definition: StrIter.cpp:38
long length()
Definition: StrIter.cpp:56
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)
void log_println(T s)
Definition: utils.h:21