![]() |
RDKit
Open-source cheminformatics and machine learning.
|
A stream buffer getting data from and putting data into a Python file object. More...
#include <python_streambuf.h>
Classes | |
class | istream |
class | ostream |
Public Types | |
typedef base_t::char_type | char_type |
typedef base_t::int_type | int_type |
typedef base_t::pos_type | pos_type |
typedef base_t::off_type | off_type |
typedef base_t::traits_type | traits_type |
Public Member Functions | |
streambuf (bp::object &python_file_obj, std::size_t buffer_size_=0) | |
Construct from a Python file object. More... | |
virtual | ~streambuf () |
Mundane destructor freeing the allocated resources. More... | |
virtual std::streamsize | showmanyc () |
C.f. C++ standard section 27.5.2.4.3. More... | |
virtual int_type | underflow () |
C.f. C++ standard section 27.5.2.4.3. More... | |
virtual int_type | overflow (int_type c=traits_type_eof()) |
C.f. C++ standard section 27.5.2.4.5. More... | |
virtual int | sync () |
Update the python file to reflect the state of this stream buffer. More... | |
virtual pos_type | seekoff (off_type off, std::ios_base::seekdir way, std::ios_base::openmode which=std::ios_base::in|std::ios_base::out) |
C.f. C++ standard section 27.5.2.4.2. More... | |
virtual pos_type | seekpos (pos_type sp, std::ios_base::openmode which=std::ios_base::in|std::ios_base::out) |
C.f. C++ standard section 27.5.2.4.2. More... | |
Static Public Member Functions | |
static int | traits_type_eof () |
Static Public Attributes | |
static const std::size_t | default_buffer_size =1024 |
The default size of the read and write buffer. More... | |
A stream buffer getting data from and putting data into a Python file object.
The aims are as follow:
and given a piece of Python code which creates a file-like object, to be able to pass this file object to that C++ function, e.g.
and have the standard stream pull data from and put data into the Python file object.
read_inputs()
returns, the Python object is able to continue reading or writing where the C++ code left off.std::fstream
.Motivation
Usage
This is 2-step:
which has to be written every time one wants a Python binding for such a C++ function.
buffer_size
is optional. See also: default_buffer_size
Note: references are to the C++ standard (the numbers between parentheses at the end of references are margin markers).
Definition at line 108 of file python_streambuf.h.
typedef base_t::char_type boost_adaptbx::python::streambuf::char_type |
Definition at line 118 of file python_streambuf.h.
typedef base_t::int_type boost_adaptbx::python::streambuf::int_type |
Definition at line 119 of file python_streambuf.h.
typedef base_t::off_type boost_adaptbx::python::streambuf::off_type |
Definition at line 121 of file python_streambuf.h.
typedef base_t::pos_type boost_adaptbx::python::streambuf::pos_type |
Definition at line 120 of file python_streambuf.h.
typedef base_t::traits_type boost_adaptbx::python::streambuf::traits_type |
Definition at line 122 of file python_streambuf.h.
|
inline |
Construct from a Python file object.
if buffer_size is 0 the current default_buffer_size is used.
Definition at line 137 of file python_streambuf.h.
References TEST_ASSERT.
|
inlinevirtual |
Mundane destructor freeing the allocated resources.
Definition at line 197 of file python_streambuf.h.
|
inlinevirtual |
C.f. C++ standard section 27.5.2.4.5.
Definition at line 238 of file python_streambuf.h.
|
inlinevirtual |
C.f. C++ standard section 27.5.2.4.2.
This implementation is optimised to look whether the position is within the buffers, so as to avoid calling Python seek or tell. It is important for many applications that the overhead of calling into Python is avoided as much as possible (e.g. parsers which may do a lot of backtracking)
Definition at line 291 of file python_streambuf.h.
References overflow(), and underflow().
Referenced by seekpos().
|
inlinevirtual |
C.f. C++ standard section 27.5.2.4.2.
Definition at line 349 of file python_streambuf.h.
References CHECK_INVARIANT, and seekoff().
|
inlinevirtual |
C.f. C++ standard section 27.5.2.4.3.
It is essential to override this virtual function for the stream member function readsome to work correctly (c.f. 27.6.1.3, alinea 30)
Definition at line 205 of file python_streambuf.h.
References underflow().
|
inlinevirtual |
Update the python file to reflect the state of this stream buffer.
Empty the write buffer into the Python file object and set the seek position of the latter accordingly (C++ standard section 27.5.2.4.2). If there is no write buffer or it is empty, but there is a non-empty read buffer, set the Python file object seek position to the seek position in that read buffer.
Definition at line 268 of file python_streambuf.h.
References overflow().
Referenced by boost_adaptbx::python::streambuf::istream::~istream().
|
inlinestatic |
Definition at line 126 of file python_streambuf.h.
|
inlinevirtual |
C.f. C++ standard section 27.5.2.4.3.
Definition at line 213 of file python_streambuf.h.
Referenced by seekoff(), and showmanyc().
|
static |
The default size of the read and write buffer.
They are respectively used to buffer data read from and data written to the Python file object. It can be modified from Python.
Definition at line 132 of file python_streambuf.h.