class RED::FileSystemTools
Standard file system API. More...
#include <REDFileSystemTools.h>
Inherits: Object.
Public static functions:
static RED_RC | CloseFile ( FILE * iHandler ) |
static RED_RC | FileExists ( const RED::String & iResourcePath, int iAccessMode ) |
static RED_RC | FilePosition ( RED::uint64 & oPosition, FILE * iFileHandler ) |
static RED_RC | FileSeek ( FILE * iFileHandler, RED::uint64 iPosition, unsigned int iBase ) |
static RED_RC | FileSize ( RED::uint64 & oSize, FILE * iFileHandler ) |
static RED_CLOSEFILE_FUNCTION | GetCloseFunction ( ) |
static RED_OPENFILE_FUNCTION | GetOpenFunction ( ) |
static RED_READFILE_FUNCTION | GetReadFunction ( ) |
static RED_SEEKFILE_FUNCTION | GetSeekFunction ( ) |
static RED::String | GetWorkingDirectory ( ) |
static RED_WRITEFILE_FUNCTION | GetWriteFunction ( ) |
static RED_RC | OpenFile ( FILE *& oHandler, const RED::String & iFilename, const RED::String & iMode ) |
static RED_RC | ReadFromFile ( unsigned char * oBuffer, RED::uint64 & oRead, FILE * iHandler, RED::uint64 iOffset, RED::uint64 iLength ) |
static RED_RC | ReadFromFile ( unsigned char * oBuffer, RED::uint64 & oRead, FILE * iHandler, RED::uint64 iLength ) |
static RED_RC | ReadLineFromFile ( unsigned char * oBuffer, RED::uint64 & oRead, bool & oEnd, FILE * iHandler, RED::uint64 iLength ) |
static void | SetCloseFunction ( RED_CLOSEFILE_FUNCTION iCloseCB ) |
static void | SetOpenFunction ( RED_OPENFILE_FUNCTION iOpenCB ) |
static void | SetReadFunction ( RED_READFILE_FUNCTION iReadCB ) |
static void | SetSeekFunction ( RED_SEEKFILE_FUNCTION iSeekCB ) |
static void | SetWorkingDirectory ( const RED::String & iDefaultDir ) |
static void | SetWriteFunction ( RED_WRITEFILE_FUNCTION iWriteCB ) |
static RED_RC | WriteToFile ( FILE * iHandler, const unsigned char * iBuffer, RED::uint64 iLength ) |
static RED_RC | WriteToFile ( FILE * iHandler, const RED::String & iString ) |
Public typedefs:
typedef bool(* | RED_CLOSEFILE_FUNCTION )(FILE *iFileHandle) |
typedef FILE *(* | RED_OPENFILE_FUNCTION )(const RED::String &iFileName, const RED::String &iMode) |
typedef bool(* | RED_READFILE_FUNCTION )(FILE *iFileHandle, unsigned char *oData, RED::uint64 iDataSize) |
typedef bool(* | RED_SEEKFILE_FUNCTION )(RED::uint64 nOffset) |
typedef bool(* | RED_WRITEFILE_FUNCTION )(FILE *iFileHandle, const unsigned char *oData, RED::uint64 iDataSize) |
Protected static variables:
static RED_CLOSEFILE_FUNCTION | _close |
static RED_OPENFILE_FUNCTION | _open |
static RED_READFILE_FUNCTION | _read |
static RED_SEEKFILE_FUNCTION | _seek |
static RED_WRITEFILE_FUNCTION | _write |
Detailed description:
Standard file system API.
The RED::FileSystemTools class defines the I/O methods used to read, write and parse files. By default, the RED::FileSystemTools class uses the standard C I/O routines (fopen, fclose, ...). All methods can be overloaded.
Functions documentation
public static RED_RC RED::FileSystemTools::CloseFile | ( | FILE * | iHandler | ) |
Closes a file specified by it's handler.
This routine closes a file that was opened using the REDOpenFile function preciously. The file handler must be provided to correctly close the file.
Parameters:
iHandler: | Handler to the file that needs to be closed. |
Returns:
public static RED_RC RED::FileSystemTools::FileExists | ( | const RED::String & | iResourcePath, |
int | iAccessMode | ||
) |
Checks the existence of a file or directory, with permissions.
This method checks that the file or folder resource identified by iResourcePath exists, and can be accessed provided the given resource permission in iAccessMode.
Parameters:
iResourcePath: | RED::String path or name of the searched resource. |
iAccessMode: | Requested permission. Only one permission flag should be provided: RED_FILE_EXISTS, RED_FILE_READ_OK or RED_FILE_WRITE_OK. |
Returns:
RED_BAD_PARAM if invalid parameters were provided to the routine,
RED_ACCESS_DENIED if the resource exists, but can't be accessed with the requested iAccessMode,
RED_FILE_NOT_FOUND if the resource does not exists,
RED_FAIL otherwise.
public static RED_RC RED::FileSystemTools::FilePosition | ( | RED::uint64 & | oPosition, |
FILE * | iFileHandler | ||
) |
Gets the current position inside the given file.
This method returns the same result than the ftell C function.
Parameters:
oPosition: | Reference to the returned file position. |
iFileHandler: | Handler to the file. |
Returns:
RED_BAD_PARAM if invalid parameters were provided to the routine,
RED_FAIL otherwise.
public static RED_RC RED::FileSystemTools::FileSeek | ( | FILE * | iFileHandler, |
RED::uint64 | iPosition, | ||
unsigned int | iBase | ||
) |
Seeks into a file at a given position.
This method works exactly as the fseek C function does.
Parameters:
iFileHandler: | Handler to the file. |
iPosition: | New position inside the file. |
iBase: | Base in which the iPosition is expressed. |
Returns:
RED_BAD_PARAM if invalid parameters were provided to the routine,
RED_FAIL otherwise.
public static RED_RC RED::FileSystemTools::FileSize | ( | RED::uint64 & | oSize, |
FILE * | iFileHandler | ||
) |
Returns the size of the input file.
Parameters:
oSize: | Reference to the returned file size. |
iFileHandler: | Handler to the file. |
Returns:
RED_BAD_PARAM if invalid parameters were provided to the routine,
RED_FAIL otherwise.
public static RED_CLOSEFILE_FUNCTION RED::FileSystemTools::GetCloseFunction | ( | ) |
Gets the custom close function.
Returns:
public static RED_OPENFILE_FUNCTION RED::FileSystemTools::GetOpenFunction | ( | ) |
Gets the custom open function.
Returns:
public static RED_READFILE_FUNCTION RED::FileSystemTools::GetReadFunction | ( | ) |
Gets the custom read function.
Returns:
public static RED_SEEKFILE_FUNCTION RED::FileSystemTools::GetSeekFunction | ( | ) |
Gets the custom seek function.
Returns:
public static RED::String RED::FileSystemTools::GetWorkingDirectory | ( | ) |
Gets the current working directory.
Returns:
public static RED_WRITEFILE_FUNCTION RED::FileSystemTools::GetWriteFunction | ( | ) |
Gets the custom write function.
Returns:
public static RED_RC RED::FileSystemTools::OpenFile | ( | FILE *& | oHandler, |
const RED::String & | iFilename, | ||
const RED::String & | iMode | ||
) |
Opens the specified file with an access mode.
This routine opens a file with the requested access mode.
The result of this routine is a file handler returned in oFileHandler, with a return code set to RED_OK. If the routine fails to open the file with the requested permissions, oFileHandler is set to NULL, and the return code is set to the corresponding found error.
This routine may be used to create a new file, when the "w" (write) mode is set.
Parameters:
oHandler: | FILE type handler returned by the routine for further usage. |
iFilename: | Access path to the file to be loaded. May be an absolute path or a relative path. |
iMode: | Standard ANSI modes supported by the fopen routine: usually a combination of "r","w","a", for respectively read, write and append modes, plus possible modifiers "t" for text and "b" for binary file write. Refer to the ANSI specifications for the list of all possible modes. Note that the mode is not specified as an unicode string, but as a basic (char *) string. |
Returns:
public static RED_RC RED::FileSystemTools::ReadFromFile | ( | unsigned char * | oBuffer, |
RED::uint64 & | oRead, | ||
FILE * | iHandler, | ||
RED::uint64 | iOffset, | ||
RED::uint64 | iLength | ||
) |
Reads a string buffer from a file starting at a position.
This function tries to read a chunk of data of iLength from the file identified by ioHandler, starting at iOffset bytes from the beginning of the file. oRead is set to the really read number of bytes, that have been stored in ioBuffer. ioBuffer must have been sufficiently allocated before the call.
Parameters:
oBuffer: | Target buffer with the read contents. |
oRead: | Number of effectively read bytes. Can be returned between 0 and iLength depending on what could be read. |
iHandler: | Handler to the read file. |
iOffset: | Offset in bytes from the beginning of the file to start reading from. the value must be positive. |
iLength: | Requested byte length to read. If zero, the method replaces the current reading position to iOffset. |
Returns:
RED_BAD_PARAM if the method has received an invalid parameter.
public static RED_RC RED::FileSystemTools::ReadFromFile | ( | unsigned char * | oBuffer, |
RED::uint64 & | oRead, | ||
FILE * | iHandler, | ||
RED::uint64 | iLength | ||
) |
Reads a string buffer from file.
This function tries to read a chunk of data of iLength from the file identified by ioHandler. oRead is set to the really read number of bytes, that have been stored in ioBuffer. ioBuffer must have been sufficiently allocated before the call.
Parameters:
oBuffer: | Target buffer with the read contents. |
oRead: | Number of effectively read bytes. Can be returned between 0 and iLength depending on what could be read. |
iHandler: | Handler to the read file. |
iLength: | Requested byte length to read. |
Returns:
RED_BAD_PARAM if the method has received an invalid parameter.
public static RED_RC RED::FileSystemTools::ReadLineFromFile | ( | unsigned char * | oBuffer, |
RED::uint64 & | oRead, | ||
bool & | oEnd, | ||
FILE * | iHandler, | ||
RED::uint64 | iLength | ||
) |
Reads a single line from a text file.
This function reads chars from a text file until either the end of file is reached or the end of the current text line is reached or the buffer size specified by iLength is reached.
Parameters:
oBuffer: | Target buffer with the read contents. |
oRead: | Number of effectively read bytes. Does not include the line ending character. |
oEnd: | Returned set to true if end of file has been reached. |
iHandler: | Handler to the read file. |
iLength: | Size of the target buffer. Must be greater than 0. |
Returns:
RED_BAD_PARAM if the method has received an invalid parameter,
RED_FILE_DATA_ERROR when the reading could not be completed for the requested bytes count.
public static void RED::FileSystemTools::SetCloseFunction | ( | RED_CLOSEFILE_FUNCTION | iCloseCB | ) |
Sets a custom close function.
The custom close function will be called in place of the standard fclose C function.
If set to NULL, the REDFileSystemTools will use the default standard C function.
Parameters:
iCloseCB: | new close function to use. |
public static void RED::FileSystemTools::SetOpenFunction | ( | RED_OPENFILE_FUNCTION | iOpenCB | ) |
Sets a custom open function.
The custom open function will be called in place of the standard fopen C function.
If set to NULL, the REDFileSystemTools will use the default standard C function.
Parameters:
iOpenCB: | new open function to use. |
public static void RED::FileSystemTools::SetReadFunction | ( | RED_READFILE_FUNCTION | iReadCB | ) |
Sets a custom read function.
The custom open function will be called in place of the standard fread C function.
If set to NULL, the REDFileSystemTools will use the default standard C function.
Parameters:
iReadCB: | new read function to use. |
public static void RED::FileSystemTools::SetSeekFunction | ( | RED_SEEKFILE_FUNCTION | iSeekCB | ) |
Sets a custom seek function.
The custom open function will be called in place of the standard fseek C function.
If set to NULL, the REDFileSystemTools will use the default standard C function.
Parameters:
iSeekCB: | new seek function to use. |
public static void RED::FileSystemTools::SetWorkingDirectory | ( | const RED::String & | iDefaultDir | ) |
Sets the current working directory.
Parameters:
iDefaultDir: | String containing the path to the working directory. |
public static void RED::FileSystemTools::SetWriteFunction | ( | RED_WRITEFILE_FUNCTION | iWriteCB | ) |
Sets a custom write function.
The custom open function will be called in place of the standard fwrite C function.
If set to NULL, the REDFileSystemTools will use the default standard C function.
Parameters:
iWriteCB: | new write function to use. |
public static RED_RC RED::FileSystemTools::WriteToFile | ( | FILE * | iHandler, |
const unsigned char * | iBuffer, | ||
RED::uint64 | iLength | ||
) |
Writes a string buffer in a file.
This function tries to write the provided iBuffer in the file identified by iHandler. iLength bytes are written to the file.
Parameters:
iHandler: | Handler to the written file. |
iBuffer: | String buffer written down to the file. |
iLength: | Number of bytes to write from iBuffer. |
Returns:
public static RED_RC RED::FileSystemTools::WriteToFile | ( | FILE * | iHandler, |
const RED::String & | iString | ||
) |
Writes a string buffer in a file.
This function tries to write the provided iString in the file identified by iHandler.
Parameters:
iHandler: | Handler to the written file. |
iString: | String written down to the file. |
Returns:
Variables documentation
Custom file close function
Custom file open function
Custom file read function
Custom file seek function
Custom file write function
Types documentation
RED_CLOSEFILE_FUNCTION: Type definition for the file close callback.
RED_OPENFILE_FUNCTION: Type definition for the file open callback.
RED_READFILE_FUNCTION: Type definition for the file read callback.
RED_SEEKFILE_FUNCTION: Type definition for the file seek callback.
RED_WRITEFILE_FUNCTION: Type definition for the file write callback.