AXCEL C++ Framework
Elegance through abstraction
Public Member Functions | Public Attributes
axcel::fs::file Class Reference

File. More...

#include <axcel.h>

Inheritance diagram for axcel::fs::file:
axcel::io::ios axcel::io::input axcel::io::output axcel::io::iob axcel::io::iob axcel::object axcel::object

List of all members.

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

Detailed Description

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.

Definition at line 839 of file axcel.h.


Constructor & Destructor Documentation

axcel::fs::file::file ( ) [inline]

Definition at line 845 of file axcel.h.

axcel::fs::file::file ( const char *  name,
const char *  mode 
)

From existing fs::file.

Definition at line 3643 of file axcel.cpp.

axcel::fs::file::file ( FILE *  f)

From open FILE stream.

Definition at line 3645 of file axcel.cpp.

axcel::fs::file::file ( int  fh,
const char *  mode 
)

From fs::file descriptor.

Definition at line 3647 of file axcel.cpp.


Member Function Documentation

bool axcel::fs::file::close ( )

Close file.

Returns:
true success, false failure

Flushes the stream and closes the underlying file descriptor.

Definition at line 3491 of file axcel.cpp.

FILE * axcel::fs::file::dopen ( int  fh,
const char *  mode 
)

Open file from file descriptor.

Parameters:
fhfile descriptor
modefile open mode (see open())
Returns:
fd global member FILE*

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.

Definition at line 3456 of file axcel.cpp.

bool axcel::fs::file::fbuf ( char *  buf,
size_t  size 
)

Set as block buffered.

Returns:
true success, false failure

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.

Definition at line 3622 of file axcel.cpp.

bool axcel::fs::file::ffwd ( long  offset)

increment file position

Parameters:
offsetNumber of times to increment
Returns:
true success, false failure

Adds offset to current file position.

Definition at line 3578 of file axcel.cpp.

bool axcel::fs::file::flush ( )

Flush file stream.

Returns:
true success, false failure

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.

Definition at line 3507 of file axcel.cpp.

int axcel::fs::file::getc ( ) [virtual]

Read byte.

Returns:
Character read as an unsigned char cast to an int or EOF on end of file or error

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:

  • If end of file is reached, the method must call drain()
  • If a small error occurs but the stream is still usable, the method must call hurt()
  • If a fatal error occurs and the stream is unusable, the method must call kill()
  • If successful, the method must call heal()

Implements axcel::io::input.

Definition at line 3384 of file axcel.cpp.

bool axcel::fs::file::lbuf ( )

Set as line buffered.

Returns:
true success, false failure

Sets the file stream as line buffered. When set to line buffered, characters are saved up until a newline is output or input is read from any stream attached to a terminal device (typically stdin).

Definition at line 3606 of file axcel.cpp.

bool axcel::fs::file::nobuf ( )

Set as unbuffered.

Returns:
true success, false failure

Sets the file stream as unbuffered. When set to unbuffered, information appears on the destination file or terminal as soon as written.

Definition at line 3593 of file axcel.cpp.

FILE * axcel::fs::file::open ( const char *  fname,
const char *  mode 
)

Open fs::file.

Parameters:
fnameAbsolute or relative path of file
modeOpen file mode
Returns:
fd global member FILE*

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.):

  • r - Open text file for reading. The stream is positioned at the beginning of the file.
  • r+ - Open for reading and writing.
  • w - Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file.
  • w+ - Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file.
  • a - Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file.
  • a+ - Open for reading and appending (Writing at end of file). The file is created if it does not exist. The initial file position for reading is at the beginning of the file, but the output is always appended to the end of the file.

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.)

Definition at line 3435 of file axcel.cpp.

axcel::fs::file::operator FILE * ( ) [inline]

Definition at line 867 of file axcel.h.

axcel::fs::file::operator string ( ) [virtual]

Convert to string.

Returns:
Suitable string representation of object's data

Reimplemented from axcel::io::ios.

Definition at line 283 of file axcel.cpp.

bool axcel::fs::file::operator! ( )

Definition at line 6664 of file axcel.cpp.

bool axcel::fs::file::prev ( long  offset)

Decrement file position.

Parameters:
offsetnumber of times to decrement

Subtracts offset from current file position.

Definition at line 3585 of file axcel.cpp.

int axcel::fs::file::putc ( int  c) [virtual]

Write byte.

Parameters:
cCharacter to write
Returns:
Character written or EOF on end of file or error

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:

  • If end of file is reached, the method must call drain()
  • If an error occurs, the method must call kill()
  • If successful, the method must call heal()

Implements axcel::io::output.

Definition at line 3374 of file axcel.cpp.

FILE * axcel::fs::file::reopen ( const char *  fname,
const char *  mode 
)

Re-open file.

Parameters:
fnameAbsolute or relative path of file
modefile 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).

Definition at line 3475 of file axcel.cpp.

bool axcel::fs::file::rewind ( )

Rewind file position.

Returns:
true success, false failure

Sets the file position indicator for the stream to the beginning of the file.

Definition at line 3563 of file axcel.cpp.

bool axcel::fs::file::seek ( long  offset,
int  whence 
)

Reposition file stream.

Parameters:
offsetOffset to reposition to
whencebase of offset
Returns:
true success, false failure

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.

Definition at line 3529 of file axcel.cpp.

long axcel::fs::file::tell ( )

Get file position.

Returns:
file position or EOF on error

Obtains the current value of the file position indicator for the stream.

Definition at line 3546 of file axcel.cpp.

string axcel::fs::file::type ( ) [virtual]

Get type of object.

Returns:
string containing name of object's class.

Reimplemented from axcel::io::ios.

Definition at line 257 of file axcel.cpp.

int axcel::fs::file::ungetc ( int  c)

Push back read byte.

Parameters:
cCharacter to push back
Returns:
c on success, or EOF on error.

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.

Definition at line 3636 of file axcel.cpp.

bool axcel::fs::file::unwind ( )

Unwind file position.

Returns:
true success, false failure

Sets the file position indicator for the stream to the end of the file.

Definition at line 3570 of file axcel.cpp.


Member Data Documentation

Definition at line 844 of file axcel.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Defines