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. | |
streambuf (bp::object &python_file_obj, char mode, std::size_t buffer_size_=0) | |
constructor to enforce a mode (binary or text) | |
~streambuf () override | |
Mundane destructor freeing the allocated resources. | |
std::streamsize | showmanyc () override |
C.f. C++ standard section 27.5.2.4.3. | |
int_type | underflow () override |
C.f. C++ standard section 27.5.2.4.3. | |
int_type | overflow (int_type c=traits_type_eof()) override |
C.f. C++ standard section 27.5.2.4.5. | |
int | sync () override |
Update the python file to reflect the state of this stream buffer. | |
pos_type | seekoff (off_type off, std::ios_base::seekdir way, std::ios_base::openmode which=std::ios_base::in|std::ios_base::out) override |
C.f. C++ standard section 27.5.2.4.2. | |
pos_type | seekpos (pos_type sp, std::ios_base::openmode which=std::ios_base::in|std::ios_base::out) override |
C.f. C++ standard section 27.5.2.4.2. | |
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. | |
A stream buffer getting data from and putting data into a Python file object.
The aims are as follow:
Given a C++ function acting on a standard stream, e.g.
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:
a trivial wrapper function
which has to be written every time one wants a Python binding for such a C++ function.
the Python side
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 111 of file python_streambuf.h.
typedef base_t::char_type boost_adaptbx::python::streambuf::char_type |
Definition at line 120 of file python_streambuf.h.
typedef base_t::int_type boost_adaptbx::python::streambuf::int_type |
Definition at line 121 of file python_streambuf.h.
typedef base_t::off_type boost_adaptbx::python::streambuf::off_type |
Definition at line 123 of file python_streambuf.h.
typedef base_t::pos_type boost_adaptbx::python::streambuf::pos_type |
Definition at line 122 of file python_streambuf.h.
typedef base_t::traits_type boost_adaptbx::python::streambuf::traits_type |
Definition at line 124 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 138 of file python_streambuf.h.
References TEST_ASSERT.
|
inline |
constructor to enforce a mode (binary or text)
yeah, is redundant, but it is somehow natural to do "s"
Definition at line 192 of file python_streambuf.h.
References CHECK_INVARIANT.
|
inlineoverride |
Mundane destructor freeing the allocated resources.
Definition at line 236 of file python_streambuf.h.
|
inlineoverride |
C.f. C++ standard section 27.5.2.4.5.
Definition at line 283 of file python_streambuf.h.
|
inlineoverride |
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 366 of file python_streambuf.h.
References overflow(), and underflow().
Referenced by seekpos().
|
inlineoverride |
C.f. C++ standard section 27.5.2.4.2.
Definition at line 429 of file python_streambuf.h.
References seekoff().
|
inlineoverride |
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 246 of file python_streambuf.h.
References underflow().
|
inlineoverride |
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 339 of file python_streambuf.h.
References overflow().
|
inlinestatic |
Definition at line 127 of file python_streambuf.h.
|
inlineoverride |
C.f. C++ standard section 27.5.2.4.3.
Definition at line 256 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 133 of file python_streambuf.h.