Torque2D Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Protected Member Functions | List of all members
File Class Reference

`#include <platformFileIO.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. More...
virtual | ~File ()
| Destructor. More...
Status | open (const char *filename, const AccessMode openMode)
U32 | getPosition () const
Status | setPosition (S32 position, bool absolutePos=true)
U32 | getSize () const
| Returns the size of the file. More...
Status | flush ()
Status | close ()
Status | getStatus () const
| Gets the status of the file. More...
Status | read (U32 size, char *dst, U32 *bytesRead=NULL)
Status | write (U32 size, const char *src, U32 *bytesWritten=NULL)
bool | hasCapability (Capability cap) const
| Returns whether or not this file is capable of the given function. More...

## Protected Member Functions
Status | setStatus ()
| Called after error encountered. More...
Status | setStatus (Status status)
| Setter for the current status. More...

## Member Enumeration Documentation

enum AccessMode

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.

enum Capability

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

Enumerator
FileRead |
FileWrite |

enum Status

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.

## Constructor & Destructor Documentation

File | ( |  | ) |

Default constructor.

~File | ( |  | ) |
| virtual

Destructor.

## Member Function Documentation

File::Status close | ( |  | ) |

Closes the file

Returns
  The status of the file.

File::Status flush | ( |  | ) |

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

Returns
  The status of the file.

U32 getPosition | ( |  | ) | const

Gets the current position in the file

This is in bytes from the beginning of the file.

U32 getSize | ( |  | ) | const

Returns the size of the file.

File::Status getStatus | ( |  | ) | const

Gets the status of the file.

bool hasCapability | ( | Capability | cap | ) | const

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

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

Opens a file for access using the specified AccessMode

Returns
  The status of the file

File::Status 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

File::Status 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

File::Status setStatus | ( |  | ) |
| protected

Called after error encountered.

File::Status setStatus | ( | File::Status | status | ) |
| protected

Setter for the current status.

File::Status 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

The documentation for this class was generated from the following files:

- platform/platformFileIO.h
- platformAndroid/AndroidFileio.cpp
- platformEmscripten/EmscriptenFileio.cpp