Gateware Libraries  R6.5A
Beta Build
GW::SYSTEM::GFile Class Referenceabstract

Cross platform FileIO/Directory handling. More...

#include <GFile.h>

Inheritance diagram for GW::SYSTEM::GFile:
Collaboration diagram for GW::SYSTEM::GFile:

Public Member Functions

virtual GReturn OpenBinaryRead (const char *const _file)=0
 Opens a file for binary read. More...
 
virtual GReturn OpenBinaryWrite (const char *const _file)=0
 Opens a file for binary write with truncation. More...
 
virtual GReturn AppendBinaryWrite (const char *const _file)=0
 Opens a file for binary write with append. More...
 
virtual GReturn OpenTextRead (const char *const _file)=0
 Opens a file for text read. More...
 
virtual GReturn OpenTextWrite (const char *const _file)=0
 Opens a file for text write with truncation. More...
 
virtual GReturn AppendTextWrite (const char *const _file)=0
 Opens a file for text write with append. More...
 
virtual GReturn Write (const char *const _inData, unsigned int _numBytes)=0
 Writes binary data to the currently opened file. More...
 
virtual GReturn Read (char *_outData, unsigned int _numBytes)=0
 Reads binary from the currently opened file. More...
 
virtual GReturn WriteLine (const char *const _inData)=0
 Writes text to the currently opened file. More...
 
virtual GReturn ReadLine (char *_outData, unsigned int _outDataSize, char _delimiter)=0
 Reads text to the currently opened file. More...
 
virtual GReturn CloseFile ()=0
 Flushes and closes the current file. More...
 
virtual GReturn FlushFile ()=0
 Flushes the current file. More...
 
virtual GReturn SetCurrentWorkingDirectory (const char *const _dir)=0
 Changes the current working directory. More...
 
virtual GReturn GetCurrentWorkingDirectory (char *_outDir, unsigned int _dirSize)=0
 Retrieves the absolute path of the current working directory. More...
 
virtual GReturn GetDirectorySize (unsigned int &_outSize)=0
 Gets the number of files in the current working directory. More...
 
virtual GReturn GetFilesFromDirectory (char *_outFiles[], unsigned int _numFiles, unsigned int _fileNameSize)=0
 Gets the names of all files in the current working directory. More...
 
virtual GReturn GetFileSize (const char *const _file, unsigned int &_outSize)=0
 Gets the size of the specified file in bytes. More...
 
- Public Member Functions inherited from GW::CORE::GInterface
virtual GReturn GetCount (unsigned int &_outCount)=0
 Return the total number of active references to this object. More...
 
virtual GReturn IncrementCount ()=0
 Increase the total number of active references to this object. More...
 
virtual GReturn DecrementCount ()=0
 Decrease the total number of active references to this object. More...
 
virtual GReturn RequestInterface (const GUUIID &_interfaceID, void **_outputInterface)=0
 Requests an interface that may or may not be supported by this object. More...
 

Detailed Description

Cross platform FileIO/Directory handling.

Handles file input/output operations, as well as directory information and file information. GFile inherits directly from GMultiThreaded, therefore its implementation must be thread safe.

Member Function Documentation

◆ AppendBinaryWrite()

virtual GReturn GW::SYSTEM::GFile::AppendBinaryWrite ( const char *const  _file)
pure virtual

Opens a file for binary write with append.

The file name passed into the function should be passed like it is a relative path. The function will look in the current working directory for the file. If the file is not found in the current working directory, the file will be created in the current working directory. File can now be written to with Write().

Parameters
[in]_fileThe file name of the file to open.
Return values
SUCCESSSuccesfully opened the file.
FAILUREA file is already open or the file could not be found/created.
INVALID_ARGUMENTA nullptr was passed in.

◆ AppendTextWrite()

virtual GReturn GW::SYSTEM::GFile::AppendTextWrite ( const char *const  _file)
pure virtual

Opens a file for text write with append.

The file name passed into the function should be passed like it is a relative path. The function will look in the current working directory for the file. If the file is not found in the current working directory, the file will be created in the current working directory. File can now be written to with Write().

Parameters
[in]_fileThe file name of the file to open.
Return values
SUCCESSSuccesfully opened the file.
FAILUREA file is already open or the file could not be found/created.
INVALID_ARGUMENTA nullptr was passed in.

◆ CloseFile()

virtual GReturn GW::SYSTEM::GFile::CloseFile ( )
pure virtual

Flushes and closes the current file.

Return values
SUCCESSFile successfully flushed and closed.
FAILUREA file is not currently open.

◆ FlushFile()

virtual GReturn GW::SYSTEM::GFile::FlushFile ( )
pure virtual

Flushes the current file.

Return values
SUCCESSFile successfully flushed.
FAILUREA file is not currently open.

◆ GetCurrentWorkingDirectory()

virtual GReturn GW::SYSTEM::GFile::GetCurrentWorkingDirectory ( char *  _outDir,
unsigned int  _dirSize 
)
pure virtual

Retrieves the absolute path of the current working directory.

This is the directory we will look into for any file Open commands. This is by Windows standard guaranteed to be 255 or less.

Parameters
[out]_outDirAn absolute path to the directory to set as the current working directory.
[in]_dirSizeThe size of _outDir.
Return values
SUCCESSSuccessfully obtained the working directory.
FAILUREThe current working directory is invalid or _outDir was not big enough. _outDir will be null.
INVALID_ARGUMENTA nullptr was passed in or the size is 0.

◆ GetDirectorySize()

virtual GReturn GW::SYSTEM::GFile::GetDirectorySize ( unsigned int &  _outSize)
pure virtual

Gets the number of files in the current working directory.

Parameters
[out]_outSizeThe number of files in the directory.
Return values
SUCCESSSuccessfully counted the files in the directory.
FAILUREEither currently working directory is invalid or count failed. _outSize will be -1.

◆ GetFilesFromDirectory()

virtual GReturn GW::SYSTEM::GFile::GetFilesFromDirectory ( char *  _outFiles[],
unsigned int  _numFiles,
unsigned int  _fileNameSize 
)
pure virtual

Gets the names of all files in the current working directory.

This function will retrieve just the file names and extensions. Any Open function using these names will assume the files are in the current working directory. Any change of the current working directory will make the names generated by this function invalid until called again.

Parameters
[out]_outFilesStores the names of the files retrieved.
[in]_numFilesThe number of files.
[in]_fileNameSizeThe size of the file names.
Return values
SUCCESSSuccessfully retrieved the file names.
FAILUREEither current working directory is invalid or obtaining file names failed.

◆ GetFileSize()

virtual GReturn GW::SYSTEM::GFile::GetFileSize ( const char *const  _file,
unsigned int &  _outSize 
)
pure virtual

Gets the size of the specified file in bytes.

The filename passed into this function should be passed as a relative path. This function will assume the file passed in is in the current working directory and will look for it there.

Parameters
[in]_fileThe file to get the size of.
[out]_outSizewill store the size of the file.
Return values
SUCCESSSuccessfully retrieved the file size.
FILE_NOT_FOUNDCould not locate the file. Check that the current working directory is valid.

◆ OpenBinaryRead()

virtual GReturn GW::SYSTEM::GFile::OpenBinaryRead ( const char *const  _file)
pure virtual

Opens a file for binary read.

The file name passed into the function should be passed like it is a relative path. The function will look in the current working directory for the file. If the file is not found in the current working directory, the function will fail.

Parameters
[in]_fileThe file name of the file to open.
Return values
SUCCESSSuccesfully opened the file.
FILE_NOT_FOUNDFile could not be found.
FAILUREA file is already opened.
INVALID_ARGUMENTA null pointer was passed in.

◆ OpenBinaryWrite()

virtual GReturn GW::SYSTEM::GFile::OpenBinaryWrite ( const char *const  _file)
pure virtual

Opens a file for binary write with truncation.

The file name passed into the function should be passed like it is a relative path. The function will look in the current working directory for the file. If the file is not found in the current working directory, the file will be created in the current working directory. File can now be read from with Read().

Parameters
[in]_fileThe file name of the file to open.
Return values
SUCCESSSuccesfully opened the file.
FAILUREA file is already open or file could not be found/created.
INVALID_ARGUMENTA nullptr was passed in.

◆ OpenTextRead()

virtual GReturn GW::SYSTEM::GFile::OpenTextRead ( const char *const  _file)
pure virtual

Opens a file for text read.

The file name passed into the function should be passed like it is a relative path. The function will look in the current working directory for the file. If the file is not found in the current working directory, the function will fail. File can now be written to with Write().

Parameters
[in]_fileThe file name of the file to open.
Return values
SUCCESSSuccesfully opened the file.
FILE_NOT_FOUNDFile could not be found.
FAILUREA file is already open.
INVALID_ARGUMENTA nullptr was passed in.

◆ OpenTextWrite()

virtual GReturn GW::SYSTEM::GFile::OpenTextWrite ( const char *const  _file)
pure virtual

Opens a file for text write with truncation.

The file name passed into the function should be passed like it is a relative path. The function will look in the current working directory for the file. If the file is not found in the current working directory, the file will be created in the current working directory. File can now be read from with Read().

Parameters
[in]_fileThe file name of the file to open.
Return values
SUCCESSSuccesfully opened the file.
FAILUREA file is already open or the file could not be found/created.
INVALID_ARGUMENTA nullptr was passed in.

◆ Read()

virtual GReturn GW::SYSTEM::GFile::Read ( char *  _outData,
unsigned int  _numBytes 
)
pure virtual

Reads binary from the currently opened file.

Reads binary data and stores it into a char* until the byte limit is reached.

Parameters
[out]_outDataThe variable to store the read in bytes.
[in]_numBytesThe number of bytes to read in from the file.
Return values
SUCCESSSuccessful read.
FAILUREEither file is not open or read failed. _outData will be null.
INVALID_ARGUMENTA byte size of 0 was passed in.

◆ ReadLine()

virtual GReturn GW::SYSTEM::GFile::ReadLine ( char *  _outData,
unsigned int  _outDataSize,
char  _delimiter 
)
pure virtual

Reads text to the currently opened file.

Reads text from the current file until either the size is reached or delimiter is reached.

Parameters
[out]_outDataNull terminated string to write out.
[in]_outDataSizeThe size of _outData.
[in]_delimiterThe delimiter to stop reading at.
Return values
SUCCESSSuccessful read.
FAILUREEither file is not open or read failed.
INVALID_ARGUMENTEither a nullptr was passed in or the size request is 0.

◆ SetCurrentWorkingDirectory()

virtual GReturn GW::SYSTEM::GFile::SetCurrentWorkingDirectory ( const char *const  _dir)
pure virtual

Changes the current working directory.

This sets the directory we will look into with any of the Open functions or other directory functions. Paths that are not relative to the directory the program was ran from should be passed in as absolute paths.

Parameters
[in]_dirAn absolute path to the directory to set as the current working directory.
Return values
SUCCESSSuccesfully set the current working directory.
FILE_NOT_FOUNDThe directory could not be found.
FAILUREFailed to open directory (Could be because it was not found).
INVALID_ARGUMENTA nullptr was passed in.

◆ Write()

virtual GReturn GW::SYSTEM::GFile::Write ( const char *const  _inData,
unsigned int  _numBytes 
)
pure virtual

Writes binary data to the currently opened file.

Will append or truncate file based on what mode the currently opened file was opened with.

Parameters
[in]_inDataThe data to write out to file.
[in]_numBytesThe number of bytes to write out to the file.
Return values
SUCCESSSuccesfully wrote out the data.
FAILUREEither a file is not open or the write failed.
INVALID_ARGUMENTEither a nullptr was passed in or a size of 0 bytes was passed in.

◆ WriteLine()

virtual GReturn GW::SYSTEM::GFile::WriteLine ( const char *const  _inData)
pure virtual

Writes text to the currently opened file.

Will append or truncate file based on what mode the currently opened file was opened with.

Parameters
[in]_inDataNull terminated string to write out.
Return values
SUCCESSSuccessful write.
FAILUREEither file is not open or read failed.
INVALID_ARGUMENTA nullptr was passed in.

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