Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
RAMFile Class Reference

#include <RAMFile.h>

Inherits File, and File.

Inherited by StreamingArchiveFile.

Public Member Functions

 RAMFile ()
 
virtual Bool open (const Char *filename, Int access=0)
 Open a file for access.
 
virtual void close (void)
 Close the file.
 
virtual Int read (void *buffer, Int bytes)
 Read the specified number of bytes in to buffer: See File::read.
 
virtual Int write (const void *buffer, Int bytes)
 Write the specified number of bytes from the buffer: See File::write.
 
virtual Int seek (Int new_pos, seekMode mode=CURRENT)
 Set file position: See File::seek.
 
virtual void nextLine (Char *buf=NULL, Int bufSize=0)
 moves current position to after the next new-line
 
virtual Bool scanInt (Int &newInt)
 return what gets read as an integer from the current memory position.
 
virtual Bool scanReal (Real &newReal)
 return what gets read as a float from the current memory position.
 
virtual Bool scanString (AsciiString &newString)
 return what gets read as a string from the current memory position.
 
virtual Bool open (File *file)
 Open file for fast RAM access.
 
virtual Bool openFromArchive (File *archiveFile, const AsciiString &filename, Int offset, Int size)
 copy file data from the given file at the given offset for the given size.
 
virtual Bool copyDataToFile (File *localFile)
 write the contents of the RAM file to the given local file. This could be REALLY slow.
 
virtual char * readEntireAndClose ()
 
virtual FileconvertToRAMFile ()
 
 RAMFile ()
 
virtual ~RAMFile ()
 
virtual Bool open (const Char *filename, Int access=0)
 Open a file for access.
 
virtual void close (void)
 Close the file.
 
virtual Int read (void *buffer, Int bytes)
 Read the specified number of bytes in to buffer: See File::read.
 
virtual Int write (void *buffer, Int bytes)
 Write the specified number of bytes from the buffer: See File::write.
 
virtual Int seek (Int new_pos, seekMode mode=CURRENT)
 Set file position: See File::seek.
 
Bool open (File *file)
 Open file for fast RAM access.
 
- Public Member Functions inherited from File
Bool eof ()
 
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 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.
 
ChargetName (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 UStringGetName (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 Attributes

Charm_data
 File data in memory.
 
Int m_pos
 current read position
 
Int m_size
 size of file in memory
 
- Protected Attributes inherited from File
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.
 

Additional Inherited Members

- Public Types inherited from File
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 }
 
- Protected Member Functions inherited from File
 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 MemoryPoolgetObjectMemoryPool ()=0
 

Detailed Description

File abstraction for standard C file operators: open, close, lseek, read, write

Definition at line 75 of file RAMFile.h.

Constructor & Destructor Documentation

◆ RAMFile() [1/2]

RAMFile::RAMFile ( )

Definition at line 106 of file RAMFile.cpp.

◆ RAMFile() [2/2]

RAMFile::RAMFile ( )

◆ ~RAMFile()

RAMFile::~RAMFile ( )
virtual

Definition at line 127 of file RAMFile.cpp.

Member Function Documentation

◆ close() [1/2]

void RAMFile::close ( void )
virtual

Close the file.

Closes the current file if it is open. Must call RAMFile::close() for each successful RAMFile::open() call.

Reimplemented from File.

Reimplemented in StreamingArchiveFile.

Definition at line 248 of file RAMFile.cpp.

◆ close() [2/2]

virtual void RAMFile::close ( void )
virtual

Close the file.

Reimplemented from File.

Reimplemented in StreamingArchiveFile.

◆ convertToRAMFile()

File * RAMFile::convertToRAMFile ( )
virtual

Implements File.

Reimplemented in StreamingArchiveFile.

Definition at line 478 of file RAMFile.cpp.

◆ copyDataToFile()

Bool RAMFile::copyDataToFile ( File * localFile)
virtual

write the contents of the RAM file to the given local file. This could be REALLY slow.

Reimplemented in StreamingArchiveFile.

Definition at line 462 of file RAMFile.cpp.

◆ nextLine()

void RAMFile::nextLine ( Char * buf = NULL,
Int bufSize = 0 )
virtual

moves current position to after the next new-line

Implements File.

Reimplemented in StreamingArchiveFile.

Definition at line 427 of file RAMFile.cpp.

◆ open() [1/4]

Bool RAMFile::open ( const Char * filename,
Int access = 0 )
virtual

Open a file for access.

This function opens a file using the standard C open() call. Access flags are mapped to the appropriate open flags. Returns true if file was opened successfully.

Reimplemented from File.

Reimplemented in StreamingArchiveFile.

Definition at line 148 of file RAMFile.cpp.

◆ open() [2/4]

virtual Bool RAMFile::open ( const Char * filename,
Int access = 0 )
virtual

Open a file for access.

Reimplemented from File.

Reimplemented in StreamingArchiveFile.

◆ open() [3/4]

Bool RAMFile::open ( File * file)
virtual

Open file for fast RAM access.

Reimplemented in StreamingArchiveFile.

Definition at line 169 of file RAMFile.cpp.

◆ open() [4/4]

Bool RAMFile::open ( File * file)

Open file for fast RAM access.

◆ openFromArchive()

Bool RAMFile::openFromArchive ( File * archiveFile,
const AsciiString & filename,
Int offset,
Int size )
virtual

copy file data from the given file at the given offset for the given size.

Reimplemented in StreamingArchiveFile.

Definition at line 210 of file RAMFile.cpp.

◆ read() [1/2]

Int RAMFile::read ( void * buffer,
Int bytes )
virtual

Read the specified number of bytes in to buffer: See File::read.

Reimplemented from File.

Reimplemented in StreamingArchiveFile.

Definition at line 263 of file RAMFile.cpp.

◆ read() [2/2]

virtual Int RAMFile::read ( void * buffer,
Int bytes )
virtual

Read the specified number of bytes in to buffer: See File::read.

Reimplemented from File.

Reimplemented in StreamingArchiveFile.

◆ readEntireAndClose()

char * RAMFile::readEntireAndClose ( )
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.

Implements File.

Reimplemented in StreamingArchiveFile.

Definition at line 493 of file RAMFile.cpp.

◆ scanInt()

Bool RAMFile::scanInt ( Int & newInt)
virtual

return what gets read as an integer from the current memory position.

Implements File.

Reimplemented in StreamingArchiveFile.

Definition at line 339 of file RAMFile.cpp.

◆ scanReal()

Bool RAMFile::scanReal ( Real & newReal)
virtual

return what gets read as a float from the current memory position.

Implements File.

Reimplemented in StreamingArchiveFile.

Definition at line 369 of file RAMFile.cpp.

◆ scanString()

Bool RAMFile::scanString ( AsciiString & newString)
virtual

return what gets read as a string from the current memory position.

Implements File.

Reimplemented in StreamingArchiveFile.

Definition at line 403 of file RAMFile.cpp.

◆ seek() [1/2]

Int RAMFile::seek ( Int new_pos,
seekMode mode = CURRENT )
virtual

Set file position: See File::seek.

Reimplemented from File.

Reimplemented in StreamingArchiveFile.

Definition at line 300 of file RAMFile.cpp.

◆ seek() [2/2]

virtual Int RAMFile::seek ( Int new_pos,
seekMode mode = CURRENT )
virtual

Set file position: See File::seek.

Reimplemented from File.

Reimplemented in StreamingArchiveFile.

◆ write() [1/2]

Int RAMFile::write ( const void * buffer,
Int bytes )
virtual

Write the specified number of bytes from the buffer: See File::write.

Reimplemented from File.

Reimplemented in StreamingArchiveFile.

Definition at line 291 of file RAMFile.cpp.

◆ write() [2/2]

Int RAMFile::write ( void * buffer,
Int bytes )
virtual

Write the specified number of bytes from the buffer: See File::write.

Reimplemented from File.

Definition at line 246 of file WSYS_RAMFile.cpp.

Member Data Documentation

◆ m_data

Char * RAMFile::m_data
protected

File data in memory.

Definition at line 80 of file RAMFile.h.

◆ m_pos

Int RAMFile::m_pos
protected

current read position

Definition at line 81 of file RAMFile.h.

◆ m_size

Int RAMFile::m_size
protected

size of file in memory

Definition at line 82 of file RAMFile.h.


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