An I/O buffer class.
A file is read into buffer space, which is accessed through extents; 'space.begin' is the start of the buffer, 'space.end' is the address of the last read character.
The buffer grows in size if required, the default size being 64KB.
Definition at line 44 of file IOBuffer.h.
Public Member Functions | |
CIOBuffer () | |
CIOBuffer (int fd) | |
~CIOBuffer () | |
void | init () |
virtual void | use_file (int fd) |
virtual int | open_file (const char *name, char flag='r') |
virtual void | reset_file () |
void | set (char *p) |
virtual ssize_t | read_file (void *buf, size_t nbytes) |
size_t | fill () |
virtual ssize_t | write_file (const void *buf, size_t nbytes) |
virtual void | flush () |
virtual bool | close_file () |
ssize_t | readto (char *&pointer, char terminal) |
ssize_t | read_line (char *&pointer) |
void | buf_write (char *&pointer, int n) |
unsigned int | buf_read (char *&pointer, int n) |
virtual const char * | get_name () const |
Public Attributes | |
v_array< char > | space |
buffer space | |
char * | endloaded |
end of loaded values | |
int | working_file |
file descriptor |
CIOBuffer | ( | ) |
Constructor.
Definition at line 21 of file IOBuffer.cpp.
CIOBuffer | ( | int | fd | ) |
Constructor taking file descriptor as parameter
fd | file descriptor to use |
Definition at line 26 of file IOBuffer.cpp.
~CIOBuffer | ( | ) |
Destructor.
Definition at line 32 of file IOBuffer.cpp.
unsigned int buf_read | ( | char *& | pointer, | |
int | n | |||
) |
Return a pointer to position in buffer after reading n bytes
pointer | returned pointer | |
n | bytes to read |
Definition at line 181 of file IOBuffer.cpp.
void buf_write | ( | char *& | pointer, | |
int | n | |||
) |
Return a pointer to the next n bytes to write into
pointer | returned pointer | |
n | number of bytes to write |
Definition at line 161 of file IOBuffer.cpp.
bool close_file | ( | ) | [virtual] |
Close the file.
Definition at line 117 of file IOBuffer.cpp.
size_t fill | ( | ) |
Fill the buffer by reading as many bytes from the file as required.
Definition at line 86 of file IOBuffer.cpp.
void flush | ( | ) | [virtual] |
Flush the stream; commit all operations to file.
Definition at line 109 of file IOBuffer.cpp.
virtual const char* get_name | ( | ) | const [virtual] |
Returns the name of the SGSerializable instance. It MUST BE the CLASS NAME without the prefixed `C'.
Implements CSGObject.
Definition at line 179 of file IOBuffer.h.
void init | ( | void | ) |
Initialize the buffer, reserve 64K memory by default.
Reimplemented from CSGObject.
Definition at line 37 of file IOBuffer.cpp.
int open_file | ( | const char * | name, | |
char | flag = 'r' | |||
) | [virtual] |
Open a file, in read or write mode.
name | File name. | |
flag | 'r' or 'w' |
Definition at line 49 of file IOBuffer.cpp.
ssize_t read_file | ( | void * | buf, | |
size_t | nbytes | |||
) | [virtual] |
Read some bytes from the file into memory.
buf | void* buffer into which to read. | |
nbytes | number of bytes to read |
Definition at line 81 of file IOBuffer.cpp.
ssize_t read_line | ( | char *& | pointer | ) |
Reads upto a newline character from the buffer.
pointer | Start of the string, set by reference |
Definition at line 156 of file IOBuffer.h.
ssize_t readto | ( | char *& | pointer, | |
char | terminal | |||
) |
Reads upto a terminal character from the buffer.
pointer | Start of the string in the buffer, set by reference. | |
terminal | Terminal character upto which to read. |
Definition at line 130 of file IOBuffer.cpp.
void reset_file | ( | ) | [virtual] |
Seek back to zero, reset the buffer markers.
Definition at line 69 of file IOBuffer.cpp.
void set | ( | char * | p | ) |
Set the buffer marker to a position.
p | Character pointer to which the end of buffer space is assigned. |
Definition at line 76 of file IOBuffer.cpp.
void use_file | ( | int | fd | ) | [virtual] |
Uses the passed file descriptor
fd | file descriptor to use |
Definition at line 44 of file IOBuffer.cpp.
ssize_t write_file | ( | const void * | buf, | |
size_t | nbytes | |||
) | [virtual] |
Write to the file from memory.
buf | void* buffer from which to write. | |
nbytes | Number of bytes to write. |
Definition at line 104 of file IOBuffer.cpp.
char* endloaded |
end of loaded values
Definition at line 192 of file IOBuffer.h.
buffer space
Definition at line 187 of file IOBuffer.h.
int working_file |
file descriptor
Definition at line 195 of file IOBuffer.h.