torque Torque Game Engine Documentation
TGE Version 1.5.2

File Class Reference

#include <fileio.h>


Public Types

enum  Status {
  Ok = 0,
  IOError,
  EOS,
  IllegalCall,
  Closed,
  UnknownError
}
 What is the status of our file handle? More...
enum  AccessMode {
  Read = 0,
  Write = 1,
  ReadWrite = 2,
  WriteAppend = 3
}
 How are we accessing the file? More...
enum  Capability {
  FileRead = BIT(0),
  FileWrite = BIT(1)
}
 Flags used to indicate what we can do to the file. More...

Public Member Functions

 File ()
 Default constructor.
virtual ~File ()
 Destructor.
Status open (const char *filename, const AccessMode openMode)
 Opens a file for access using the specified AccessMode.
U32 getPosition () const
 Gets the current position in the file.
Status setPosition (S32 position, bool absolutePos=true)
 Sets the current position in the file.
U32 getSize () const
 Returns the size of the file.
Status flush ()
 Make sure everything that's supposed to be written to the file gets written.
Status close ()
 Closes the file.
Status getStatus () const
 Gets the status of the file.
Status read (U32 size, char *dst, U32 *bytesRead=NULL)
 Reads "size" bytes from the file, and dumps data into "dst".
Status write (U32 size, const char *src, U32 *bytesWritten=NULL)
 Writes "size" bytes into the file from the pointer "src".
bool hasCapability (Capability cap) const
 Returns whether or not this file is capable of the given function.

Protected Member Functions

Status setStatus ()
 Called after error encountered.
Status setStatus (Status status)
 Setter for the current status.

Private Member Functions

 File (const File &)
 This is here to disable the copy constructor.
Fileoperator= (const File &)
 This is here to disable assignment.

Private Attributes

voidhandle
 Pointer to the file handle.
Status currentStatus
 Current status of the file (Ok, IOError, etc.).
U32 capability
 Keeps track of file capabilities.


Member Enumeration Documentation

What is the status of our file handle?

Enumerator:
Ok  Ok!
IOError  Read or Write error.
EOS  End of Stream reached (mostly for reads).
IllegalCall  An unsupported operation used. Always accompanied by AssertWarn.
Closed  Tried to operate on a closed stream (or detached filter).
UnknownError  Catchall.

How are we accessing the file?

Enumerator:
Read  Open for read only, starting at beginning of file.
Write  Open for write only, starting at beginning of file; will blast old contents of file.
ReadWrite  Open for read-write.
WriteAppend  Write-only, starting at end of file.

Flags used to indicate what we can do to the file.

Enumerator:
FileRead 
FileWrite 


Constructor & Destructor Documentation

File::File ( const File  )  [private]

This is here to disable the copy constructor.

File::File (  ) 

Default constructor.

virtual File::~File (  )  [virtual]

Destructor.


Member Function Documentation

File& File::operator= ( const File  )  [private]

This is here to disable assignment.

Status File::open ( const char *  filename,
const AccessMode  openMode 
)

Opens a file for access using the specified AccessMode.

Returns:
The status of the file

U32 File::getPosition (  )  const

Gets the current position in the file.

This is in bytes from the beginning of the file.

Status File::setPosition ( S32  position,
bool  absolutePos = true 
)

Sets the current position in the file.

You can set either a relative or absolute position to go to in the file.

 File *foo;

 ... set up file ...

 // Go to byte 32 in the file...
 foo->setPosition(32);

 // Now skip back 20 bytes...
 foo->setPosition(-20, false);

 // And forward 17...
 foo->setPosition(17, false);

Returns:
The status of the file

U32 File::getSize (  )  const

Returns the size of the file.

Status File::flush (  ) 

Make sure everything that's supposed to be written to the file gets written.

Returns:
The status of the file.

Status File::close (  ) 

Closes the file.

Returns:
The status of the file.

Status File::getStatus (  )  const

Gets the status of the file.

Status File::read ( U32  size,
char *  dst,
U32 bytesRead = NULL 
)

Reads "size" bytes from the file, and dumps data into "dst".

The number of actual bytes read is returned in bytesRead

Returns:
The status of the file

Status File::write ( U32  size,
const char *  src,
U32 bytesWritten = NULL 
)

Writes "size" bytes into the file from the pointer "src".

The number of actual bytes written is returned in bytesWritten

Returns:
The status of the file

bool File::hasCapability ( Capability  cap  )  const

Returns whether or not this file is capable of the given function.

Status File::setStatus (  )  [protected]

Called after error encountered.

Status File::setStatus ( Status  status  )  [protected]

Setter for the current status.


Field Documentation

void* File::handle [private]

Pointer to the file handle.

Current status of the file (Ok, IOError, etc.).

U32 File::capability [private]

Keeps track of file capabilities.




All Rights Reserved GarageGames.com, Inc. 1999-2005
Auto-magically Generated with Doxygen