cgul_block_reader_file.h File Reference

file block reader More...

#include "cgul_common.h"
#include "cgul_exception.h"
#include "cgul_block_reader.h"
Include dependency graph for cgul_block_reader_file.h:
This graph shows which files directly or indirectly include this file:

Typedefs

typedef typedefCGUL_BEGIN_C struct cgul_block_reader_file * cgul_block_reader_file_t
 

Functions

CGUL_EXPORT cgul_block_reader_t cgul_block_reader_file__as_block_reader (cgul_exception_t *cex, cgul_block_reader_file_t brfile)
 
CGUL_EXPORT cgul_block_reader_file_t cgul_block_reader_file__new (cgul_exception_t *cex)
 
CGUL_EXPORT cgul_block_reader_file_t cgul_block_reader_file__new_from_fname (cgul_exception_t *cex, const char *fname)
 
CGUL_EXPORT cgul_block_reader_file_t cgul_block_reader_file__new_from_file (cgul_exception_t *cex, FILE *f)
 
CGUL_EXPORT void cgul_block_reader_file__delete (cgul_block_reader_file_t brfile)
 
CGUL_EXPORT void cgul_block_reader_file__open_fname (cgul_exception_t *cex, cgul_block_reader_file_t brfile, const char *fname)
 
CGUL_EXPORT void cgul_block_reader_file__open_file (cgul_exception_t *cex, cgul_block_reader_file_t brfile, FILE *f)
 
CGUL_EXPORT void cgul_block_reader_file__close (cgul_exception_t *cex, cgul_block_reader_file_t brfile)
 
CGUL_EXPORT size_t cgul_block_reader_file__read_next_block (cgul_exception_t *cex, cgul_block_reader_file_t brfile, void *block, size_t block_size)
 
CGUL_EXPORT const char * cgul_block_reader_file__get_fname (cgul_exception_t *cex, cgul_block_reader_file_t brfile)
 
CGUL_EXPORT const char * cgul_block_reader_file__get_presentation_name (cgul_exception_t *cex, cgul_block_reader_file_t brfile)
 
CGUL_EXPORT void cgul_block_reader_file__set_presentation_name (cgul_exception_t *cex, cgul_block_reader_file_t brfile, const char *presentation_name)
 
CGUL_EXPORT FILE * cgul_block_reader_file__get_file (cgul_exception_t *cex, cgul_block_reader_file_t brfile)
 

Detailed Description

Implementation of the cgul_block_reader interface for standard C FILE objects.

Author
Paul Serice

Typedef Documentation

§ cgul_block_reader_file_t

typedef typedefCGUL_BEGIN_C struct cgul_block_reader_file* cgul_block_reader_file_t

Opaque pointer to a cgul_block_reader_file instance.

Function Documentation

§ cgul_block_reader_file__as_block_reader()

CGUL_EXPORT cgul_block_reader_t cgul_block_reader_file__as_block_reader ( cgul_exception_t cex,
cgul_block_reader_file_t  brfile 
)

Safely upcast brfile to the cgul_block_reader interface.

Parameters
[in]cexc-style exception
[in]brfilecgul_block_reader_file instance
See also
cgul_block_reader

Referenced by cgul_block_reader_file_cxx::as_block_reader().

§ cgul_block_reader_file__new()

CGUL_EXPORT cgul_block_reader_file_t cgul_block_reader_file__new ( cgul_exception_t cex)

Create a new cgul_block_reader_file instance. After this method returns, cgul_block_reader_file__open_fname() or cgul_block_reader_file__open_file() should be called before calling cgul_block_reader_file__read_next_block(). The client is responsible for calling cgul_block_reader_file__delete() on the object returned. If an error occurs, NULL is returned, and an exception is thrown.

Note
It is safe to cast the object returned directly to a cgul_block_reader (i.e., to the base type).
Parameters
[in,out]cexc-style exception
Returns
new cgul_block_reader_file instance

Referenced by cgul_block_reader_file_cxx::cgul_block_reader_file_cxx().

§ cgul_block_reader_file__new_from_fname()

CGUL_EXPORT cgul_block_reader_file_t cgul_block_reader_file__new_from_fname ( cgul_exception_t cex,
const char *  fname 
)

This method creates a new cgul_block_reader_file instance and calls cgul_block_reader_file__open_fname() passing it fname. The file will be closed when this instance is deleted. The client is responsible for calling cgul_block_reader_file__delete() on the object returned. If an error occurs, NULL is returned, and an exception is thrown.

Parameters
[in,out]cexc-style exception
[in]fnamefile name
Returns
new cgul_block_reader_file instance

Referenced by cgul_block_reader_file_cxx::cgul_block_reader_file_cxx().

§ cgul_block_reader_file__new_from_file()

CGUL_EXPORT cgul_block_reader_file_t cgul_block_reader_file__new_from_file ( cgul_exception_t cex,
FILE *  f 
)

This method creates a new cgul_block_reader_file instance and calls cgul_block_reader_file__open_file() passing it f. The class does not take ownership of f. Thus, the client is still responsible for calling fclose() on it. The client is also responsible for calling cgul_block_reader_file__delete() on the object returned. If an error occurs, NULL is returned, and an exception is thrown.

Parameters
[in,out]cexc-style exception
[in]ffile
Returns
new cgul_block_reader_file instance

Referenced by cgul_block_reader_file_cxx::cgul_block_reader_file_cxx().

§ cgul_block_reader_file__delete()

CGUL_EXPORT void cgul_block_reader_file__delete ( cgul_block_reader_file_t  brfile)

This virtual method deletes the brfile instance freeing all internally allocated resources. This does not include closing the underlying file if it was obtained from the client by a call to cgul_block_reader_file__new_from_file() or cgul_block_reader_file__open_file(). The client must not use brfile after calling this method.

Parameters
[in]brfilecgul_block_reader_file instance

Referenced by cgul_block_reader_file_cxx::set_obj(), and cgul_block_reader_file_cxx::~cgul_block_reader_file_cxx().

§ cgul_block_reader_file__open_fname()

CGUL_EXPORT void cgul_block_reader_file__open_fname ( cgul_exception_t cex,
cgul_block_reader_file_t  brfile,
const char *  fname 
)

Open the file with name fname and use it when reading blocks of data. If a data source is already open, it will be closed before this method attempts to open the new data source. The new file will be closed when this instance is deleted. If an error occurs, an exception is thrown.

Parameters
[in,out]cexc-style exception
[in]brfilecgul_block_reader_file instance
[in]fnamefile name

Referenced by cgul_block_reader_file_cxx::open_fname().

§ cgul_block_reader_file__open_file()

CGUL_EXPORT void cgul_block_reader_file__open_file ( cgul_exception_t cex,
cgul_block_reader_file_t  brfile,
FILE *  f 
)

Use the file f when reading blocks of data. If a data source is already open, it is closed before attempting to open the new data source. This class does not take ownership of f. Thus, the client is still responsible for calling fclose() on f. If an error occurs, an exception is thrown.

Parameters
[in]cexc-style exception
[in]brfilecgul_block_reader_file instance
[in]ffile

Referenced by cgul_block_reader_file_cxx::open_file().

§ cgul_block_reader_file__close()

CGUL_EXPORT void cgul_block_reader_file__close ( cgul_exception_t cex,
cgul_block_reader_file_t  brfile 
)

Close the file. After this method returns, cgul_block_reader_file__open_fname() or cgul_block_reader_file__open_file() should be called before calling any other method.

Parameters
[in,out]cexc-style exception
[in]brfilecgul_block_reader_file instance

Referenced by cgul_block_reader_file_cxx::close().

§ cgul_block_reader_file__read_next_block()

CGUL_EXPORT size_t cgul_block_reader_file__read_next_block ( cgul_exception_t cex,
cgul_block_reader_file_t  brfile,
void *  block,
size_t  block_size 
)

Virtual method used to read one block of data block of size block_size bytes from the underlying file. The user is responsible for making sure block points to at least block_size contiguous bytes of memory. This method returns the number of bytes read or 0 if EOF is reached without error. If an error occurs, 0 is returned, and an exception is thrown.

Parameters
[in,out]cexc-style exception
[in]brfilecgul_block_reader_file instance
[in]blockblock
[in]block_sizeblock size in bytes
Returns
number of bytes read

Referenced by cgul_block_reader_file_cxx::read_next_block().

§ cgul_block_reader_file__get_fname()

CGUL_EXPORT const char* cgul_block_reader_file__get_fname ( cgul_exception_t cex,
cgul_block_reader_file_t  brfile 
)

Return the name of underlying file. If cgul_block_reader_file__new_from_file() or cgul_block_reader_file__open_file() was used to initialize the object, NULL is returned instead. This method throws an exception if no file is currently open.

Parameters
[in,out]cexc-style exception
[in]brfilecgul_block_reader_file instance
Returns
name of underlying file or NULL

Referenced by cgul_block_reader_file_cxx::get_fname().

§ cgul_block_reader_file__get_presentation_name()

CGUL_EXPORT const char* cgul_block_reader_file__get_presentation_name ( cgul_exception_t cex,
cgul_block_reader_file_t  brfile 
)

Virtual method that returns the presentation name.

Parameters
[in,out]cexc-style exception
[in]brfilecgul_block_reader_file instance
Returns
presentation name

Referenced by cgul_block_reader_file_cxx::get_presentation_name().

§ cgul_block_reader_file__set_presentation_name()

CGUL_EXPORT void cgul_block_reader_file__set_presentation_name ( cgul_exception_t cex,
cgul_block_reader_file_t  brfile,
const char *  presentation_name 
)

Virtual method that sets the presentation name. The presentation name is primarily used for error reporting and can be set to anything, but it does need to be set again if the input file changes. If the presentation name is not set, "FILE" is returned. An exception is thrown if an attempt is made to set the presentation name without first setting the input file.

Parameters
[in,out]cexc-style exception
[in]brfilecgul_block_reader_file instance
[in]presentation_namepresentation name

Referenced by cgul_block_reader_file_cxx::set_presentation_name().

§ cgul_block_reader_file__get_file()

CGUL_EXPORT FILE* cgul_block_reader_file__get_file ( cgul_exception_t cex,
cgul_block_reader_file_t  brfile 
)

Return the currently opened file. The client must not do anything that would invalidate the pointer or corrupt the associated data stream. This method throws an exception if no file is currently open.

Parameters
[in]cexc-style exception
[in]brfilecgul_block_reader_file instance
Returns
currently opened file or memory

Referenced by cgul_block_reader_file_cxx::get_file().