Castor3D 0.16.0
Multiplatform 3D engine
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
castor::File Class Reference

#include <File.hpp>

Inheritance diagram for castor::File:
Inheritance graph
[legend]
Collaboration diagram for castor::File:
Collaboration graph
[legend]

Public Types

enum class  CreateMode : uint32_t {
  eUserRead = 0x00000001 , eUserWrite = 0x00000002 , eUserExec = 0x00000004 , eGroupRead = 0x00000010 ,
  eGroupWrite = 0x00000020 , eGroupExec = 0x00000040 , eOthersRead = 0x00000100 , eOthersWrite = 0x00000200 ,
  eOthersExec = 0x00000400 , eUserRWX = eUserRead | eUserWrite | eUserExec , eGroupRWX = eGroupRead | eGroupWrite | eGroupExec , eOthersRWX = eOthersRead | eOthersWrite | eOthersExec ,
  eAllRWX = eUserRWX | eGroupRWX | eOthersRWX
}
 open modes enumerator More...
 
enum class  OpenMode : uint32_t {
  eDummy = 0x00000000 , eRead = 0x00000001 , eWrite = 0x00000002 , eAppend = 0x00000004 ,
  eBinary = 0x00000008
}
 open modes enumerator More...
 
enum class  OffsetMode : uint8_t {
  eBeginning = 0 , eCurrent = 1 , eEnd = 2 , eCount ,
  eMin = eBeginning
}
 Offset modes enumerator. More...
 
enum class  EncodingMode : uint8_t {
  eAuto = 0 , eASCII = 1 , eUTF8 = 2 , eUTF16 = 3 ,
  eCount , eMin = eAuto
}
 Text file encoding mode. More...
 
using TraverseDirFunction = castor::Function< bool( Path const & path ) >
 
using HitFileFunction = castor::Function< void( Path const & folder, String const & name ) >
 
using FilterFunction = castor::Function< bool( Path const & folder, String const & name ) >
 

Public Member Functions

virtual CU_API ~File () noexcept
 Destructor, closes the file.
 
CU_API int seek (long long offset, OffsetMode origin=OffsetMode::eBeginning)
 sets the cursor in the file according to the given offset and the given mode
 
CU_API long long getLength ()
 Retrieves the file size.
 
CU_API bool isOk () const
 Tells if the file cursor is OK.
 
CU_API long long tell ()
 Retrieves the file cursor position.
 
Path const & getFileFullPath () const
 Retrieves the full file path, name and extension.
 
Path getFilePath () const
 Retrieves the full file path.
 
Path getFileName () const
 Retrieves the file name and extension.
 

Static Public Member Functions

static CU_API bool traverseDirectory (Path const &folderPath, TraverseDirFunction const &directoryFunction, HitFileFunction const &fileFunction)
 Traverses the files and directories of a directory.
 
static CU_API PathArray filterDirectoryFiles (Path const &folderPath, FilterFunction const &onFile, bool recursive=false)
 Filters the files in a directory, recursively or not.
 
static CU_API bool listDirectoryFiles (Path const &folderPath, PathArray &files, bool recursive=false)
 List all files in a directory, recursively or not.
 
static CU_API Path getExecutableDirectory ()
 Gives the current directory (id est where the execution is)
 
static CU_API Path getUserDirectory ()
 Gives the user home directory.
 
static CU_API bool directoryExists (Path const &folderPath)
 Tests directory existence.
 
static CU_API bool directoryCreate (Path const &folderPath, FlagCombination< CreateMode > const &flags=CreateMode::eAllRWX)
 Creates a directory.
 
static CU_API bool directoryDelete (Path const &folderPath)
 Deletes an empty directory.
 
static CU_API bool fileExists (Path const &filePath)
 Tests file existence.
 
static CU_API bool deleteFile (Path const &filePath)
 Deletes a file.
 
static CU_API bool copyFile (Path const &filePath, Path const &folderPath, bool allowReplace=false)
 Copy a file into a folder.
 
static CU_API bool copyFileName (Path const &srcFileName, Path const &dstFileName, bool allowReplace=false)
 Copies a file.
 
static CU_API String normaliseFileName (String const &name)
 Replaces the characters non valid for file name with '_'.
 

Protected Member Functions

CU_API File (Path const &filePath, FlagCombination< OpenMode > const &mode, EncodingMode encoding=EncodingMode::eASCII)
 Opens the file at the given path with the given mode and encoding.
 
 CU_DeclareInvariantBlock ()
 
CU_API uint64_t doWrite (uint8_t const *buffer, uint64_t size)
 
CU_API uint64_t doRead (uint8_t *buffer, uint64_t size)
 
- Protected Member Functions inherited from castor::NonMovable
 NonMovable ()=default
 Constructor.
 
 ~NonMovable () noexcept=default
 Destructor.
 

Protected Attributes

FlagCombination< OpenModem_mode { 0u }
 
EncodingMode m_encoding { EncodingMode::eASCII }
 
Path m_fileFullPath
 
FILE * m_file { nullptr }
 
uint64_t m_cursor { 0 }
 
uint64_t m_length { 0 }
 

Member Typedef Documentation

◆ FilterFunction

using castor::File::FilterFunction = castor::Function< bool( Path const & folder, String const & name ) >

◆ HitFileFunction

using castor::File::HitFileFunction = castor::Function< void( Path const & folder, String const & name ) >

◆ TraverseDirFunction

using castor::File::TraverseDirFunction = castor::Function< bool( Path const & path ) >

Member Enumeration Documentation

◆ CreateMode

enum class castor::File::CreateMode : uint32_t
strong

open modes enumerator

Enumerator
eUserRead 

Owner can read.

eUserWrite 

Owner can write.

eUserExec 

Owner can execute.

eGroupRead 

Owner group can read.

eGroupWrite 

Owner group can write.

eGroupExec 

Owner group can execute.

eOthersRead 

Others can read.

eOthersWrite 

Others can write.

eOthersExec 

Others can execute.

eUserRWX 

read, write and execution rights for owner.

eGroupRWX 

read, write and execution rights for owner group.

eOthersRWX 

read, write and execution rights for others.

eAllRWX 

read, write and execution rights for all users.

◆ EncodingMode

enum class castor::File::EncodingMode : uint8_t
strong

Text file encoding mode.

Enumerator
eAuto 

Auto select text encoding.

eASCII 

ASCII text encoding.

eUTF8 

UTF8 text encoding.

eUTF16 

UTF16 text encoding.

eCount 
eMin 

◆ OffsetMode

enum class castor::File::OffsetMode : uint8_t
strong

Offset modes enumerator.

Enumerator
eBeginning 

The offset is set from the beginning of the file.

eCurrent 

The offset is set from the current position.

eEnd 

The offset is set from the end of the file.

eCount 
eMin 

◆ OpenMode

enum class castor::File::OpenMode : uint32_t
strong

open modes enumerator

Enumerator
eDummy 

Dummy open mode, not to be used.

eRead 

read open mode.

eWrite 

write open mode.

eAppend 

Append open mode.

eBinary 

Binary open mode.

Constructor & Destructor Documentation

◆ File()

CU_API castor::File::File ( Path const & filePath,
FlagCombination< OpenMode > const & mode,
EncodingMode encoding = EncodingMode::eASCII )
protected

Opens the file at the given path with the given mode and encoding.

Parameters
[in]filePathThe file path
[in]modeThe opening mode, combination of one or more OpenMode
[in]encodingThe file encoding mode

◆ ~File()

virtual CU_API castor::File::~File ( )
virtualnoexcept

Destructor, closes the file.

Member Function Documentation

◆ copyFile()

static CU_API bool castor::File::copyFile ( Path const & filePath,
Path const & folderPath,
bool allowReplace = false )
static

Copy a file into a folder.

Parameters
[in]filePathFile name and path.
[in]folderPathThe destination folder.
[in]allowReplacetrue to allow existing file replacing.
Returns
true if file has been correctly copied.

◆ copyFileName()

static CU_API bool castor::File::copyFileName ( Path const & srcFileName,
Path const & dstFileName,
bool allowReplace = false )
static

Copies a file.

Returns
true if file has been correctly copied

◆ CU_DeclareInvariantBlock()

castor::File::CU_DeclareInvariantBlock ( )
protected

◆ deleteFile()

static CU_API bool castor::File::deleteFile ( Path const & filePath)
static

Deletes a file.

Parameters
[in]filePathFile name and path
Returns
true if file has been correctly deleted

◆ directoryCreate()

static CU_API bool castor::File::directoryCreate ( Path const & folderPath,
FlagCombination< CreateMode > const & flags = CreateMode::eAllRWX )
static

Creates a directory.

Parameters
[in]folderPathDirectory path
[in]flagsUser rights
Returns
true if the directory has been created

◆ directoryDelete()

static CU_API bool castor::File::directoryDelete ( Path const & folderPath)
static

Deletes an empty directory.

Parameters
[in]folderPathDirectory path
Returns
true if the directory has been deleted

◆ directoryExists()

static CU_API bool castor::File::directoryExists ( Path const & folderPath)
static

Tests directory existence.

Parameters
[in]folderPathDirectory path
Returns
true if directory is found

◆ doRead()

CU_API uint64_t castor::File::doRead ( uint8_t * buffer,
uint64_t size )
protected

◆ doWrite()

CU_API uint64_t castor::File::doWrite ( uint8_t const * buffer,
uint64_t size )
protected

◆ fileExists()

static CU_API bool castor::File::fileExists ( Path const & filePath)
static

Tests file existence.

Parameters
[in]filePathFile name and path
Returns
true if file is found

◆ filterDirectoryFiles()

static CU_API PathArray castor::File::filterDirectoryFiles ( Path const & folderPath,
FilterFunction const & onFile,
bool recursive = false )
static

Filters the files in a directory, recursively or not.

Parameters
[in]folderPathThe directory path.
[in]onFileThe filter function, returns true to add to the list, false to ignore.
[in]recursiveTells if search must be recursive.
Returns
The files list.

◆ getExecutableDirectory()

static CU_API Path castor::File::getExecutableDirectory ( )
static

Gives the current directory (id est where the execution is)

Returns
The directory

◆ getFileFullPath()

Path const & castor::File::getFileFullPath ( ) const
inline

Retrieves the full file path, name and extension.

Returns
The value

References m_fileFullPath.

◆ getFileName()

Path castor::File::getFileName ( ) const
inline

Retrieves the file name and extension.

Returns
The value

References castor::Path::getFullFileName(), and m_fileFullPath.

Here is the call graph for this function:

◆ getFilePath()

Path castor::File::getFilePath ( ) const
inline

Retrieves the full file path.

Returns
The value

References castor::Path::getPath(), and m_fileFullPath.

Here is the call graph for this function:

◆ getLength()

CU_API long long castor::File::getLength ( )

Retrieves the file size.

Returns
The value

◆ getUserDirectory()

static CU_API Path castor::File::getUserDirectory ( )
static

Gives the user home directory.

Returns
The directory

◆ isOk()

CU_API bool castor::File::isOk ( ) const

Tells if the file cursor is OK.

Returns
true if the file cursor is not in error and not EOF

◆ listDirectoryFiles()

static CU_API bool castor::File::listDirectoryFiles ( Path const & folderPath,
PathArray & files,
bool recursive = false )
static

List all files in a directory, recursively or not.

Parameters
[in]folderPathThe directory path
[out]filesReceives the files list
[in]recursiveTells if search must be recursive
Returns
true if the directory is listed

◆ normaliseFileName()

static CU_API String castor::File::normaliseFileName ( String const & name)
static

Replaces the characters non valid for file name with '_'.

◆ seek()

CU_API int castor::File::seek ( long long offset,
OffsetMode origin = OffsetMode::eBeginning )

sets the cursor in the file according to the given offset and the given mode

Parameters
[in]offsetThe wanted offset
[in]originThe offset mode
Returns
0 if successful

◆ tell()

CU_API long long castor::File::tell ( )

Retrieves the file cursor position.

Returns
The value

◆ traverseDirectory()

static CU_API bool castor::File::traverseDirectory ( Path const & folderPath,
TraverseDirFunction const & directoryFunction,
HitFileFunction const & fileFunction )
static

Traverses the files and directories of a directory.

Parameters
[in]folderPathThe directory path.
[in]directoryFunctionreturns true to traverse it, false to ignore.
[in]fileFunctionPlaceholder to handle a file name.
Returns
false if any error occured.

Member Data Documentation

◆ m_cursor

uint64_t castor::File::m_cursor { 0 }
protected

The current cursor position in file.

◆ m_encoding

EncodingMode castor::File::m_encoding { EncodingMode::eASCII }
protected

The encoding mode.

◆ m_file

FILE* castor::File::m_file { nullptr }
protected

The file.

◆ m_fileFullPath

Path castor::File::m_fileFullPath
protected

The full file path.

Referenced by getFileFullPath(), getFileName(), and getFilePath().

◆ m_length

uint64_t castor::File::m_length { 0 }
protected

The total file length.

◆ m_mode

FlagCombination< OpenMode > castor::File::m_mode { 0u }
protected

The opening mode.


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