SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
List of all members | 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]

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 Member Functions inherited from CSGObject
 CSGObject ()
 CSGObject (const CSGObject &orig)
virtual ~CSGObject ()
virtual bool is_generic (EPrimitiveType *generic) const
template<class T >
void set_generic ()
void unset_generic ()
virtual void print_serializable (const char *prefix="")
virtual bool save_serializable (CSerializableFile *file, const char *prefix="")
virtual bool load_serializable (CSerializableFile *file, const char *prefix="")
void set_global_io (SGIO *io)
SGIOget_global_io ()
void set_global_parallel (Parallel *parallel)
Parallelget_global_parallel ()
void set_global_version (Version *version)
Versionget_global_version ()
SGVector< char * > get_modelsel_names ()
char * get_modsel_param_descr (const char *param_name)
index_t get_modsel_param_index (const char *param_name)

Public Attributes

v_array< char > space
 buffer space
char * endloaded
 end of loaded values
int working_file
 file descriptor
- Public Attributes inherited from CSGObject
SGIOio
Parallelparallel
Versionversion
Parameterm_parameters
Parameterm_model_selection_parameters

Additional Inherited Members

- Protected Member Functions inherited from CSGObject
virtual void load_serializable_pre () throw (ShogunException)
virtual void load_serializable_post () throw (ShogunException)
virtual void save_serializable_pre () throw (ShogunException)
virtual void save_serializable_post () throw (ShogunException)

Constructor & Destructor Documentation

CIOBuffer ( )

Constructor.

Definition at line 21 of file IOBuffer.cpp.

CIOBuffer ( int  fd)

Constructor taking file descriptor as parameter

Parameters
fdfile 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
pointerreturned pointer
nbytes 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
pointerreturned pointer
nnumber 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
nameFile 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
bufvoid* buffer into which to read.
nbytesnumber 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
pointerStart 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
pointerStart of the string in the buffer, set by reference.
terminalTerminal 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
pCharacter 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
fdfile 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
bufvoid* buffer from which to write.
nbytesNumber 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.

int working_file

file descriptor

Definition at line 195 of file IOBuffer.h.


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

SHOGUN Machine Learning Toolbox - Documentation