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
[legend]

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

Constructor.

Definition at line 21 of file IOBuffer.cpp.

CIOBuffer ( int  fd  ) 

Constructor taking file descriptor as parameter

Parameters:
fd file descriptor to use

Definition at line 26 of file IOBuffer.cpp.

~CIOBuffer (  ) 

Destructor.

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

Parameters:
pointer returned pointer
n bytes to read
Returns:
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

Parameters:
pointer returned pointer
n number of bytes to write

Definition at line 161 of file IOBuffer.cpp.

bool close_file (  )  [virtual]

Close the file.

Returns:
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.

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

Returns:
name of the SGSerializable

Implements CSGObject.

Definition at line 179 of file IOBuffer.h.

void init (  ) 

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.

Parameters:
name File name.
flag 'r' or 'w'
Returns:
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.

Parameters:
buf void* buffer into which to read.
nbytes number of bytes to read
Returns:
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.

Parameters:
pointer Start of the string, set by reference
Returns:
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.

Parameters:
pointer Start of the string in the buffer, set by reference.
terminal Terminal character upto which to read.
Returns:
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.

Parameters:
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

Parameters:
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.

Parameters:
buf void* buffer from which to write.
nbytes Number of bytes to write.
Returns:
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