"L. Spiro Engine"
Static Public Member Functions | Static Protected Attributes

lsf::CFileLib Class Reference

Cross-platform file functions. More...

#include <LSFFileLib.h>

List of all members.

Static Public Member Functions

static LSF_FILE LSE_CALL OpenFile (const LSCHAR *_pcFile, LSF_OPEN_FILE _ofOpenType, LSBOOL _bOpenAlways)
static LSBOOL LSE_CALL CloseFile (LSF_FILE &_fFile)
static LSBOOL LSE_CALL ReadFile (LSF_FILE _fFile, LSVOID *_pvBuffer, LSUINTPTR _uiptrBytesToRead)
static LSBOOL LSE_CALL WriteFile (LSF_FILE _fFile, const LSVOID *_pvBuffer, LSUINTPTR _uiptrBytesToWrite)
static LSBOOL LSE_CALL SetFilePointer (LSF_FILE _fFile, LSINT64 _i64DistanceToMove, LSF_SEEK _sMoveMethod)
static LSUINT64 LSE_CALL GetFilePointer (LSF_FILE _fFile)
static LSBOOL LSE_CALL CreateFileMap (const LSCHAR *_pcFile, LSF_OPEN_FILE _ofOpenType, LSF_FILE_MAP &_fmMap)
static LSBOOL LSE_CALL CreateFileMap (const LSWCHAR_T *_pwcFile, LSF_OPEN_FILE _ofOpenType, LSF_FILE_MAP &_fmMap)
static LSVOID LSE_CALL DestroyFileMap (LSF_FILE_MAP &_fmMap)
static LSVOID *LSE_CALL Map (const LSF_FILE_MAP &_fmMap, LSUINT64 _ui64Offset, LSUINTPTR _uiptrLen)
static LSVOID LSE_CALL UnMap (const LSVOID *_pvAddr, LSUINTPTR _uiptrLen)
static LSBOOL LSE_CALL CanWriteToFileMap (const LSF_FILE_MAP &_fmMap)
static LSUINT32 LSE_CALL GetPageSize ()
static LSUINT64 LSE_CALL GetFileSize (LSF_FILE _fFile)
static LSUINT64 LSE_CALL GetFileSize (const LSCHAR *_pcFile)
static LSUINT64 LSE_CALL GetFileSize (const LSWCHAR_T *_pwcFile)
static LSBOOL LSE_CALL Exists (const LSCHAR *_pcFile)
static LSBOOL LSE_CALL Exists (const LSWCHAR_T *_pwcFile)
static LSCHAR *LSE_CALL GetSelfDir (LSCHAR *_pcRet)
static LSWCHAR_T *LSE_CALL GetSelfDir (LSWCHAR_T *_pwcRet)
static LSCHAR *LSE_CALL ExpandPath (const LSCHAR *_pcPath, LSCHAR *_pcRet)
static LSWCHAR_T *LSE_CALL ExpandPath (const LSWCHAR_T *_pwcPath, LSWCHAR_T *_pwcRet)
static LSCHAR *LSE_CALL ExpandResourcePath (const LSCHAR *_pcPath, LSCHAR *_pcRet)
static LSCHAR *LSE_CALL NoExtension (LSCHAR *_pcPath)
static LSWCHAR_T *LSE_CALL NoExtension (LSWCHAR_T *_pwcPath)
static LSCHAR *LSE_CALL NoPath (LSCHAR *_pcPath)
static LSWCHAR_T *LSE_CALL NoPath (LSWCHAR_T *_pwcPath)
static LSCHAR *LSE_CALL NoFile (LSCHAR *_pcPath)
static LSWCHAR_T *LSE_CALL NoFile (LSWCHAR_T *_pwcPath)
static LSINT32 LSE_CALL Eof ()
static LSVOID LSE_CALL SetResPath (const LSCHAR *_pcPath)
static LSE_INLINE const LSCHAR
*LSE_CALL 
GetResPath ()

Static Protected Attributes

static LSCHAR m_szResourcePath [LSF_MAX_PATH]
static LSUINT32 m_ui32ResPathLen

Detailed Description

Cross-platform file functions.

Class CFileLib Description: Handles opening, closing, reading from, and writing to files. Also allows getting information on files such as size.


Member Function Documentation

static LSBOOL LSE_CALL lsf::CFileLib::CanWriteToFileMap ( const LSF_FILE_MAP &  _fmMap) [static]

Does the given file map provide write permissions?

Parameters:
_fmMapThe mapped file previously created with CreateFileMap();
Returns:
Returns true if the file was mapped with write permissions.
static LSBOOL LSE_CALL lsf::CFileLib::CloseFile ( LSF_FILE &  _fFile) [static]

Close a file. Sets the file pointer to NULL automatically.

Parameters:
_fFileHandle to the open file to close. This is set to an invalid handle after being closed.
Returns:
Returns false if there was an error closing the handle. If the handle is invalid, returns true immediately.
static LSBOOL LSE_CALL lsf::CFileLib::CreateFileMap ( const LSWCHAR_T *  _pwcFile,
LSF_OPEN_FILE  _ofOpenType,
LSF_FILE_MAP &  _fmMap 
) [static]

Create a file-mapping object. File must exist.

Parameters:
_pwcFileThe file to map.
_ofOpenTypeFlag determining how to open the file. Valid values are LSF_OF_READ, LSF_OF_WRITE, or both.
_fmMapHolds the returned file map upon success. If the function returns true, this structure must be passed to a call to DestroyFileMap() when no longer needed.
Returns:
Returns true if the mapping succeeded. False typically indicates that the file does not exist or cannot be accessed.
static LSBOOL LSE_CALL lsf::CFileLib::CreateFileMap ( const LSCHAR *  _pcFile,
LSF_OPEN_FILE  _ofOpenType,
LSF_FILE_MAP &  _fmMap 
) [static]

Create a file-mapping object. File must exist.

Parameters:
_pcFileThe file to map.
_ofOpenTypeFlag determining how to open the file. Valid values are LSF_OF_READ, LSF_OF_WRITE, or both.
_fmMapHolds the returned file map upon success. If the function returns true, this structure must be passed to a call to DestroyFileMap() when no longer needed.
Returns:
Returns true if the mapping succeeded. False typically indicates that the file does not exist or cannot be accessed.
static LSVOID LSE_CALL lsf::CFileLib::DestroyFileMap ( LSF_FILE_MAP &  _fmMap) [static]

Destroy a file map created with CreateFileMap(). Any regions not unmapped inside the file will become invalid. Use UnMap() on all mapped regions before calling this.

Parameters:
_fmMapThe file map to be destroyed.
static LSINT32 LSE_CALL lsf::CFileLib::Eof ( ) [static]

Returns the system EOF (end-of-file) value. This is normally -1 but is not guaranteed to be so on every platform/compiler.

Returns:
Returns the system EOF value.
static LSBOOL LSE_CALL lsf::CFileLib::Exists ( const LSCHAR *  _pcFile) [static]

Does the given file exist? Files only!

Parameters:
_pcFilePath to the file.
Returns:
Returns true if the file exists. If the path resolves to an existing folder or if the path does not exist, false is returned.
static LSBOOL LSE_CALL lsf::CFileLib::Exists ( const LSWCHAR_T *  _pwcFile) [static]

Does the given file exist? Files only!

Parameters:
_pcFilePath to the file.
Returns:
Returns true if the file exists. If the path resolves to an existing folder or if the path does not exist, false is returned.
static LSCHAR* LSE_CALL lsf::CFileLib::ExpandPath ( const LSCHAR *  _pcPath,
LSCHAR *  _pcRet 
) [static]

Fully expands the given path. The result is stored in _pcRet, which must be at least LSF_MAX_PATH characters long. Returns _pcRet or NULL on error.

Parameters:
_pcPathPath to expand, in UTF-8 format.
_pcRetBuffer to receive the expanded path. Must be at least LSF_MAX_PATH characters long.
Returns:
Returns _pcRet or NULL on error. On success, _pcRet will be filled with a NULL-terminated UTF-8 string representing the expanded path.
static LSWCHAR_T* LSE_CALL lsf::CFileLib::ExpandPath ( const LSWCHAR_T *  _pwcPath,
LSWCHAR_T *  _pwcRet 
) [static]

Fully expands the given path. The result is stored in _pwcRet, which must be at least LSF_MAX_PATH characters long. Returns _pwcRet or NULL on error.

Parameters:
_pwcPathPath to expand.
_pwcRetBuffer to receive the expanded path. Must be at least LSF_MAX_PATH characters long.
Returns:
_pwcRet or NULL on error.
static LSCHAR* LSE_CALL lsf::CFileLib::ExpandResourcePath ( const LSCHAR *  _pcPath,
LSCHAR *  _pcRet 
) [static]

Fully expands the given path, which is assumed to be relative to the resources directory. If the given path is not, an invalid path will be created.

Parameters:
_pcPathPath to expand, in UTF-8 format.
_pcRetBuffer to receive the expanded path. Must be at least LSF_MAX_PATH characters long.
Returns:
Returns _pcRet or NULL on error. On success, _pcRet will be filled with a NULL-terminated UTF-8 string representing the expanded path to the resource folder.
static LSUINT64 LSE_CALL lsf::CFileLib::GetFilePointer ( LSF_FILE  _fFile) [static]

Returns the position of the file pointer.

Parameters:
_fFileA handle to the file.
Returns:
Returns the position of the file pointer.
static LSUINT64 LSE_CALL lsf::CFileLib::GetFileSize ( const LSWCHAR_T *  _pwcFile) [static]

Get the size of a file.

Parameters:
_pwcFilePath to the file whose size is to be obtained.
Returns:
The size of the file.
static LSUINT64 LSE_CALL lsf::CFileLib::GetFileSize ( LSF_FILE  _fFile) [static]

Get the size of an open file.

Parameters:
_fFileHandle to the opened file whose size is to be obtained.
Returns:
The size of the file.
static LSUINT64 LSE_CALL lsf::CFileLib::GetFileSize ( const LSCHAR *  _pcFile) [static]

Get the size of a file.

Parameters:
_pcFileUTF-8 path to the file whose size is to be obtained.
Returns:
The size of the file.
static LSUINT32 LSE_CALL lsf::CFileLib::GetPageSize ( ) [static]

Get the size of a page boundary for mapping files.

Returns:
Returns the size of page boundaries, required for file-mapping routines.
LSE_INLINE const LSCHAR *LSE_CALL lsf::CFileLib::GetResPath ( ) [static]

Gets the resource path.

Returns:
Returns a pointer to the string containing the path to the resources.
static LSCHAR* LSE_CALL lsf::CFileLib::GetSelfDir ( LSCHAR *  _pcRet) [static]

Get the path to the directory in which this executable resides. Returns the string that was put into it. Must be at least LSF_MAX_PATH characters long. Returns NULL in the event of error. The returned string always ends with a backslash (or forward slash depending on the operating system).

Parameters:
_pcRetBuffer to be filled with the path to this executable.
Returns:
Returns _pcRet.
static LSWCHAR_T* LSE_CALL lsf::CFileLib::GetSelfDir ( LSWCHAR_T *  _pwcRet) [static]

Get the path to the directory in which this executable resides. Returns the string that was put into it. Must be at least LSF_MAX_PATH characters long. Returns NULL in the event of error. The returned string always ends with a backslash (or forward slash depending on the operating system).

Parameters:
_pwcRetBuffer to be filled with the path to this executable.
Returns:
Returns _pwcRet.
static LSVOID* LSE_CALL lsf::CFileLib::Map ( const LSF_FILE_MAP &  _fmMap,
LSUINT64  _ui64Offset,
LSUINTPTR  _uiptrLen 
) [static]

Map a region of a mapped file to memory. The mapped region must be unmapped with UnMap() when no longer needed.

Parameters:
_fmMapThe mapped file created with a previous call to CreateFileMap().
_ui64OffsetOffset into the file where to begin the mapping. Must be aligned on a system page boundary.
_uiptrLenNumber of bytes to map starting at the given offset.
Returns:
Returns NULL on failure, otherwise a pointer to the mapped data.
static LSWCHAR_T* LSE_CALL lsf::CFileLib::NoExtension ( LSWCHAR_T *  _pwcPath) [static]

Remove the extension from a path. Returns the input string, which is modified in-place.

Parameters:
_pwcPathOn input, it holds the path whose extension is to be removed. On return, it holds the path without the removed extension.
Returns:
Returns _pwcPath.
static LSCHAR* LSE_CALL lsf::CFileLib::NoExtension ( LSCHAR *  _pcPath) [static]

Remove the extension from a path. Returns the input string, which is modified in-place. The returned string is in UTF-8 format.

Parameters:
_pcPathOn input, it holds the path whose extension is to be removed. On return, it holds the path without the removed extension.
Returns:
Returns _pcPath.
static LSWCHAR_T* LSE_CALL lsf::CFileLib::NoFile ( LSWCHAR_T *  _pwcPath) [static]

Remove the file part of a path (leaves only the folder part). The return includes the terminating / or \. If there is no folder part to return, ./ is returned. Returns the input string, which is modified in-place.

Parameters:
_pwcPathOn input, it holds the string whose file part is to be removed. On return, it holds the string removed of its file.
Returns:
Returns _pwcPath.
static LSCHAR* LSE_CALL lsf::CFileLib::NoFile ( LSCHAR *  _pcPath) [static]

Remove the file part of a path (leaves only the folder part). The return includes the terminating / or \. If there is no folder part to return, ./ is returned. Returns the input string, which is modified in-place.

Parameters:
_pcPathOn input, it holds the string whose file part is to be removed. On return, it holds the string removed of its file.
Returns:
Returns _pcPath.
static LSWCHAR_T* LSE_CALL lsf::CFileLib::NoPath ( LSWCHAR_T *  _pwcPath) [static]

Remove the path part from a path (leaves only the file part). Returns the input string, which is modified in-place.

Parameters:
_pwcPathOn input, it holds the string whose path part is to be removed. On return, it holds the string removed of its path.
Returns:
Returns _pwcPath.
static LSCHAR* LSE_CALL lsf::CFileLib::NoPath ( LSCHAR *  _pcPath) [static]

Remove the path part from a path (leaves only the file part). Returns the input string, which is modified in-place. The returned string is in UTF-8 format.

Parameters:
_pcPathOn input, it holds the string whose path part is to be removed. On return, it holds the string removed of its path.
Returns:
Returns _pcPath.
static LSF_FILE LSE_CALL lsf::CFileLib::OpenFile ( const LSCHAR *  _pcFile,
LSF_OPEN_FILE  _ofOpenType,
LSBOOL  _bOpenAlways 
) [static]

Open a file. Returns NULL if failed.

Parameters:
_pcFilePath to the file to open. Must be UTF-8.
_ofOpenTypeFlag determining how to open the file. Valid values are LSF_OF_READ, LSF_OF_WRITE, and LSF_OF_APPEND, and some combinations thereof.
_bOpenAlwaysIf true, the file is opened even if it does not exist (it is created).
Returns:
The handle to the opened file or NULL.
static LSBOOL LSE_CALL lsf::CFileLib::ReadFile ( LSF_FILE  _fFile,
LSVOID *  _pvBuffer,
LSUINTPTR  _uiptrBytesToRead 
) [static]

Read from a file. Returns false under any form of error. If true is returned, the full amount of data was read from the file to the buffer.

Parameters:
_fFileHandle to the opened file from which to read.
_pvBufferBuffer to store the data read from the file. This must be long enough to hold _uiptrBytesToRead bytes.
_uiptrBytesToReadNumber of bytes to read from the file.
Returns:
Returns false if the read operation failed for any reason.
static LSBOOL LSE_CALL lsf::CFileLib::SetFilePointer ( LSF_FILE  _fFile,
LSINT64  _i64DistanceToMove,
LSF_SEEK  _sMoveMethod 
) [static]

Moves the file pointer of the specified file.

Parameters:
_fFileA handle to the file.
_i64DistanceToMoveThe number of bytes to move the file pointer. A positive value moves the pointer forward in the file and a negative value moves the file pointer backward.
_sMoveMethodThe starting point for the file pointer move. Must be one of the LSF_SEEK enumerated values.
Returns:
Returns true if the supplied handle is valid.
static LSVOID LSE_CALL lsf::CFileLib::SetResPath ( const LSCHAR *  _pcPath) [static]

Sets the resource path.

Parameters:
_pcPathThe resource path to set.
static LSVOID LSE_CALL lsf::CFileLib::UnMap ( const LSVOID *  _pvAddr,
LSUINTPTR  _uiptrLen 
) [static]

Unmaps a region of memory previously mapped with a call to Map().

Parameters:
_pvAddrPrevious pointer returned by Map().
_uiptrLenLength previously passed to Map() when creating the region.
static LSBOOL LSE_CALL lsf::CFileLib::WriteFile ( LSF_FILE  _fFile,
const LSVOID *  _pvBuffer,
LSUINTPTR  _uiptrBytesToWrite 
) [static]

Write to a file. Returns false under any form of error. Data is written starting at the current position in the file.

Parameters:
_fFileHandle to the opened file to which to write. Must have been opened with either LSF_OF_WRITE or LSF_OF_APPEND.
_pvBufferData to write to the file.
_uiptrBytesToWriteNumber of bytes to copy from _pvBuffer to the file.
Returns:
Returns false if the write failed for any reason.

Member Data Documentation

LSCHAR lsf::CFileLib::m_szResourcePath[LSF_MAX_PATH] [static, protected]

The resource path.

LSUINT32 lsf::CFileLib::m_ui32ResPathLen [static, protected]

Length of the resource path in characters.


The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator