![]() |
Castor3D 0.17.0
Multiplatform 3D engine
|
User friendly File class. More...
#include <BinaryFile.hpp>


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, castor::StringView repl=cuT("_")) |
| Replaces the characters non valid for file name with given replacement character. | |
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< OpenMode > | m_mode { 0u } |
| EncodingMode | m_encoding { EncodingMode::eASCII } |
| Path | m_fileFullPath |
| FILE * | m_file { nullptr } |
| uint64_t | m_cursor { 0 } |
| uint64_t | m_length { 0 } |
User friendly File class.
| 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.
| [in] | fileName | The file path |
| [in] | mode | The opening mode, combination of one or more OpenMode |
| [in] | encodingMode | The encoding mode |
Reads a string from the file (binary, so reads size then content)
| [out] | toRead | The string |
true if read correctly | uint64_t castor::BinaryFile::read | ( | T & | toRead | ) |
Reads an object from the file.
| [out] | toRead | The object |
| uint64_t castor::BinaryFile::readArray | ( | T * | toRead, |
| uint64_t | count ) |
Reads a dynamic array of objects from the file.
| [out] | toRead | The objects array (must be allocated before call) |
| [in] | count | The array size |
| uint64_t castor::BinaryFile::readArray | ( | T(&) | toRead[N] | ) |
Reads a static array of objects from the file.
| [out] | toRead | The objects array |
Writes a string into the file (binary, so writes size then content, without '\0')
| [in] | toWrite | The string |
true if written correctly | uint64_t castor::BinaryFile::write | ( | T const & | toWrite | ) |
Writes an object into the file.
| [in] | toWrite | The object |
| uint64_t castor::BinaryFile::writeArray | ( | T const * | toWrite, |
| uint64_t | count ) |
Writes a dynamic array of objects into the file.
| [in] | toWrite | The object array |
| [in] | count | The array size |
| uint64_t castor::BinaryFile::writeArray | ( | T const(&) | toWrite[N] | ) |
Writes a static array of objects into the file.
| [in] | toWrite | The object array |