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

Text file class. More...

#include <TextFile.hpp>

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

Public Member Functions

CU_API TextFile (Path const &fileName, FlagCombination< OpenMode > const &mode, EncodingMode encoding=EncodingMode::eASCII)
 Opens the file at the given path with the given mode and encoding.
 
CU_API uint64_t readLine (String &toRead, uint64_t size, StringView separators=cuT("\r\n"))
 Reads one line from the file (stops at first separator met or when size is read)
 
CU_API uint64_t readWord (String &toRead)
 Reads one word from the file (stops at first ' ' met)
 
CU_API uint64_t readChar (xchar &toRead)
 Reads one char from the file.
 
CU_API uint64_t copyToString (String &out)
 Copies all this file's content into a string.
 
CU_API uint64_t writeText (String const &text)
 Writes a text into 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

Text file class.

Constructor & Destructor Documentation

◆ TextFile()

CU_API castor::TextFile::TextFile ( Path const & fileName,
FlagCombination< OpenMode > const & mode,
EncodingMode encoding = 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]encodingThe text encoding mode

Member Function Documentation

◆ copyToString()

CU_API uint64_t castor::TextFile::copyToString ( String & out)

Copies all this file's content into a string.

Parameters
[out]outReceives the content
Returns
The bytes read

◆ readChar()

CU_API uint64_t castor::TextFile::readChar ( xchar & toRead)

Reads one char from the file.

Parameters
[out]toReadReceives the read char
Returns
The bytes read

◆ readLine()

CU_API uint64_t castor::TextFile::readLine ( String & toRead,
uint64_t size,
StringView separators = cuT("\r\n") )

Reads one line from the file (stops at first separator met or when size is read)

Parameters
[out]toReadReceives the read line
[in]sizeThe maximum line size
[in]separatorsThe list of line separators
Returns
The bytes read

◆ readWord()

CU_API uint64_t castor::TextFile::readWord ( String & toRead)

Reads one word from the file (stops at first ' ' met)

Parameters
[out]toReadReceives the read word
Returns
The bytes read

◆ writeText()

CU_API uint64_t castor::TextFile::writeText ( String const & text)

Writes a text into the file.

Parameters
[in]textThe text
Returns
The bytes written

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