AXCEL C++ Framework
Elegance through abstraction
|
File. More...
#include <axcel.h>
Public Member Functions | |
virtual string | type () |
Get type of object. | |
virtual | operator string () |
Convert to string. | |
bool | operator! () |
file () | |
file (const char *name, const char *mode) | |
From existing fs::file. | |
file (FILE *f) | |
From open FILE stream. | |
file (int fh, const char *mode) | |
From fs::file descriptor. | |
int | putc (int c) |
Write byte. | |
int | getc () |
Read byte. | |
FILE * | open (const char *fname, const char *mode) |
Open fs::file. | |
FILE * | dopen (int fh, const char *mode) |
Open file from file descriptor. | |
FILE * | reopen (const char *fname, const char *mode) |
Re-open file. | |
bool | close () |
Close file. | |
bool | flush () |
Flush file stream. | |
bool | seek (long offset, int whence) |
Reposition file stream. | |
long | tell () |
Get file position. | |
bool | rewind () |
Rewind file position. | |
bool | unwind () |
Unwind file position. | |
bool | ffwd (long offset) |
increment file position | |
bool | prev (long offset) |
Decrement file position. | |
bool | nobuf () |
Set as unbuffered. | |
bool | lbuf () |
Set as line buffered. | |
bool | fbuf (char *buf, size_t size) |
Set as block buffered. | |
int | ungetc (int c) |
Push back read byte. | |
operator FILE * () | |
Public Attributes | |
FILE * | fd |
File.
A file is a node that can be referenced by it's name from the file system and read from and/or written to. This class goes on top of the file stream functions from the Standard C Library. The type of files this class focuses on are regular files that are located on some disk, flash media, or other device whose contents are static and retained even when the computer is turned off.
axcel::fs::file::file | ( | const char * | name, |
const char * | mode | ||
) |
axcel::fs::file::file | ( | int | fh, |
const char * | mode | ||
) |
bool axcel::fs::file::close | ( | ) |
FILE * axcel::fs::file::dopen | ( | int | fh, |
const char * | mode | ||
) |
Open file from file descriptor.
fh | file descriptor |
mode | file open mode (see open()) |
Associates this stream with the existing file descriptor, fh. The mode of the stream (one of the values "r", "r+", "w", "w+", "a", "a+") must be compatible with the mode of the file descriptor. The file position indicator of the new stream is set to that belonging to fd, and the error and end-of-file indicators are cleared. Modes "w" or "w+" do not cause truncation of the file. The file descriptor is not dup'ed, and will be closed when the stream created by dopen() is closed. The result of applying dopen() to a shared memory object is undefined.
bool axcel::fs::file::fbuf | ( | char * | buf, |
size_t | size | ||
) |
Set as block buffered.
Sets the file stream as block/fully buffered. When set to block buffered, many characters are saved up and written as a block. buf should point to a buffer at least
size bytes long; this buffer will be used instead of the current buffer. If buf is NULL, only the mode is affected; a new buffer will be allocated on the next read or write operation.
bool axcel::fs::file::ffwd | ( | long | offset | ) |
bool axcel::fs::file::flush | ( | ) |
Flush file stream.
Forces a write of all user-space buffered data for the stream. For input streams, discards any buffered data that has been fetched from the underlying file, but has not been by the application. The open status of the stream is unaffected.
int axcel::fs::file::getc | ( | ) | [virtual] |
Read byte.
Reads the next character from stream and returns it as an unsigned char cast to an int, or EOF on end of file or error. Before returning from the method, one of the following methods of the stream must be called:
Implements axcel::io::input.
bool axcel::fs::file::lbuf | ( | ) |
bool axcel::fs::file::nobuf | ( | ) |
FILE * axcel::fs::file::open | ( | const char * | fname, |
const char * | mode | ||
) |
Open fs::file.
fname | Absolute or relative path of file |
mode | Open file mode |
Opens the file whose name is the string pointed to by fname and associates a stream with it.
The argument mode points to a string beginning with one of the following sequences (Additional characters may follow these sequences.):
The mode string can also include the letter 'b' either as a last character or as a character between the characters in any of the two-chracter strings described above. As this function calls fopen, this is strictly for compatibility with C89 and has no effect; the 'b' is ignored on all POSIX conforming systems, including Linux. (Other systems may treat text files and binary files differently, and adding the 'b' may be a good idea if you do I/O to binary file and expect that your program may be ported to non-Unix environments.)
axcel::fs::file::operator string | ( | ) | [virtual] |
Convert to string.
Reimplemented from axcel::io::ios.
bool axcel::fs::file::prev | ( | long | offset | ) |
int axcel::fs::file::putc | ( | int | c | ) | [virtual] |
Write byte.
c | Character to write |
Writes character c to stream and returns a non-negative number on success or EOF on error. Before returning from within this method, one of the following methods must be called:
Implements axcel::io::output.
FILE * axcel::fs::file::reopen | ( | const char * | fname, |
const char * | mode | ||
) |
Re-open file.
fname | Absolute or relative path of file |
mode | file open mode |
Opens the file whose name is the string pointed to by fname and associates this stream with it. The original stream (if it exists) is closed. The mode argument is used just as in the open() method. The primary use of reopen() method is to change the file associated with a standard text stream (stderr, stdin, or stdout).
bool axcel::fs::file::rewind | ( | ) |
bool axcel::fs::file::seek | ( | long | offset, |
int | whence | ||
) |
Reposition file stream.
offset | Offset to reposition to |
whence | base of offset |
Sets the file position indicator for the stream. The new position, measured in bytes, is obtained by adding offset bytes to the position specified by whence. If whence is set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is relative to the start of the file, the current position indicator, or end-of-file, respectively. A successful call to seek() clears the end-of-file indicator for the stream and undoes any effects of the ungetc() function on the same stream.
long axcel::fs::file::tell | ( | ) |
string axcel::fs::file::type | ( | ) | [virtual] |
Get type of object.
Reimplemented from axcel::io::ios.
int axcel::fs::file::ungetc | ( | int | c | ) |
Push back read byte.
c | Character to push back |
Pushes c back to the stream, cast to unsigned char, where it is available for subsequent read operations. Pushed-back characters will be returned in reverse order; only one pushback is guaranteed.
bool axcel::fs::file::unwind | ( | ) |
FILE* axcel::fs::file::fd |