Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::File Class Reference

Core class that represents a file. More...

Inheritance diagram for Nz::File:
Nz::Stream

Public Member Functions

 File ()
 Constructs a File object by default.
 
 File (const String &filePath)
 Constructs a File object with a file path. More...
 
 File (const String &filePath, OpenModeFlags openMode)
 Constructs a File object with a file path and flags. More...
 
 File (const File &)=delete
 
 File (File &&file) noexcept=default
 
 ~File ()
 Destructs the object and calls Close. More...
 
bool Copy (const String &newFilePath)
 Copies this file to a new file path. More...
 
void Close ()
 Closes the file.
 
bool Delete ()
 Deletes the file. More...
 
bool EndOfFile () const
 Checks whether the file has reached the end. More...
 
bool EndOfStream () const override
 Checks whether the file has reached the end of the stream. More...
 
bool Exists () const
 Checks whether the file exists. More...
 
time_t GetCreationTime () const
 Gets the creation time of the file. More...
 
UInt64 GetCursorPos () const override
 Gets the position of the cursor in the file. More...
 
String GetDirectory () const override
 Gets the directory of the file. More...
 
String GetFileName () const
 Gets the name of the file. More...
 
time_t GetLastAccessTime () const
 Gets the last time the file was accessed. More...
 
time_t GetLastWriteTime () const
 Gets the last time the file was written. More...
 
String GetPath () const override
 Gets the path of the file. More...
 
UInt64 GetSize () const override
 Gets the size of the file. More...
 
bool IsOpen () const
 Checks whether the file is open. More...
 
bool Open (OpenModeFlags openMode=OpenMode_NotOpen)
 Opens the file with flags. More...
 
bool Open (const String &filePath, OpenModeFlags openMode=OpenMode_NotOpen)
 Opens the file with file path and flags. More...
 
bool Rename (const String &newFilePath)
 Renames the file with a new name. More...
 
bool SetCursorPos (CursorPosition pos, Int64 offset=0)
 Sets the position of the cursor. More...
 
bool SetCursorPos (UInt64 offset) override
 Sets the position of the cursor. More...
 
bool SetFile (const String &filePath)
 Sets the file path. More...
 
bool SetSize (UInt64 size)
 Sets the size of the file. More...
 
Fileoperator= (const String &filePath)
 Sets the file path. More...
 
Fileoperator= (const File &)=delete
 
Fileoperator= (File &&file) noexcept=default
 
- Public Member Functions inherited from Nz::Stream
 Stream (const Stream &)=default
 
 Stream (Stream &&)=default
 
virtual ~Stream ()
 Destructs the object.
 
void EnableTextMode (bool textMode)
 Enables the text mode. More...
 
void Flush ()
 Flushes the stream. More...
 
OpenModeFlags GetOpenMode () const
 Gets the open mode of the stream. More...
 
StreamOptionFlags GetStreamOptions () const
 Gets the options of the stream. More...
 
std::size_t Read (void *buffer, std::size_t size)
 Reads the stream and puts the result in a buffer. More...
 
virtual String ReadLine (unsigned int lineSize=0)
 Reads a line from the stream. More...
 
bool IsReadable () const
 Checks whether the stream is readable. More...
 
bool IsSequential () const
 Checks whether the stream is sequential. More...
 
bool IsTextModeEnabled () const
 Checks whether the stream has text mode enabled. More...
 
bool IsWritable () const
 Checks whether the stream can be written. More...
 
bool Write (const ByteArray &byteArray)
 Writes a ByteArray into the stream. More...
 
bool Write (const String &string)
 Writes a String into the stream. More...
 
std::size_t Write (const void *buffer, std::size_t size)
 Writes in the stream the content of a buffer. More...
 
Streamoperator= (const Stream &)=default
 
Streamoperator= (Stream &&)=default
 

Static Public Member Functions

static String AbsolutePath (const String &filePath)
 Gets the absolute path of the file. More...
 
static ByteArray ComputeHash (HashType hash, const String &filePath)
 Computes the hash for the file. More...
 
static ByteArray ComputeHash (AbstractHash *hash, const String &filePath)
 Computes the hash for the file. More...
 
static bool Copy (const String &sourcePath, const String &targetPath)
 Copies the first file to a new file path. More...
 
static bool Delete (const String &filePath)
 Deletes the file. More...
 
static bool Exists (const String &filePath)
 Checks whether the file exists. More...
 
static time_t GetCreationTime (const String &filePath)
 Gets the creation time of the file. More...
 
static String GetDirectory (const String &filePath)
 Gets the directory of the file. More...
 
static time_t GetLastAccessTime (const String &filePath)
 Gets the last time the file was accessed. More...
 
static time_t GetLastWriteTime (const String &filePath)
 Gets the last time the file was written. More...
 
static UInt64 GetSize (const String &filePath)
 Gets the size of the file. More...
 
static bool IsAbsolute (const String &filePath)
 Checks whether the file path is absolute. More...
 
static String NormalizePath (const String &filePath)
 Normalizes the file path. More...
 
static String NormalizeSeparators (const String &filePath)
 Normalizes the path separator. More...
 
static bool Rename (const String &sourcePath, const String &targetPath)
 Renames the file with a new name. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Nz::Stream
 Stream (StreamOptionFlags streamOptions=StreamOption_None, OpenModeFlags openMode=OpenMode_NotOpen)
 Constructs a Stream object with options. More...
 
virtual void FlushStream ()=0
 
- Protected Attributes inherited from Nz::Stream
OpenModeFlags m_openMode
 
StreamOptionFlags m_streamOptions
 

Detailed Description

Core class that represents a file.

Constructor & Destructor Documentation

◆ File() [1/2]

Nz::File::File ( const String filePath)

Constructs a File object with a file path.

Parameters
filePathPath to the file

◆ File() [2/2]

Nz::File::File ( const String filePath,
OpenModeFlags  openMode 
)

Constructs a File object with a file path and flags.

Parameters
filePathPath to the file
openModeFlag of the file

◆ ~File()

Nz::File::~File ( )

Destructs the object and calls Close.

See also
Close

Member Function Documentation

◆ AbsolutePath()

String Nz::File::AbsolutePath ( const String filePath)
static

Gets the absolute path of the file.

Returns
Absolute path of the file
Parameters
filePathPath of the file
Remarks
Produces a NazaraError if filePath is weird with NAZARA_PLATFORM_WINDOWS defined

◆ ComputeHash() [1/2]

ByteArray Nz::File::ComputeHash ( HashType  hash,
const String filePath 
)
inlinestatic

Computes the hash for the file.

Returns
ByteArray represing the result of the hash of the file
Parameters
hashHash to execute
filePathPath for the file

◆ ComputeHash() [2/2]

ByteArray Nz::File::ComputeHash ( AbstractHash hash,
const String filePath 
)
inlinestatic

Computes the hash for the file.

Returns
ByteArray represing the result of the hash of the file
Parameters
hashHash to execute
filePathPath for the file

◆ Copy() [1/2]

bool Nz::File::Copy ( const String newFilePath)

Copies this file to a new file path.

Returns
true if copy is successful
Parameters
newFilePathPath of the new file

◆ Copy() [2/2]

bool Nz::File::Copy ( const String sourcePath,
const String targetPath 
)
static

Copies the first file to a new file path.

Returns
true if copy is successful
Parameters
sourcePathPath of the original file
targetPathPath of the copied file

◆ Delete() [1/2]

bool Nz::File::Delete ( )

Deletes the file.

Returns
true if delete is successful

◆ Delete() [2/2]

bool Nz::File::Delete ( const String filePath)
static

Deletes the file.

Returns
true if delete is successful
Parameters
filePathPath of the file

◆ EndOfFile()

bool Nz::File::EndOfFile ( ) const

Checks whether the file has reached the end.

Returns
true if cursor is at the end of the file
Remarks
Produces a NazaraError if file is not open with NAZARA_CORE_SAFE defined

◆ EndOfStream()

bool Nz::File::EndOfStream ( ) const
overridevirtual

Checks whether the file has reached the end of the stream.

Returns
true if cursor is at the end of the file
Remarks
Produces a NazaraError if file is not open with NAZARA_CORE_SAFE defined
See also
EndOfFile

Implements Nz::Stream.

◆ Exists() [1/2]

bool Nz::File::Exists ( ) const

Checks whether the file exists.

Returns
true if file exists

◆ Exists() [2/2]

bool Nz::File::Exists ( const String filePath)
static

Checks whether the file exists.

Returns
true if file exists
Parameters
filePathPath of the file

◆ GetCreationTime() [1/2]

time_t Nz::File::GetCreationTime ( ) const

Gets the creation time of the file.

Returns
Information about the creation time

◆ GetCreationTime() [2/2]

time_t Nz::File::GetCreationTime ( const String filePath)
static

Gets the creation time of the file.

Returns
Information about the creation time
Parameters
filePathPath of the file

◆ GetCursorPos()

UInt64 Nz::File::GetCursorPos ( ) const
overridevirtual

Gets the position of the cursor in the file.

Returns
Position of the cursor
Remarks
Produces a NazaraAssert if file is not open

Implements Nz::Stream.

◆ GetDirectory() [1/2]

String Nz::File::GetDirectory ( ) const
overridevirtual

Gets the directory of the file.

Returns
Directory of the file

Reimplemented from Nz::Stream.

◆ GetDirectory() [2/2]

String Nz::File::GetDirectory ( const String filePath)
static

Gets the directory of the file.

Returns
Directory of the file
Parameters
filePathPath of the file

◆ GetFileName()

String Nz::File::GetFileName ( ) const

Gets the name of the file.

Returns
Name of the file

◆ GetLastAccessTime() [1/2]

time_t Nz::File::GetLastAccessTime ( ) const

Gets the last time the file was accessed.

Returns
Information about the last access time

◆ GetLastAccessTime() [2/2]

time_t Nz::File::GetLastAccessTime ( const String filePath)
static

Gets the last time the file was accessed.

Returns
Information about the last access time
Parameters
filePathPath of the file

◆ GetLastWriteTime() [1/2]

time_t Nz::File::GetLastWriteTime ( ) const

Gets the last time the file was written.

Returns
Information about the last writing time

◆ GetLastWriteTime() [2/2]

time_t Nz::File::GetLastWriteTime ( const String filePath)
static

Gets the last time the file was written.

Returns
Information about the last writing time
Parameters
filePathPath of the file

◆ GetPath()

String Nz::File::GetPath ( ) const
overridevirtual

Gets the path of the file.

Returns
Path of the file

Reimplemented from Nz::Stream.

◆ GetSize() [1/2]

UInt64 Nz::File::GetSize ( ) const
overridevirtual

Gets the size of the file.

Returns
Size of the file

Implements Nz::Stream.

◆ GetSize() [2/2]

UInt64 Nz::File::GetSize ( const String filePath)
static

Gets the size of the file.

Returns
Size of the file
Parameters
filePathPath of the file

◆ IsAbsolute()

bool Nz::File::IsAbsolute ( const String filePath)
static

Checks whether the file path is absolute.

Returns
true if path is absolute
Parameters
filePathPath to test

◆ IsOpen()

bool Nz::File::IsOpen ( ) const

Checks whether the file is open.

Returns
true if open

◆ NormalizePath()

String Nz::File::NormalizePath ( const String filePath)
static

Normalizes the file path.

Returns
Path normalized (replacing '/' with '\' on Windows, ...)
Parameters
filePathPath to normalize

◆ NormalizeSeparators()

String Nz::File::NormalizeSeparators ( const String filePath)
static

Normalizes the path separator.

Returns
Path normalized (replacing '/' with '\' on Windows, ...)
Parameters
filePathPath to normalize

◆ Open() [1/2]

bool Nz::File::Open ( OpenModeFlags  openMode = OpenMode_NotOpen)

Opens the file with flags.

Returns
true if opening is successful
Parameters
openModeFlag for file
Remarks
Produces a NazaraError if OS error to open a file

◆ Open() [2/2]

bool Nz::File::Open ( const String filePath,
OpenModeFlags  openMode = OpenMode_NotOpen 
)

Opens the file with file path and flags.

Returns
true if opening is successful
Parameters
filePathPath to the file
openModeFlag for file
Remarks
Produces a NazaraError if OS error to open a file

◆ operator=()

File & Nz::File::operator= ( const String filePath)

Sets the file path.

Returns
A reference to this
Remarks
Produces a NazaraError if file path can not be open

◆ Rename() [1/2]

bool Nz::File::Rename ( const String newFilePath)

Renames the file with a new name.

Returns
true if rename is successful

◆ Rename() [2/2]

bool Nz::File::Rename ( const String sourcePath,
const String targetPath 
)
static

Renames the file with a new name.

Returns
true if rename is successful
Parameters
sourcePathPath of the original file
targetPathPath of the renamed file

◆ SetCursorPos() [1/2]

bool Nz::File::SetCursorPos ( CursorPosition  pos,
Int64  offset = 0 
)

Sets the position of the cursor.

Returns
true if cursor is successfully positioned
Parameters
posPosition of the cursor
offsetOffset according to the cursor position
Remarks
Produces a NazaraAssert if file is not open

◆ SetCursorPos() [2/2]

bool Nz::File::SetCursorPos ( UInt64  offset)
overridevirtual

Sets the position of the cursor.

Returns
true if cursor is successfully positioned
Parameters
offsetOffset according to the cursor begin position
Remarks
Produces a NazaraAssert if file is not open

Implements Nz::Stream.

◆ SetFile()

bool Nz::File::SetFile ( const String filePath)

Sets the file path.

Returns
true if file opening is successful
Remarks
Produces a NazaraError if file path can not be open

◆ SetSize()

bool Nz::File::SetSize ( UInt64  size)

Sets the size of the file.

Returns
true if the file size has correctly changed
Parameters
sizeThe size the file should have after this call
Remarks
The cursor position is not affected by this call
The file must be open in write mode

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