Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MCFile Class Reference

Representation of a file. More...

#include <mcllib/MCFile.h>

Inheritance diagram for MCFile:

MCIOBase MCDirEntry MCBase List of all members.

Public Types

enum  ESeekWhence { MCSEEKSTART = 0, MCSEEKCUR = 1, MCSEEKEND = 2 }
 Enumeration indicating how the seek() method should operate. More...
enum  EStdHandle { MCSTDIN = 0, MCSTDOUT = 1, MCSTDERR = 2 }
 Standard file handles. More...

Public Member Functions

bool isStdHandle ()
 Check to see if the file refers to a standard file handle.
 MCFile (const MCString &name)
 Construct a file which represents a file in the filesystem.
 MCFile (EStdHandle hdl)
 Construct a file which represents one of the standard files.
 MCFile ()
 Default constructor.
void open (mcintn flags, mcintn mode=0666)
 Open the file.
mcintn print (const char *fmt,...)
 Write formatted output to the file in the style of printf().
mcintn printf (const char *fmt,...)
 Write formatted output to the file in the style of printf().
mcint64 seek (mcint64 offset, ESeekWhence whence)
 Position within the file.
void sync ()
 Block until the file's contents are physically on the disk.
mcintn vprint (const char *fmt, va_list ap)
 Write formatted output to the file in the style of vprintf().
mcintn vprintf (const char *fmt, va_list ap)
 vprintf to the file.
 ~MCFile ()
 Destructor.

Static Public Attributes

const mcintn MCAPPEND
 Flag indicating open the file for append.
const mcintn MCCREATE
 Flag indicating that the file should be created if it doesn't exist.
const mcintn MCEXCL
 Flag indicating that create should fail if the file already exists.
const mcintn MCMAKE
 Convenience to open a file read-write, creating if necessary.
const mcintn MCMAKEEMPTY
 Flag indicating to create the file is necessary and erase any existing content (truncate).
const mcintn MCRDONLY
 Flag indicating open the file read only.
const mcintn MCRDWR
 Flag indicating open the file for reading and writing.
const mcintn MCSYNC
 Flag indicating that writes block until the data is physically on disk.
const mcintn MCTRUNC
 Flag indicating that the file should be truncated (emptied).
const mcintn MCWRONLY
 Flag indicating open the file write only.

Detailed Description

Representation of a file.

Platform Note: The print() set of functions ensure that new-lines are output as CR-NL on platforms where this is the normal line ending (e.g. WIN32 platforms).


Member Enumeration Documentation

enum ESeekWhence
 

Enumeration indicating how the seek() method should operate.

Enumeration values:
MCSEEKSTART  Seek offset is relative to the start of the file.
MCSEEKCUR  Seek offset is relative to the current file position.
MCSEEKEND  Seek offset is relative to the end of the file.

enum EStdHandle
 

Standard file handles.

Enumeration values:
MCSTDIN  Represents the standard input handle.
MCSTDOUT  Represents the standard output handle.
MCSTDERR  Represents the standard error handle.


Constructor & Destructor Documentation

MCFile  ) 
 

Default constructor.

Calls to open() on files created in this way will throw an exception.

MCFile EStdHandle  hdl  ) 
 

Construct a file which represents one of the standard files.

Calls to open() on files created in this way will throw an exception.

Parameters:
hdl the EStdHandle to use

MCFile const MCString name  ) 
 

Construct a file which represents a file in the filesystem.

Construction does not create the file or access the filesystem.

Parameters:
name name of the file

~MCFile  ) 
 

Destructor.

If the file is open (and does not represent a standard file - stdin, stdout, stderr) it is closed.


Member Function Documentation

bool isStdHandle  ) 
 

Check to see if the file refers to a standard file handle.

Returns:
true if the file is a standard handle

void open mcintn  flags,
mcintn  mode = 0666
 

Open the file.

Parameters:
flags flags indicating how the file is to be opened. If the file cannot be opened in the way specified by flags then an exception is thrown. This could be because the file does not exist, cannot be created, is read-only and the open mode specifies write access etc.
mode access mode for the file. If access modes are supported on the platform, and the open would create the file and the file doesn't already exist then the new file is created with the specified mode.

mcintn print const char *  fmt,
  ...
 

Write formatted output to the file in the style of printf().

A new-line is added at the end of the output if one is missing. An exception is thrown if the output fails.

Parameters:
fmt a format specification.
... variable arguments depending on the format specification
Returns:
the number of characters output

mcintn printf const char *  fmt,
  ...
 

Write formatted output to the file in the style of printf().

An exception is thrown if the output fails.

Parameters:
fmt a format specification.
... variable arguments depending on the format specification
Returns:
the number of characters output

mcint64 seek mcint64  offset,
ESeekWhence  whence
 

Position within the file.

An exception is thrown if the seek fails (e.g. because the file is not open).

Parameters:
offset the offset to position to
whence the position relative to which the offset applies
Returns:
the offset relative to the beginning of the file

void sync  ) 
 

Block until the file's contents are physically on the disk.

If pending writes have been buffered they will be synchronized to the disk.

mcintn vprint const char *  fmt,
va_list  ap
 

Write formatted output to the file in the style of vprintf().

A new-line is added at the end of the output if one is missing. An exception is thrown if the output fails.

Parameters:
fmt a format specification.
ap va_list obtained from a varargs function
Returns:
the number of characters output

mcintn vprintf const char *  fmt,
va_list  ap
 

vprintf to the file.

An exception is thrown if the output fails. Write formatted output to the file in the style of vprintf(). An exception is thrown if the output fails.

Parameters:
fmt a format specification.
ap va_list obtained from a varargs function
Returns:
the number of characters output


Member Data Documentation

const mcintn MCAPPEND [static]
 

Flag indicating open the file for append.

The file is opened read/write and positioned at the end. Use in the open() method.

const mcintn MCCREATE [static]
 

Flag indicating that the file should be created if it doesn't exist.

Use in the open() method.

const mcintn MCMAKE [static]
 

Convenience to open a file read-write, creating if necessary.

Equivalent to MCRDWR | MCCREATE

const mcintn MCMAKEEMPTY [static]
 

Flag indicating to create the file is necessary and erase any existing content (truncate).

Equivalent to MCMAKE | MCTRUNC

const mcintn MCRDONLY [static]
 

Flag indicating open the file read only.

Use in the open() method

const mcintn MCRDWR [static]
 

Flag indicating open the file for reading and writing.

This is the same as MCRDONLY | MCWRONLY. Use in the open() method

const mcintn MCSYNC [static]
 

Flag indicating that writes block until the data is physically on disk.

Use in the open() method

const mcintn MCTRUNC [static]
 

Flag indicating that the file should be truncated (emptied).

Use in the open() method

const mcintn MCWRONLY [static]
 

Flag indicating open the file write only.

Use in the open() method


Generated on Wed Jan 12 19:05:49 2005 for MCLLIB by  doxygen 1.3.9.1