Castor3D 0.16.0
Multiplatform 3D engine
Public Member Functions | List of all members
castor::BinaryFile Class Reference

User friendly File class. More...

#include <BinaryFile.hpp>

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

Public Member Functions

CU_API BinaryFile (Path const &fileName, FlagCombination< OpenMode > const &mode, EncodingMode encodingMode=EncodingMode::eASCII)
 Opens the file at the given path with the given mode and encoding.
 
CU_API bool write (String const &toWrite)
 Writes a string into the file (binary, so writes size then content, without '\0')
 
CU_API bool read (String &toRead)
 Reads a string from the file (binary, so reads size then content)
 
template<typename T >
uint64_t write (T const &toWrite)
 Writes an object into the file.
 
template<typename T >
uint64_t read (T &toRead)
 Reads an object from the file.
 
template<typename T >
uint64_t writeArray (T const *toWrite, uint64_t count)
 Writes a dynamic array of objects into the file.
 
template<typename T , uint64_t N>
uint64_t writeArray (T const(&toWrite)[N])
 Writes a static array of objects into the file.
 
template<typename T >
uint64_t readArray (T *toRead, uint64_t count)
 Reads a dynamic array of objects from the file.
 
template<typename T , uint64_t N>
uint64_t readArray (T(&toRead)[N])
 Reads a static array of objects from the file.
 
- Public Member Functions inherited from castor::File
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.
 

Additional Inherited Members

- Public Types inherited from castor::File
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 ) >
 
- Static Public Member Functions inherited from castor::File
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 inherited from castor::File
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 inherited from castor::File
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 }
 

Detailed Description

User friendly File class.

Remarks
adds some static functions to check file/directory validity, file/directory creation...

Constructor & Destructor Documentation

◆ BinaryFile()

CU_API castor::BinaryFile::BinaryFile ( Path const & fileName,
FlagCombination< OpenMode > const & mode,
EncodingMode encodingMode = EncodingMode::eASCII )

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

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

Member Function Documentation

◆ read() [1/2]

CU_API bool castor::BinaryFile::read ( String & toRead)

Reads a string from the file (binary, so reads size then content)

Parameters
[out]toReadThe string
Returns
true if read correctly

◆ read() [2/2]

template<typename T >
uint64_t castor::BinaryFile::read ( T & toRead)

Reads an object from the file.

Parameters
[out]toReadThe object
Returns
The bytes read

◆ readArray() [1/2]

template<typename T >
uint64_t castor::BinaryFile::readArray ( T * toRead,
uint64_t count )

Reads a dynamic array of objects from the file.

Parameters
[out]toReadThe objects array (must be allocated before call)
[in]countThe array size
Returns
The bytes read

◆ readArray() [2/2]

template<typename T , uint64_t N>
uint64_t castor::BinaryFile::readArray ( T(&) toRead[N])

Reads a static array of objects from the file.

Parameters
[out]toReadThe objects array
Remarks
Array size is deduced from parameter
Returns
The bytes read

◆ write() [1/2]

CU_API bool castor::BinaryFile::write ( String const & toWrite)

Writes a string into the file (binary, so writes size then content, without '\0')

Parameters
[in]toWriteThe string
Returns
true if written correctly

◆ write() [2/2]

template<typename T >
uint64_t castor::BinaryFile::write ( T const & toWrite)

Writes an object into the file.

Parameters
[in]toWriteThe object
Returns
The bytes written

◆ writeArray() [1/2]

template<typename T >
uint64_t castor::BinaryFile::writeArray ( T const * toWrite,
uint64_t count )

Writes a dynamic array of objects into the file.

Parameters
[in]toWriteThe object array
[in]countThe array size
Returns
The bytes written

◆ writeArray() [2/2]

template<typename T , uint64_t N>
uint64_t castor::BinaryFile::writeArray ( T const(&) toWrite[N])

Writes a static array of objects into the file.

Remarks
Array size is deduced from parameter
Parameters
[in]toWriteThe object array
Returns
The bytes written

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