UCommon

ucc::fbuf Class Reference

A generic file streaming class built from the buffer protocol. More...

#include <buffer.h>

Inheritance diagram for ucc::fbuf:
Collaboration diagram for ucc::fbuf:

Public Member Functions

void close (void)
 Close the file, flush buffers.
void create (char *path, fsys::access_t access=fsys::ACCESS_APPEND, unsigned permissions=0640, size_t size=512)
 Create and open the specified file.
 fbuf ()
 Construct an unopened file buffer.
 fbuf (char *path, fsys::access_t access, size_t size)
 Construct a file buffer that opens an existing file.
 fbuf (char *path, fsys::access_t access, unsigned permissions, size_t size)
 Construct a file buffer that creates and opens a specific file.
void open (char *path, fsys::access_t access=fsys::ACCESS_RDWR, size_t size=512)
 Construct a file buffer that opens an existing file.
bool seek (offset_t offset)
 Seek specific offset in open file and reset I/O buffers.
offset_t tell (void)
 Give the current position in the currently open file.
bool trunc (offset_t offset)
 Truncate the currently open file to a specific position.
 ~fbuf ()
 Destroy object and release all resources.

Protected Member Functions

void _clear (void)
 Method to clear low level i/o error.
int _err (void)
size_t _pull (char *address, size_t size)
 Method to pull buffer from physical i/o (read).
size_t _push (char *address, size_t size)
fd_t getfile (void)

Detailed Description

A generic file streaming class built from the buffer protocol.

This can be used in place of fopen based file operations and does not require libstdc++.

Author:
David Sugar <dyfet@gnutelephony.org>

Definition at line 57 of file buffer.h.


Constructor & Destructor Documentation

ucc::fbuf::fbuf ( char *  path,
fsys::access_t  access,
unsigned  permissions,
size_t  size 
)

Construct a file buffer that creates and opens a specific file.

Parameters:
pathof file to create.
accessmode of file (rw, rdonly, etc).
permissionsof the newly created file.
sizeof the stream buffer.
ucc::fbuf::fbuf ( char *  path,
fsys::access_t  access,
size_t  size 
)

Construct a file buffer that opens an existing file.

Parameters:
pathof existing file to open.
accessmode of file (rw, rdonly, etc).
sizeof the stream buffer.

Member Function Documentation

size_t ucc::fbuf::_pull ( char *  address,
size_t  size 
) [protected, virtual]

Method to pull buffer from physical i/o (read).

The address is passed to this virtual since it is hidden as private.

Parameters:
addressof buffer to pull data into.
sizeof buffer area being pulled..
Returns:
number of read written, 0 on error or end of data.

Implements BufferProtocol.

void ucc::fbuf::create ( char *  path,
fsys::access_t  access = fsys::ACCESS_APPEND,
unsigned  permissions = 0640,
size_t  size = 512 
)

Create and open the specified file.

If a file is currently open, it is closed first.

Parameters:
pathof file to create.
accessmode of file (rw, rdonly, etc).
permissionsof the newly created file.
sizeof the stream buffer.
void ucc::fbuf::open ( char *  path,
fsys::access_t  access = fsys::ACCESS_RDWR,
size_t  size = 512 
)

Construct a file buffer that opens an existing file.

Parameters:
pathof existing file to open.
accessmode of file (rw, rdonly, etc).
sizeof the stream buffer.
bool ucc::fbuf::seek ( offset_t  offset)

Seek specific offset in open file and reset I/O buffers.

If the file is opened for both read and write, both the read and write position will be reset.

Parameters:
offsetto seek.
Returns:
true if successful.

Reimplemented from ucc::fsys.

offset_t ucc::fbuf::tell ( void  )

Give the current position in the currently open file.

If we are appending, this is always seek::end. If we have a file opened for both read and write, this gives the read offset.

Returns:
file offset of current i/o operations.
bool ucc::fbuf::trunc ( offset_t  offset)

Truncate the currently open file to a specific position.

All I/O buffers are reset and the file pointer is set to the end.

Parameters:
offsetto truncate.
Returns:
true if successful.

Reimplemented from ucc::fsys.


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