memory mapped emulation via binary streams (files)
Implements memory mapped file emulation (
Definition at line 27 of file BinaryStream.h.
Public Member Functions | |
CBinaryStream () | |
CBinaryStream (const char *fname, const char *flag="r") | |
CBinaryStream (const CBinaryStream &bs) | |
virtual | ~CBinaryStream () |
void | open_stream (const char *fname, const char *flag="r") |
void | close_stream () |
uint64_t | get_length () |
uint64_t | get_size () |
char * | get_line (uint64_t &len, uint64_t &offs) |
int32_t | get_num_lines () |
void | pre_buffer (T *buffer, long index, long num) const |
T | read_next () const |
T | operator[] (int32_t index) const |
virtual const char * | get_name () const |
Protected Attributes | |
FILE * | fd |
uint64_t | length |
char * | rw |
char * | m_fname |
CBinaryStream | ( | ) |
default constructor
Definition at line 32 of file BinaryStream.h.
CBinaryStream | ( | const char * | fname, | |
const char * | flag = "r" | |||
) |
constructor
open a file for read mode
fname | name of file, zero terminated string | |
flag | determines read or read write mode (currently only 'r' is supported) |
Definition at line 47 of file BinaryStream.h.
CBinaryStream | ( | const CBinaryStream< T > & | bs | ) |
copy constructor
bs | binary stream to copy from |
Definition at line 59 of file BinaryStream.h.
virtual ~CBinaryStream | ( | ) | [virtual] |
destructor
Definition at line 67 of file BinaryStream.h.
void close_stream | ( | ) |
close a file stream
Definition at line 95 of file BinaryStream.h.
uint64_t get_length | ( | ) |
get the number of objects of type T cointained in the file
Definition at line 112 of file BinaryStream.h.
char* get_line | ( | uint64_t & | len, | |
uint64_t & | offs | |||
) |
get next line from file
The returned line may be modfied in case the file was opened read/write. It is otherwise read-only.
len | length of line (returned via reference) | |
offs | offset to be passed for reading next line, should be 0 initially (returned via reference) |
Definition at line 137 of file BinaryStream.h.
virtual const char* get_name | ( | void | ) | const [virtual] |
int32_t get_num_lines | ( | ) |
count the number of lines in a file
Definition at line 146 of file BinaryStream.h.
uint64_t get_size | ( | ) |
get the size of the file in bytes
Definition at line 121 of file BinaryStream.h.
void open_stream | ( | const char * | fname, | |
const char * | flag = "r" | |||
) |
open file stream
fname | file name | |
flag | flags "r" for reading etc |
Definition at line 77 of file BinaryStream.h.
T operator[] | ( | int32_t | index | ) | const |
operator overload for file read only access
index | index |
Definition at line 192 of file BinaryStream.h.
void pre_buffer | ( | T * | buffer, | |
long | index, | |||
long | num | |||
) | const |
read num elements starting from index into buffer
buffer | buffer that has to be at least num elements long | |
index | index into file starting from which elements are read | |
num | number of elements to be read |
Definition at line 157 of file BinaryStream.h.
T read_next | ( | ) | const |
FILE* fd [protected] |
file descriptor
Definition at line 211 of file BinaryStream.h.
uint64_t length [protected] |
size of file
Definition at line 213 of file BinaryStream.h.
char* m_fname [protected] |
fname
Definition at line 217 of file BinaryStream.h.
char* rw [protected] |
mode
Definition at line 215 of file BinaryStream.h.