File
Public Types
AccessMode { Read = 0 Write = 1 ReadWrite = 2 WriteAppend = 3 }
How are we accessing the file?
Capability { FileRead = BIT(0) FileWrite = BIT(1) }
Flags used to indicate what we can do to the file.
FileStatus { Ok = 0 IOError EOS IllegalCall Closed UnknownError }
What is the status of our file handle?
Private Attributes
Keeps track of file capabilities.
Current status of the file (Ok, IOError, etc.).
Private Functions
Public Functions
File()
Default constructor.
~File()
Destructor.
close()
Closes the file.
flush()
Make sure everything that's supposed to be written to the file gets written.
Gets the current position in the file.
Gets the status of the file.
bool
hasCapability(Capability cap)
Returns whether or not this file is capable of the given function.
open(const char * filename, const AccessMode openMode)
Opens a file for access using the specified AccessMode.
setPosition(S32 position, bool absolutePos)
Sets the current position in the file.
Protected Functions
Called after error encountered.
setStatus(FileStatus status)
Setter for the current status.
Detailed Description
Public Types
AccessMode
Enumerator
- Read = 0
Open for read only, starting at beginning of file.
- Write = 1
Open for write only, starting at beginning of file; will blast old contents of file.
- ReadWrite = 2
Open for read-write.
- WriteAppend = 3
Write-only, starting at end of file.
How are we accessing the file?
Capability
Enumerator
- FileRead = BIT(0)
- FileWrite = BIT(1)
Flags used to indicate what we can do to the file.
FileStatus
Enumerator
- Ok = 0
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.
What is the status of our file handle?
Private Attributes
U32 capability
Keeps track of file capabilities.
FileStatus currentStatus
Current status of the file (Ok, IOError, etc.).
void * handle
Pointer to the file handle.
Private Functions
File(const File & )
This is here to disable the copy constructor.
operator=(const File & )
This is here to disable assignment.
Public Functions
File()
Default constructor.
~File()
Destructor.
close()
Closes the file.
The status of the file.
flush()
Make sure everything that's supposed to be written to the file gets written.
The status of the file.
getHandle()
getPosition()
Gets the current position in the file.
This is in bytes from the beginning of the file.
getSize()
Returns the size of the file.
getStatus()
Gets the status of the file.
hasCapability(Capability cap)
Returns whether or not this file is capable of the given function.
open(const char * filename, const AccessMode openMode)
Opens a file for access using the specified AccessMode.
The status of the file
read(U32 size, char * dst, U32 * bytesRead)
Reads "size" bytes from the file, and dumps data into "dst".
The number of actual bytes read is returned in bytesRead
The status of the file
setPosition(S32 position, bool absolutePos)
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);
The status of the file
write(U32 size, const char * src, U32 * bytesWritten)
Writes "size" bytes into the file from the pointer "src".
The number of actual bytes written is returned in bytesWritten
The status of the file
Protected Functions
setStatus()
Called after error encountered.
setStatus(FileStatus status)
Setter for the current status.