Public Member Functions | Public Attributes

CIOBuffer Class Reference

Detailed Description

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.

Inheritance diagram for CIOBuffer:
Inheritance graph

List of all members.

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

Constructor & Destructor Documentation

CIOBuffer (  ) 


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


Definition at line 32 of file IOBuffer.cpp.

Member Function Documentation

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
bytes 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.

true on success, false otherwise.

Definition at line 117 of file IOBuffer.cpp.

size_t fill (  ) 

Fill the buffer by reading as many bytes from the file as required.

Number of bytes read.

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'.

name of the SGSerializable

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'
1 on success, 0 on error.

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
Number of bytes read successfully.

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
Number of characters read.

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.
Number of characters 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.
Number of bytes successfully written.

Definition at line 104 of file IOBuffer.cpp.

Member Data Documentation

char* endloaded

end of loaded values

Definition at line 192 of file IOBuffer.h.

v_array<char> space

buffer space

Definition at line 187 of file IOBuffer.h.

file descriptor

Definition at line 195 of file IOBuffer.h.

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation