class RED::FileSystemTools

Standard file system API. More...

#include <REDFileSystemTools.h>

Inherits: Object.

Public static functions:

static RED_RCCloseFile ( FILE * iHandler )
static RED_RCFileExists ( const RED::String & iResourcePath, int iAccessMode )
static RED_RCFilePosition ( RED::uint64 & oPosition, FILE * iFileHandler )
static RED_RCFileSeek ( FILE * iFileHandler, RED::uint64 iPosition, unsigned int iBase )
static RED_RCFileSize ( RED::uint64 & oSize, FILE * iFileHandler )
static RED_CLOSEFILE_FUNCTIONGetCloseFunction ( )
static RED_OPENFILE_FUNCTIONGetOpenFunction ( )
static RED_READFILE_FUNCTIONGetReadFunction ( )
static RED_SEEKFILE_FUNCTIONGetSeekFunction ( )
static RED::StringGetWorkingDirectory ( )
static RED_WRITEFILE_FUNCTIONGetWriteFunction ( )
static RED_RCOpenFile ( FILE *& oHandler, const RED::String & iFilename, const RED::String & iMode )
static RED_RCReadFromFile ( unsigned char * oBuffer, RED::uint64 & oRead, FILE * iHandler, RED::uint64 iOffset, RED::uint64 iLength )
static RED_RCReadFromFile ( unsigned char * oBuffer, RED::uint64 & oRead, FILE * iHandler, RED::uint64 iLength )
static RED_RCReadLineFromFile ( unsigned char * oBuffer, RED::uint64 & oRead, bool & oEnd, FILE * iHandler, RED::uint64 iLength )
static voidSetCloseFunction ( RED_CLOSEFILE_FUNCTION iCloseCB )
static voidSetOpenFunction ( RED_OPENFILE_FUNCTION iOpenCB )
static voidSetReadFunction ( RED_READFILE_FUNCTION iReadCB )
static voidSetSeekFunction ( RED_SEEKFILE_FUNCTION iSeekCB )
static voidSetWorkingDirectory ( const RED::String & iDefaultDir )
static voidSetWriteFunction ( RED_WRITEFILE_FUNCTION iWriteCB )
static RED_RCWriteToFile ( FILE * iHandler, const unsigned char * iBuffer, RED::uint64 iLength )
static RED_RCWriteToFile ( 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:

RED_OK when the file could be successfully closed, RED_FAIL otherwise, most likely meaning that an invalid handler was provided to the call.
public static RED_RC RED::FileSystemTools::FileExists(const RED::String &iResourcePath,
intiAccessMode
)

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_OK when the resource exists and can be accessed with the requested permissions,
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_OK on success,
RED_BAD_PARAM if invalid parameters were provided to the routine,
RED_FAIL otherwise.
public static RED_RC RED::FileSystemTools::FileSeek(FILE *iFileHandler,
RED::uint64iPosition,
unsigned intiBase
)

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_OK on success,
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_OK when the resource exists and can be accessed with the requested permissions,
RED_BAD_PARAM if invalid parameters were provided to the routine,
RED_FAIL otherwise.

Gets the custom close function.

Returns:

A pointer to the custom close function if it exists, NULL otherwise.

Gets the custom open function.

Returns:

A pointer to the custom open function if it exists, NULL otherwise.

Gets the custom read function.

Returns:

A pointer to the custom read function if it exists, NULL otherwise.

Gets the custom seek function.

Returns:

A pointer to the custom seek function if it exists, NULL otherwise.

Gets the current working directory.

Returns:

The path of the current directory.

Gets the custom write function.

Returns:

A pointer to the custom write function if it exists, NULL otherwise.
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:

RED_OK when the file was successfully accessed from the file system, RED_BAD_PARAM if invalid parameters were provided to the routine, RED_ACCESS_DENIED when the file could not be accessed with the requested rights, RED_FILE_NOT_FOUND when the file could not be found using iFilename, or RED_FAIL when an unexpected error occurred.
public static RED_RC RED::FileSystemTools::ReadFromFile(unsigned char *oBuffer,
RED::uint64 &oRead,
FILE *iHandler,
RED::uint64iOffset,
RED::uint64iLength
)

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.
iHandler:Handler to the read file.
iOffset:Offset from the beginning of the file to start reading from. the value must be expressed in bytes.
iLength:Requested byte length to read.

Returns:

RED_OK when the requested length was read,
RED_BAD_PARAM if the method has received an invalid parameter,
RED_FILE_DATA_ERROR when the reading could not be completed for the number of requested bytes.
public static RED_RC RED::FileSystemTools::ReadFromFile(unsigned char *oBuffer,
RED::uint64 &oRead,
FILE *iHandler,
RED::uint64iLength
)

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.
iHandler:Handler to the read file.
iLength:Requested byte length to read.

Returns:

RED_OK when the requested length was read,
RED_BAD_PARAM if the method has received an invalid parameter,
RED_FILE_DATA_ERROR when the reading could not be completed for the number of requested bytes.
public static RED_RC RED::FileSystemTools::ReadLineFromFile(unsigned char *oBuffer,
RED::uint64 &oRead,
bool &oEnd,
FILE *iHandler,
RED::uint64iLength
)

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.
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_OK if the line was successfully read,
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.

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.

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.

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.

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.

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::uint64iLength
)

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:

RED_OK when the requested length was successfully written, RED_FILE_WRITE_ERROR when the writing could not be completed for the number of requested bytes, RED_BAD_PARAM if the method has received an invalid parameter.
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:

RED_OK when the requested length was successfully written, RED_FAIL when the writing could not be completed for the number of requested bytes, RED_BAD_PARAM if the method has received an invalid parameter.

Variables documentation

Custom file close function

Custom file open function

Custom file read function

Custom file seek function

Custom file write function

Types documentation

public typedef bool(* RED::FileSystemTools::RED_CLOSEFILE_FUNCTION)(FILE *iFileHandle)

RED_CLOSEFILE_FUNCTION: Type definition for the file close callback.

public typedef FILE *(* RED::FileSystemTools::RED_OPENFILE_FUNCTION)(const RED::String &iFileName, const RED::String &iMode)

RED_OPENFILE_FUNCTION: Type definition for the file open callback.

public typedef bool(* RED::FileSystemTools::RED_READFILE_FUNCTION)(FILE *iFileHandle, unsigned char *oData, RED::uint64 iDataSize)

RED_READFILE_FUNCTION: Type definition for the file read callback.

RED_SEEKFILE_FUNCTION: Type definition for the file seek callback.

public typedef bool(* RED::FileSystemTools::RED_WRITEFILE_FUNCTION)(FILE *iFileHandle, const unsigned char *oData, RED::uint64 iDataSize)

RED_WRITEFILE_FUNCTION: Type definition for the file write callback.