#include <file.h>
Inherits MemoryPoolObject, and Stream.
Inherited by LocalFile, RAMFile, RAMFile, and StdFile.
Public Types | |
| enum | access { NONE = 0x00000000 , READ = 0x00000001 , WRITE = 0x00000002 , APPEND = 0x00000004 , CREATE = 0x00000008 , TRUNCATE = 0x00000010 , TEXT = 0x00000020 , BINARY = 0x00000040 , READWRITE = (READ | WRITE) , ONLYNEW = 0x00000080 , STREAMING = 0x00000100 , NONE = 0x00000000 , READ = 0x00000001 , WRITE = 0x00000002 , APPEND = 0x00000004 , CREATE = 0x00000008 , TRUNCATE = 0x00000010 , TEXT = 0x00000020 , BINARY = 0x00000040 , READWRITE = (READ | WRITE) , NEW = 0x00000080 } |
| enum | seekMode { START , CURRENT , END , START , CURRENT , END } |
| enum | access { NONE = 0x00000000 , READ = 0x00000001 , WRITE = 0x00000002 , APPEND = 0x00000004 , CREATE = 0x00000008 , TRUNCATE = 0x00000010 , TEXT = 0x00000020 , BINARY = 0x00000040 , READWRITE = (READ | WRITE) , ONLYNEW = 0x00000080 , STREAMING = 0x00000100 , NONE = 0x00000000 , READ = 0x00000001 , WRITE = 0x00000002 , APPEND = 0x00000004 , CREATE = 0x00000008 , TRUNCATE = 0x00000010 , TEXT = 0x00000020 , BINARY = 0x00000040 , READWRITE = (READ | WRITE) , NEW = 0x00000080 } |
| enum | seekMode { START , CURRENT , END , START , CURRENT , END } |
| enum | EFileError { FileError_None = 0 , FileError_FNF , FileError_Access , FileError_Open , FileError_Read , FileError_Write , FileError_Seek , FileError_Nomem , FileError_Fault } |
Public Types inherited from Stream | |
| enum | EStreamFrom { FromStart = 0 , FromMarker , FromEnd } |
Public Member Functions | |
| Bool | eof () |
| virtual Bool | open (const Char *filename, Int access=0) |
| Open a file for access. | |
| virtual void | close (void) |
| Close the file !!! File object no longer valid after this call !!! | |
| virtual Int | read (void *buffer, Int bytes) |
| virtual Int | write (const void *buffer, Int bytes) |
| virtual Int | seek (Int bytes, seekMode mode=CURRENT) |
| virtual void | nextLine (Char *buf=NULL, Int bufSize=0)=0 |
| reads until it reaches a new-line character | |
| virtual Bool | scanInt (Int &newInt)=0 |
| read an integer from the current file position. | |
| virtual Bool | scanReal (Real &newReal)=0 |
| read a real number from the current file position. | |
| virtual Bool | scanString (AsciiString &newString)=0 |
| read a string from the current file position. | |
| virtual Bool | print (const Char *format,...) |
| Prints formated string to text file. | |
| virtual Int | size (void) |
| Returns the size of the file. | |
| virtual Int | position (void) |
| Returns the current read/write position. | |
| void | setName (const char *name) |
| Set the name of the file. | |
| const char * | getName (void) const |
| Returns a pointer to the name of the file. | |
| Int | getAccess (void) const |
| Returns file's access flags. | |
| void | deleteOnClose (void) |
| Causes the File object to delete itself when it closes. | |
| virtual char * | readEntireAndClose ()=0 |
| virtual File * | convertToRAMFile ()=0 |
| virtual Bool | open (const Char *filename, Int access=0) |
| Open a file for access. | |
| virtual void | close (void) |
| Close the file !!! File object no longer valid after this call !!! | |
| virtual Int | read (void *buffer, Int bytes) |
| virtual Int | write (void *buffer, Int bytes) |
| virtual Int | seek (Int bytes, seekMode mode=CURRENT) |
| virtual Bool | printf (const Char *format,...) |
| Prints formated string to text file. | |
| virtual Int | size (void) |
| Returns the size of the file. | |
| virtual Int | position (void) |
| Returns the current read/write position. | |
| void | setName (const Char *name) |
| Set the name of the file. | |
| Char * | getName (void) |
| Returns a pointer to the name of the file. | |
| Bool | getName (Char *buffer, Int max) |
| Copies the name of the file to the buffer. | |
| Int | getAccess (void) |
| Returns file's access flags. | |
| void | deleteOnClose (void) |
| Causes the File object to delete itself when it closes. | |
| File () | |
| Default constructor - Create an unassociated File. | |
| File (const Char *name, ERights rights=Rights_ReadOnly) | |
| Name constructor - Create a File with an associated name. | |
| File (const UString &name, ERights rights=Rights_ReadOnly) | |
| virtual | ~File () |
| Destructor. | |
| const UString & | GetName (void) const |
| Retrieve name of file. | |
| virtual void | SetName (const UString &name) |
| Associate a name to the file. | |
| virtual ERights | GetRights (void) const |
| Retrieve file access rights. | |
| virtual void | SetRights (ERights rights) |
| Set file access rights. | |
| virtual bool | IsAvailable (bool force=false) |
| Check if the file is available. | |
| virtual bool | IsOpen (void) const |
| Check if te file is open. | |
| virtual EFileError | Open (ERights rights) |
| Open the file for access. | |
| virtual EFileError | Open (const UString &name, ERights rights) |
| Open the file with the associated name for access. | |
| virtual void | Close (void) |
| Close the file. | |
| virtual EFileError | Create (void) |
| Create a new file. | |
| virtual EFileError | Delete (void) |
| Delete an existing file. | |
| virtual EFileError | Load (void *&outBuffer, UInt32 &outSize) |
| Load the file into memory. | |
| virtual EFileError | Save (const void *buffer, UInt32 size) |
| Write file data. | |
| virtual bool | OnFileError (EFileError error, bool canRetry) |
| Error handling hook. | |
| virtual UInt32 | GetLength (void) |
| Get the length of the file. | |
| virtual void | SetLength (UInt32 length) |
| Set the length of the file. | |
| virtual UInt32 | GetMarker (void) |
| Get file position marker. | |
| virtual void | SetMarker (Int32 offset, EStreamFrom from) |
| Set file position marker. | |
| virtual bool | AtEnd (void) |
| End of file test. | |
| virtual UInt32 | GetBytes (void *ptr, UInt32 bytes) |
| Read bytes from the file. | |
| virtual UInt32 | PutBytes (const void *ptr, UInt32 bytes) |
| Write bytes to the file. | |
| virtual UInt32 | PeekBytes (void *ptr, UInt32 bytes) |
| Read bytes from the file without marker adjustment. | |
| virtual void | Flush (void) |
| Flush the stream. | |
Public Member Functions inherited from MemoryPoolObject | |
| void | deleteInstance () |
Protected Member Functions | |
| File () | |
| This class can only used as a base class. | |
| File () | |
| This class can only used as a base class. | |
| virtual | ~File () |
Protected Member Functions inherited from MemoryPoolObject | |
| virtual | ~MemoryPoolObject () |
| void * | operator new (size_t s) |
| void | operator delete (void *p) |
| virtual MemoryPool * | getObjectMemoryPool ()=0 |
Protected Attributes | |
| AsciiString | m_nameStr |
| Stores file name. | |
| Int | m_access |
| How the file was opened. | |
| Bool | m_open |
| Has the file been opened. | |
| Bool | m_deleteOnClose |
| delete File object on close() | |
| Char | m_name [IO_MAX_PATH+1] |
| Stores file name. | |
Friends | |
| class | FileSystem |
File is an interface class for basic file operations.
All code should use the File class and not its derivatives, unless absolutely necessary. Also FS::Open should be used to create File objects and open files.
| enum File::access |
| enum File::access |
Definition at line 80 of file WSYS_file.h.
| enum File::EFileError |
| enum File::seekMode |
| enum File::seekMode |
Definition at line 94 of file WSYS_file.h.
|
protected |
|
protected |
This class can only used as a base class.
| File::File | ( | ) |
Default constructor - Create an unassociated File.
| File::File | ( | const Char * | name, |
| ERights | rights = Rights_ReadOnly ) |
| File::File | ( | const UString & | name, |
| ERights | rights = Rights_ReadOnly ) |
|
virtual |
Destructor.
|
virtual |
|
virtual |
Close the file !!! File object no longer valid after this call !!!
Must call File::close() for each successful File::open() call.
Reimplemented in LocalFile, RAMFile, RAMFile, StdFile, and StreamingArchiveFile.
|
virtual |
|
pure virtual |
Implemented in LocalFile, RAMFile, and StreamingArchiveFile.
|
virtual |
|
virtual |
|
inline |
| void File::deleteOnClose | ( | void | ) |
Causes the File object to delete itself when it closes.
|
virtual |
|
inline |
Returns file's access flags.
Definition at line 158 of file WSYS_file.h.
|
inline |
|
virtual |
|
virtual |
| const UString & File::GetName | ( | void | ) | const |
Copies the name of the file to the buffer.
Definition at line 229 of file WSYS_File.cpp.
|
inline |
Returns a pointer to the name of the file.
Definition at line 157 of file WSYS_file.h.
|
inline |
|
virtual |
|
virtual |
|
virtual |
reads until it reaches a new-line character
Implemented in LocalFile, RAMFile, and StreamingArchiveFile.
|
virtual |
|
virtual |
|
virtual |
Open a file for access.
Any derived open() members must first call File::open. If File::open succeeds but the derived class's open failes then make sure to call File::close() before returning.
Reimplemented in LocalFile, RAMFile, RAMFile, StdFile, and StreamingArchiveFile.
Open a file for access.
Reimplemented in LocalFile, RAMFile, RAMFile, StdFile, and StreamingArchiveFile.
|
virtual |
|
virtual |
Returns the current read/write position.
Prints formated string to text file.
Definition at line 244 of file WSYS_File.cpp.
Read the specified number of bytes from the file in to the memory pointed at by buffer. Returns the number of bytes read. Returns -1 if an error occured.
Reimplemented in LocalFile, RAMFile, RAMFile, StdFile, and StreamingArchiveFile.
Read the specified number of bytes from the file in to the memory pointed at by buffer. Returns the number of bytes read. Returns -1 if an error occured.
Reimplemented in LocalFile, RAMFile, RAMFile, StdFile, and StreamingArchiveFile.
|
pure virtual |
Allocate a buffer large enough to hold entire file, read the entire file into the buffer, then close the file. the buffer is owned by the caller, who is responsible for freeing is (via delete[]). This is a Good Thing to use because it minimizes memory copies for BIG files.
Implemented in LocalFile, RAMFile, and StreamingArchiveFile.
|
virtual |
read an integer from the current file position.
Implemented in LocalFile, RAMFile, and StreamingArchiveFile.
read a real number from the current file position.
Implemented in LocalFile, RAMFile, and StreamingArchiveFile.
|
pure virtual |
read a string from the current file position.
Implemented in LocalFile, RAMFile, and StreamingArchiveFile.
Sets the file position of the next read/write operation. Returns the new file position as the number of bytes from the start of the file. Returns -1 if an error occured.
seekMode determines how the seek is done:
START : means seek to the specified number of bytes from the start of the file CURRENT: means seek the specified the number of bytes from the current file position END: means seek the specified number of bytes back from the end of the file
Reimplemented in LocalFile, RAMFile, RAMFile, StdFile, and StreamingArchiveFile.
Sets the file position of the next read/write operation. Returns the new file position as the number of bytes from the start of the file. Returns -1 if an error occured.
seekMode determines how the seek is done:
START : means seek to the specified number of bytes from the start of the file CURRENT: means seek the specified the number of bytes from the current file position END: means seek the specified number of bytes back from the end of the file
Reimplemented in LocalFile, RAMFile, RAMFile, StdFile, and StreamingArchiveFile.
|
virtual |
|
virtual |
|
virtual |
| void File::setName | ( | const Char * | name | ) |
Set the name of the file.
|
inline |
|
virtual |
|
virtual |
Returns the size of the file.
Default implementation of File::size. Derived classes can optimize this member function.
|
virtual |
Returns the size of the file.
Write the specified number of bytes from the
memory pointed at by buffer to the file. Returns the number of bytes written. Returns -1 if an error occured.
Reimplemented in LocalFile, RAMFile, and StreamingArchiveFile.
|
friend |
Definition at line 76 of file WSYS_file.h.
|
protected |
|
protected |
Stores file name.
Definition at line 103 of file WSYS_file.h.
|
protected |