k1a  1.1
Accelerated functionalities for k1lib
k1a::StrIterCat Class Reference

Line iterator from file. More...

#include <StrIterCat.h>

Inheritance diagram for k1a::StrIterCat:
[legend]
Collaboration diagram for k1a::StrIterCat:
[legend]

Public Member Functions

 StrIterCat (PyObject *pyObj, std::string fileName)
 
std::string next ()
 
 ~StrIterCat ()
 
- Public Member Functions inherited from k1a::StrIter
 StrIter ()
 
 StrIter (PyObject *pyObj)
 
StrItertransform (std::vector< transformF > fs, bool decref=false)
 Transforms StrIter into other iterators. More...
 
long length ()
 
 ~StrIter ()
 

Public Attributes

std::string * fileName
 
- Public Attributes inherited from k1a::StrIter
PyObject * pyObj
 Associated python object. More...
 
bool done
 Whether the iterator has any elements left. More...
 

Private Attributes

std::ifstream * fp
 

Additional Inherited Members

- Static Public Member Functions inherited from k1a::StrIter
template<class T >
static PyObject * Py_next (PyObject *self)
 Default __next__ function. More...
 
template<class T >
static PyObject * Py_repr (PyObject *self)
 Default __repr__ function. More...
 
template<class T >
static Py_ssize_t Py_length (PyObject *self)
 
template<class T >
static void Py_dealloc (PyObject *self)
 Default dealloc function. More...
 
template<class T >
static PySequenceMethods * Py_as_sequence ()
 Default tp_as_sequence method generator. More...
 

Detailed Description

Line iterator from file.

Basically a k1a.StrIter, but iterates through lines in a specific file. Constructor: k1a::PyStrIterCat_new. Example:

PyObject *a = PyStrIterCat_new("file.txt");
PyObject * PyStrIterCat_new(std::string fileName)
Creates a new PyStrIterCat object.
Definition: StrIterCat.cpp:37

Definition at line 25 of file StrIterCat.h.

Constructor & Destructor Documentation

◆ StrIterCat()

k1a::StrIterCat::StrIterCat ( PyObject *  pyObj,
std::string  fileName 
)

Definition at line 16 of file StrIterCat.cpp.

16  : StrIter(pyObj) {
17  this->fileName = new std::string(fileName);
18  this->fp = new std::ifstream(fileName);
19 };
std::string * fileName
Definition: StrIterCat.h:27
std::ifstream * fp
Definition: StrIterCat.h:33
PyObject * pyObj
Associated python object.
Definition: StrIter.h:81

◆ ~StrIterCat()

k1a::StrIterCat::~StrIterCat ( )

Definition at line 51 of file StrIterCat.cpp.

51  {
52  fp->close();
53  delete fileName;
54 }

Member Function Documentation

◆ next()

std::string k1a::StrIterCat::next ( )
virtual

Reimplemented from k1a::StrIter.

Definition at line 21 of file StrIterCat.cpp.

21  {
22  std::string line;
23  if (std::getline(*fp, line))
24  return line;
25  else {
26  done = true;
27  return "";
28  }
29 };
bool done
Whether the iterator has any elements left.
Definition: StrIter.h:82

Member Data Documentation

◆ fileName

std::string* k1a::StrIterCat::fileName

Definition at line 27 of file StrIterCat.h.

◆ fp

std::ifstream* k1a::StrIterCat::fp
private

Definition at line 33 of file StrIterCat.h.


The documentation for this class was generated from the following files: