|
UCommon
|
A generic file streaming class built from the buffer protocol. More...
#include <buffer.h>


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, unsigned permissions, size_t size) | |
| Construct a file buffer that creates and opens a specific file. | |
| fbuf (char *path, fsys::access_t access, size_t size) | |
| Construct a file buffer that opens an existing 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. | |
Public Member Functions inherited from ucommon::BufferProtocol | |
| int | _getch (void) |
| Get a character from the buffer. | |
| int | _putch (int ch) |
| Put a character into the buffer. | |
| bool | eof (void) |
| Check if at end of input. | |
| int | err (void) |
| bool | flush (void) |
| Flush buffered memory to physical I/O. | |
| size_t | get (char *address, size_t count) |
| Get memory from the buffer. | |
| size_t | getline (char *string, size_t size) |
| Get text as a line of input from the buffer. | |
| size_t | getline (string &buffer) |
| Get a string as a line of input from the buffer. | |
| bool | is_input (void) |
| See if input active. | |
| bool | is_open (void) |
| See if buffer open. | |
| bool | is_output (void) |
| See if output active. | |
| bool | is_pending (void) |
| See if pending input. | |
| operator bool () | |
| See if buffer open. | |
| bool | operator! () |
| See if buffer closed. | |
| size_t | printf (const char *format,...) |
| Print formatted string to the buffer. | |
| void | purge (void) |
| Purge any pending input or output buffer data. | |
| size_t | put (const char *address, size_t count=0) |
| Put memory into the buffer. | |
| size_t | putline (const char *string) |
| Put a string as a line of output to the buffer. | |
| void | reset (void) |
| Reset input buffer state. | |
| void | seteof (void) |
| Set eof flag. | |
Public Member Functions inherited from ucommon::CharacterProtocol | |
| int | get (void) |
| Get the next character. | |
| int | put (int code) |
| Put the next character. | |
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) |
Protected Member Functions inherited from ucommon::BufferProtocol | |
| virtual bool | _blocking (void) |
| Return true if blocking. | |
| virtual int | _err (void) const =0 |
| Method to get low level i/o error. | |
| virtual bool | _flush (void) |
| Flush buffer to physical i/o. | |
| virtual bool | _pending (void) |
| Check if data is pending. | |
| virtual size_t | _push (const char *address, size_t size)=0 |
| Method to push buffer into physical i/o (write). | |
| void | allocate (size_t size, type_t access=BUF_RDWR) |
| Allocate I/O buffer(s) of specified size. | |
| BufferProtocol () | |
| Construct an empty (unallocated) buffer. | |
| BufferProtocol (size_t size, type_t access=BUF_RDWR) | |
| Construct a buffer of pre-allocated size and access type. | |
| char * | gather (size_t size) |
| Gather returns a pointer to contiguous input of specified size. | |
| void | release (void) |
| Release (free) buffer memory. | |
| char * | request (size_t size) |
| Request workspace in output buffer. | |
| void | seteol (const char *string) |
| Set end of line marker. | |
| size_t | unread (void) |
| Get current input position. | |
| size_t | unsaved (void) |
| Get current output position. | |
| virtual | ~BufferProtocol () |
| Destroy object by releasing buffer memory. | |
Additional Inherited Members | |
Public Types inherited from ucommon::BufferProtocol | |
| enum | type_t { BUF_RD, BUF_WR, BUF_RDWR } |
Protected Attributes inherited from ucommon::BufferProtocol | |
| const char * | format |
Private Types inherited from ucommon::fsys | |
| enum | access_t { ACCESS_RDONLY, ACCESS_WRONLY, ACCESS_REWRITE, ACCESS_RDWR = ACCESS_REWRITE, ACCESS_APPEND, ACCESS_SHARED, ACCESS_DIRECTORY, ACCESS_STREAM, ACCESS_RANDOM } |
| Enumerated file access modes. | |
| typedef struct stat | fileinfo_t |
| typedef long | offset_t |
| File offset type. | |
Private Member Functions inherited from ucommon::fsys | |
| void | assign (fd_t descriptor) |
| Assign descriptor directly. | |
| void | create (char *path, access_t access, unsigned mode) |
| Open a file descriptor directly. | |
| int | drop (offset_t size=0) |
| Drop cached data from start of file. | |
| int | err (void) |
| Get last error. | |
| int | fileinfo (fileinfo_t *buffer) |
| Get status of open descriptor. | |
| fsys () | |
| Construct an unattached fsys descriptor. | |
| fsys (fd_t handle) | |
| Contruct fsys from raw file handle. | |
| fsys (fsys &descriptor) | |
| Copy (dup) an existing fsys descriptor. | |
| fsys (char *path, access_t access) | |
| Create a fsys descriptor by opening an existing file or directory. | |
| fsys (char *path, access_t access, unsigned permission) | |
| Create a fsys descriptor by creating a file. | |
| fd_t | getHandle (void) |
| Get the native system descriptor handle of the file descriptor. | |
| bool | istty (void) |
| See if current file stream is a tty device. | |
| void | open (char *path, access_t access) |
| Open a file or directory. | |
| operator bool () | |
| Test if file descriptor is open. | |
| operator fd_t () | |
| Get the descriptor from the object by casting reference. | |
| bool | operator! () |
| Test if file descriptor is closed. | |
| fd_t | operator* () |
| Get the descriptor from the object by pointer reference. | |
| void | operator= (fsys &descriptor) |
| Assign file descriptor by duplicating another descriptor. | |
| void | operator= (fd_t descriptor) |
| Assing file descriptor from system descriptor. | |
| ssize_t | read (void *buffer, size_t count) |
| Read data from descriptor or scan directory. | |
| fd_t | release (void) |
| Release descriptor, do not close. | |
| void | set (fd_t descriptor) |
| Set with external descriptor. | |
| int | sync (void) |
| Commit changes to the filesystem. | |
| ssize_t | write (void *buffer, size_t count) |
| Write data to descriptor. | |
| ~fsys () | |
| Close and release a file descriptor. | |
Static Private Member Functions inherited from ucommon::fsys | |
| static int | access (char *path, unsigned mode) |
| Test path access. | |
| static fd_t | append (char *path) |
| Direct means to create or append a writable path and return descriptor. | |
| static void | assign (fsys &object, fd_t descriptor) |
| Assign a descriptor directly. | |
| static int | change (char *path, unsigned mode) |
| Change file access mode. | |
| static int | changeDir (char *path) |
| Set directory prefix (chdir). | |
| static void | close (fsys &descriptor) |
| Close a file descriptor or directory directly. | |
| static int | copy (char *source, char *target, size_t size=1024) |
| Copy a file. | |
| static void | create (fsys &object, char *path, access_t access, unsigned mode) |
| create a file descriptor or directory directly. | |
| static int | createDir (char *path, unsigned mode) |
| Simple direct method to create a directory. | |
| static int | drop (fsys &descriptor, offset_t size) |
| Drop cached data from a file descriptor. | |
| static int | fileinfo (char *path, fileinfo_t *buffer) |
| Stat a file. | |
| static void * | find (fsys &module, char *symbol) |
| Find symbol in loaded module. | |
| static int | getPrefix (char *path, size_t size) |
| Get current directory prefix (pwd). | |
| static int | hardlink (char *path, char *target) |
| Create a hard link. | |
| static fd_t | input (char *path) |
| Direct means to open a read-only file path and return a descriptor. | |
| static bool | ischar (struct stat *inode) |
| static bool | isdev (struct stat *inode) |
| static bool | isdir (char *path) |
| Test if path is a directory. | |
| static bool | isdir (struct stat *inode) |
| static bool | isdisk (struct stat *inode) |
| static bool | isfile (char *path) |
| Test if path is a file. | |
| static bool | isfile (struct stat *inode) |
| static bool | ishidden (char *path) |
| Test if path is a hidden file. | |
| static bool | islink (char *path) |
| Test if path is a symlink. | |
| static bool | islink (struct stat *inode) |
| static bool | issys (struct stat *inode) |
| static bool | istty (fd_t fd) |
| See if the file handle is a tty device. | |
| static int | link (char *path, char *target) |
| Create a symbolic link. | |
| static int | linkinfo (char *path, char *buffer, size_t size) |
| Read a symbolic link to get it's target. | |
| static int | load (char *path) |
| Load an unmaged plugin directly. | |
| static void | load (fsys &module, char *path) |
| Load a plugin into memory. | |
| static void | open (fsys &object, char *path, access_t access) |
| Open a file or directory. | |
| static fd_t | output (char *path) |
| Direct means to create or access a writable path and return descriptor. | |
| static ssize_t | read (fsys &descriptor, void *buffer, size_t count) |
| Read data from file descriptor or directory. | |
| static void | release (fd_t descriptor) |
| Release a file descriptor. | |
| static int | remapError (void) |
| static int | remove (char *path) |
| Remove a file. | |
| static int | removeDir (char *path) |
| Simple direct method to remove a directory. | |
| static int | rename (char *oldpath, char *newpath) |
| Rename a file. | |
| static int | seek (fsys &descriptor, offset_t offset) |
| Set the position of a file descriptor. | |
| static int | unlink (char *path) |
| Remove a symbolic link explicitly. | |
| static void | unload (fsys &module) |
| unload a specific plugin. | |
| static ssize_t | write (fsys &descriptor, void *buffer, size_t count) |
| write data to file descriptor. | |
Static Private Attributes inherited from ucommon::fsys | |
| static offset_t | end |
| Used to mark "append" in set position operations. | |
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++.
| ucommon::fbuf::fbuf | ( | char * | path, |
| fsys::access_t | access, | ||
| unsigned | permissions, | ||
| size_t | size | ||
| ) |
Construct a file buffer that creates and opens a specific file.
| path | of file to create. |
| access | mode of file (rw, rdonly, etc). |
| permissions | of the newly created file. |
| size | of the stream buffer. |
| ucommon::fbuf::fbuf | ( | char * | path, |
| fsys::access_t | access, | ||
| size_t | size | ||
| ) |
Construct a file buffer that opens an existing file.
| path | of existing file to open. |
| access | mode of file (rw, rdonly, etc). |
| size | of the stream buffer. |
|
protectedvirtual |
Method to pull buffer from physical i/o (read).
The address is passed to this virtual since it is hidden as private.
| address | of buffer to pull data into. |
| size | of buffer area being pulled.. |
Implements ucommon::BufferProtocol.
| void ucommon::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.
| path | of file to create. |
| access | mode of file (rw, rdonly, etc). |
| permissions | of the newly created file. |
| size | of the stream buffer. |
| void ucommon::fbuf::open | ( | char * | path, |
| fsys::access_t | access = fsys::ACCESS_RDWR, |
||
| size_t | size = 512 |
||
| ) |
Construct a file buffer that opens an existing file.
| path | of existing file to open. |
| access | mode of file (rw, rdonly, etc). |
| size | of the stream buffer. |
| bool ucommon::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.
| offset | to seek. |
Reimplemented from ucommon::fsys.
| offset_t ucommon::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.
| bool ucommon::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.
| offset | to truncate. |
Reimplemented from ucommon::fsys.
1.8.1.1