cgul_block_reader_memory.h File Reference

memory block reader More...

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

Typedefs

typedef typedefCGUL_BEGIN_C struct cgul_block_reader_memory * cgul_block_reader_memory_t
 

Functions

CGUL_EXPORT cgul_block_reader_t cgul_block_reader_memory__as_block_reader (cgul_exception_t *cex, cgul_block_reader_memory_t brmemory)
 
CGUL_EXPORT cgul_block_reader_memory_t cgul_block_reader_memory__new (cgul_exception_t *cex)
 
CGUL_EXPORT cgul_block_reader_memory_t cgul_block_reader_memory__new_from_memory (cgul_exception_t *cex, void *buffer, size_t buffer_size)
 
CGUL_EXPORT void cgul_block_reader_memory__delete (cgul_block_reader_memory_t brmemory)
 
CGUL_EXPORT void cgul_block_reader_memory__open (cgul_exception_t *cex, cgul_block_reader_memory_t brmemory, void *buffer, size_t buffer_size)
 
CGUL_EXPORT void cgul_block_reader_memory__close (cgul_exception_t *cex, cgul_block_reader_memory_t brmemory)
 
CGUL_EXPORT size_t cgul_block_reader_memory__read_next_block (cgul_exception_t *cex, cgul_block_reader_memory_t brmemory, void *block, size_t block_size)
 
CGUL_EXPORT const char * cgul_block_reader_memory__get_presentation_name (cgul_exception_t *cex, cgul_block_reader_memory_t brmemory)
 
CGUL_EXPORT void cgul_block_reader_memory__set_presentation_name (cgul_exception_t *cex, cgul_block_reader_memory_t brmemory, const char *presentation_name)
 
CGUL_EXPORT void * cgul_block_reader_memory__get_buffer (cgul_exception_t *cex, cgul_block_reader_memory_t brmemory)
 

Detailed Description

Implementation of the cgul_block_reader interface for data stored in memory.

Author
Paul Serice

Typedef Documentation

§ cgul_block_reader_memory_t

typedef typedefCGUL_BEGIN_C struct cgul_block_reader_memory* cgul_block_reader_memory_t

Opaque pointer to a cgul_block_reader_memory instance.

Function Documentation

§ cgul_block_reader_memory__as_block_reader()

CGUL_EXPORT cgul_block_reader_t cgul_block_reader_memory__as_block_reader ( cgul_exception_t cex,
cgul_block_reader_memory_t  brmemory 
)

Safely upcast brmemory to the cgul_block_reader interface.

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

Referenced by cgul_block_reader_memory_cxx::as_block_reader().

§ cgul_block_reader_memory__new()

CGUL_EXPORT cgul_block_reader_memory_t cgul_block_reader_memory__new ( cgul_exception_t cex)

Create a new cgul_block_reader_memory instance. After this method returns, cgul_block_reader_memory__open() should be called before calling cgul_block_reader_memory__read_next_block(). The client is responsible for calling cgul_block_reader_memory__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_memory instance

Referenced by cgul_block_reader_memory_cxx::cgul_block_reader_memory_cxx().

§ cgul_block_reader_memory__new_from_memory()

CGUL_EXPORT cgul_block_reader_memory_t cgul_block_reader_memory__new_from_memory ( cgul_exception_t cex,
void *  buffer,
size_t  buffer_size 
)

This method creates a new cgul_block_reader_memory instance and calls cgul_block_reader_memory__open() passing it buffer and buffer_size. This class does not take ownership of buffer so the client is still responsible for freeing buffer if necessary. The client is also responsible for calling cgul_block_reader_memory__delete() on the object returned. If an error occurs, NULL is returned, and an exception is thrown.

Parameters
[in,out]cexc-style exception
[in]buffermemory buffer
[in]buffer_sizesize of buffer in bytes
Returns
new cgul_block_reader_memory instance

Referenced by cgul_block_reader_memory_cxx::cgul_block_reader_memory_cxx().

§ cgul_block_reader_memory__delete()

CGUL_EXPORT void cgul_block_reader_memory__delete ( cgul_block_reader_memory_t  brmemory)

This virtual method deletes the brmemory instance freeing all internally allocated resources. The client must not use brmemory after calling this method.

Parameters
[in]brmemorycgul_block_reader_memory instance

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

§ cgul_block_reader_memory__open()

CGUL_EXPORT void cgul_block_reader_memory__open ( cgul_exception_t cex,
cgul_block_reader_memory_t  brmemory,
void *  buffer,
size_t  buffer_size 
)

Set the buffer buffer to use when reading blocks of data from memory. If a memory buffer is already open, it will be closed before this method attempts to open the new memory buffer. This class does not take ownership of buffer. Thus, the client is still responsible for freeing buffer if necessary. If an error occurs, an exception is thrown.

Parameters
[in,out]cexc-style exception
[in]brmemorycgul_block_reader_memory instance
[in]bufferinput memory buffer
[in]buffer_sizesize of buffer in bytes

Referenced by cgul_block_reader_memory_cxx::open().

§ cgul_block_reader_memory__close()

CGUL_EXPORT void cgul_block_reader_memory__close ( cgul_exception_t cex,
cgul_block_reader_memory_t  brmemory 
)

Close the memory. After this method returns, cgul_block_reader_memory__open should be called before calling any other method.

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

Referenced by cgul_block_reader_memory_cxx::close().

§ cgul_block_reader_memory__read_next_block()

CGUL_EXPORT size_t cgul_block_reader_memory__read_next_block ( cgul_exception_t cex,
cgul_block_reader_memory_t  brmemory,
void *  block,
size_t  block_size 
)

Virtual method that reads one block of data block of size block_size bytes from the underlying buffer. The user is responsible for making sure block points to at least block_size contiguous bytes of memory. The user is also responsible for making sure block does not overlap with the open buffer from which blocks are read (as required by memcpy()). 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]brmemorycgul_block_reader_memory instance
[in]blockblock
[in]block_sizeblock size in bytes
Returns
number of bytes read

Referenced by cgul_block_reader_memory_cxx::read_next_block().

§ cgul_block_reader_memory__get_presentation_name()

CGUL_EXPORT const char* cgul_block_reader_memory__get_presentation_name ( cgul_exception_t cex,
cgul_block_reader_memory_t  brmemory 
)

Virtual method that returns the presentation name.

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

Referenced by cgul_block_reader_memory_cxx::get_presentation_name().

§ cgul_block_reader_memory__set_presentation_name()

CGUL_EXPORT void cgul_block_reader_memory__set_presentation_name ( cgul_exception_t cex,
cgul_block_reader_memory_t  brmemory,
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 buffer changes. If the presentation name is not set, "MEMORY" is returned. An exception is thrown if an attempt is made to set the presentation name without first setting the input buffer.

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

Referenced by cgul_block_reader_memory_cxx::set_presentation_name().

§ cgul_block_reader_memory__get_buffer()

CGUL_EXPORT void* cgul_block_reader_memory__get_buffer ( cgul_exception_t cex,
cgul_block_reader_memory_t  brmemory 
)

Return the currently opened buffer from which blocks are read. The client must not do anything that would invalidate the pointer or corrupt the associated data stream. This method throws an exception only if a file is not currently open.

Because the client is responsible for freeing the buffer if necessary, it can be convenient to call this method just before deleting the object in order to free the pointer returned.

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

Referenced by cgul_block_reader_memory_cxx::get_buffer().