ecto
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
ecto::py::streambuf Class Reference

#include <streambuf.hpp>

Inheritance diagram for ecto::py::streambuf:
Inheritance graph
[legend]
Collaboration diagram for ecto::py::streambuf:
Collaboration graph
[legend]

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 ()
 

Public Attributes

bp::object file_obj
 

Static Public Attributes

static std::size_t default_buffer_size = 1024
 The default size of the read and write buffer. More...
 

Private Types

typedef std::basic_streambuf< char > base_t
 

Private Member Functions

boost::optional< off_typeseekoff_without_calling_python (off_type off, std::ios_base::seekdir way, std::ios_base::openmode which)
 

Private Attributes

bp::object py_read
 
bp::object py_write
 
bp::object py_seek
 
bp::object py_tell
 
std::size_t buffer_size
 
bp::object read_buffer
 
char * write_buffer
 
off_type pos_of_read_buffer_end_in_py_file
 
off_type pos_of_write_buffer_end_in_py_file
 
char * farthest_pptr
 

Member Typedef Documentation

typedef std::basic_streambuf<char> ecto::py::streambuf::base_t
private
typedef base_t::char_type ecto::py::streambuf::char_type
typedef base_t::int_type ecto::py::streambuf::int_type
typedef base_t::off_type ecto::py::streambuf::off_type
typedef base_t::pos_type ecto::py::streambuf::pos_type
typedef base_t::traits_type ecto::py::streambuf::traits_type

Constructor & Destructor Documentation

ecto::py::streambuf::streambuf ( bp::object &  python_file_obj,
std::size_t  buffer_size_ = 0 
)
inline

Construct from a Python file object.

if buffer_size is 0 the current default_buffer_size is used.

virtual ecto::py::streambuf::~streambuf ( )
inlinevirtual

Mundane destructor freeing the allocated resources.

Member Function Documentation

virtual int_type ecto::py::streambuf::overflow ( int_type  c = traits_type_eof())
inlinevirtual

C.f. C++ standard section 27.5.2.4.5.

virtual pos_type ecto::py::streambuf::seekoff ( off_type  off,
std::ios_base::seekdir  way,
std::ios_base::openmode  which = std::ios_base::in | std::ios_base::out 
)
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)

boost::optional<off_type> ecto::py::streambuf::seekoff_without_calling_python ( off_type  off,
std::ios_base::seekdir  way,
std::ios_base::openmode  which 
)
inlineprivate
virtual pos_type ecto::py::streambuf::seekpos ( pos_type  sp,
std::ios_base::openmode  which = std::ios_base::in | std::ios_base::out 
)
inlinevirtual

C.f. C++ standard section 27.5.2.4.2.

virtual std::streamsize ecto::py::streambuf::showmanyc ( )
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)

virtual int ecto::py::streambuf::sync ( )
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.

static int ecto::py::streambuf::traits_type_eof ( )
inlinestatic
virtual int_type ecto::py::streambuf::underflow ( )
inlinevirtual

C.f. C++ standard section 27.5.2.4.3.

Member Data Documentation

std::size_t ecto::py::streambuf::buffer_size
private
std::size_t ecto::py::streambuf::default_buffer_size = 1024
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.

char* ecto::py::streambuf::farthest_pptr
private
bp::object ecto::py::streambuf::file_obj
off_type ecto::py::streambuf::pos_of_read_buffer_end_in_py_file
private
off_type ecto::py::streambuf::pos_of_write_buffer_end_in_py_file
private
bp::object ecto::py::streambuf::py_read
private
bp::object ecto::py::streambuf::py_seek
private
bp::object ecto::py::streambuf::py_tell
private
bp::object ecto::py::streambuf::py_write
private
bp::object ecto::py::streambuf::read_buffer
private
char* ecto::py::streambuf::write_buffer
private

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