dodo  0.0.1
A C++ library to create containerized Linux services
dodo::network::FileReadBuffer Class Reference

File-based VirtualReadBuffer, conventient for testing purposes as parsers can be tested against file instead of network sources. More...

#include <socketreadbuffer.hpp>

Inheritance diagram for dodo::network::FileReadBuffer:
Collaboration diagram for dodo::network::FileReadBuffer:

Public Member Functions

 FileReadBuffer (std::string filename, size_t bufsize=8192)
 Construct a FileReadBuffer. More...
 
virtual char get () const
 Get the current char from VirtualReadBuffer. More...
 
virtual common::SystemError next ()
 Move to the next char from the VirtualReadBuffer. More...
 
virtual common::SystemError underflow ()
 If the buffer_ underflows, the buffer_ must be reset refilledwith new data from the source. More...
 
- Public Member Functions inherited from dodo::network::VirtualReadBuffer
size_t getUnderflowCount () const
 Return the number of times underflow() was invoked. More...
 

Protected Attributes

FILE * file_
 The file handle. More...
 
size_t idx_
 The index into the buffer. More...
 
size_t read_
 The number of chars read in buffer_. More...
 
- Protected Attributes inherited from dodo::network::VirtualReadBuffer
char * buffer_
 The buffer. More...
 
ssize_t bufsize_
 The size of buffer_. More...
 
size_t underflows_
 The number underflow() invocations. More...
 

Detailed Description

File-based VirtualReadBuffer, conventient for testing purposes as parsers can be tested against file instead of network sources.

Definition at line 148 of file socketreadbuffer.hpp.

Constructor & Destructor Documentation

◆ FileReadBuffer()

dodo::network::FileReadBuffer::FileReadBuffer ( std::string  filename,
size_t  bufsize = 8192 
)
explicit

Construct a FileReadBuffer.

Parameters
filenameThe file to read.
bufsizeThe buffer size to use

Definition at line 63 of file socketreadbuffer.cpp.

References dodo::network::VirtualReadBuffer::buffer_, dodo::network::VirtualReadBuffer::bufsize_, dodo::common::SystemError::ecOK, file_, idx_, read_, throw_SystemException, and underflow().

Here is the call graph for this function:

Member Function Documentation

◆ get()

char dodo::network::FileReadBuffer::get ( ) const
virtual

Get the current char from VirtualReadBuffer.

Returns
The current character read.
See also
next()

Implements dodo::network::VirtualReadBuffer.

Definition at line 91 of file socketreadbuffer.cpp.

References dodo::network::VirtualReadBuffer::buffer_, and idx_.

◆ next()

common::SystemError dodo::network::FileReadBuffer::next ( )
virtual

Move to the next char from the VirtualReadBuffer.

Note that call will return a SystemError::ecEAGAIN if there is no more data (received within the prevailing timeout).

Returns
SystemError::ecOK and c is valid, or an SystemError.

Implements dodo::network::VirtualReadBuffer.

Definition at line 95 of file socketreadbuffer.cpp.

References idx_, and underflow().

Here is the call graph for this function:

◆ underflow()

common::SystemError dodo::network::FileReadBuffer::underflow ( )
virtual

If the buffer_ underflows, the buffer_ must be reset refilledwith new data from the source.

Returns
Systemerror::ecOK on succes.

Implements dodo::network::VirtualReadBuffer.

Definition at line 79 of file socketreadbuffer.cpp.

References dodo::network::VirtualReadBuffer::buffer_, dodo::network::VirtualReadBuffer::bufsize_, dodo::common::SystemError::ecEAGAIN, dodo::common::SystemError::ecOK, file_, idx_, read_, and dodo::network::VirtualReadBuffer::underflows_.

Referenced by FileReadBuffer(), and next().

Here is the caller graph for this function:

Field Documentation

◆ file_

FILE* dodo::network::FileReadBuffer::file_
protected

The file handle.

Definition at line 169 of file socketreadbuffer.hpp.

Referenced by FileReadBuffer(), and underflow().

◆ idx_

size_t dodo::network::FileReadBuffer::idx_
protected

The index into the buffer.

Definition at line 172 of file socketreadbuffer.hpp.

Referenced by FileReadBuffer(), get(), next(), and underflow().

◆ read_

size_t dodo::network::FileReadBuffer::read_
protected

The number of chars read in buffer_.

Definition at line 177 of file socketreadbuffer.hpp.

Referenced by FileReadBuffer(), and underflow().


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