MxEngine
Public Types | Public Member Functions | Static Public Member Functions | List of all members
MxEngine::File Class Reference

#include <File.h>

Public Types

enum  FileMode { READ = 0x1, WRITE = 0x2, BINARY = 0x4 }
 
using FileData = MxString
 

Public Member Functions

 File ()=default
 
 File (const FilePath &path, int mode=FileMode::READ)
 
 File (const MxString &path, int mode=FileMode::READ)
 
 File (const char *path, int mode=FileMode::READ)
 
 File (const File &)=default
 
 File (File &&)=default
 
Fileoperator= (const File &)=default
 
Fileoperator= (File &&)=default
 
FileStream & GetStream ()
 
bool IsOpen () const
 
void Open (FilePath path, int mode=FileMode::READ)
 
void Open (const MxString &path, int mode=FileMode::READ)
 
void Open (const char *path, int mode=FileMode::READ)
 
void Close ()
 
FileData ReadAllText ()
 
const FilePath & GetPath () const
 
template<typename T >
Fileoperator>> (T &&value)
 
template<typename T >
Fileoperator<< (T &&value)
 
void WriteBytes (const uint8_t *bytes, size_t size)
 

Static Public Member Functions

static FileData ReadAllText (const FilePath &path)
 
static FileData ReadAllText (const MxString &path)
 
static FileData ReadAllText (const char *path)
 
static bool Exists (const FilePath &path)
 
static bool Exists (const MxString &path)
 
static bool Exists (const char *path)
 
static bool IsFile (const MxString &path)
 
static bool IsFile (const FilePath &path)
 
static bool IsFile (const char *path)
 
static bool IsDirectory (const MxString &path)
 
static bool IsDirectory (const FilePath &path)
 
static bool IsDirectory (const char *path)
 
static FileSystemTime LastModifiedTime (const FilePath &path)
 
static FileSystemTime LastModifiedTime (const MxString &path)
 
static FileSystemTime LastModifiedTime (const char *path)
 
static void CreateDirectory (const FilePath &path)
 
static void CreateDirectory (const MxString &path)
 
static void CreateDirectory (const char *path)
 

Detailed Description

File is an abstraction over std::fstream object and std::filesystem::path. It caches data, searches files and used for reading/writing binat and text data. Note: consider using Script class for files which are frequently updated by user

Member Enumeration Documentation

§ FileMode

mode is used to specify how to treat opened file. Use binary OR ( | ) to compine mods

Constructor & Destructor Documentation

§ File() [1/4]

MxEngine::File::File ( )
default

creates empty file object (empty stream, empty path)

§ File() [2/4]

MxEngine::File::File ( const FilePath &  path,
int  mode = FileMode::READ 
)

creates file object and opens fstream

Parameters
pathpath to a file
modehow to treat file (see FileMode documentation)

§ File() [3/4]

MxEngine::File::File ( const MxString &  path,
int  mode = FileMode::READ 
)

creates file object and opens fstream

Parameters
pathpath to a file (absolute or relative to executable directory)
modehow to treat file (see FileMode documentation)

§ File() [4/4]

MxEngine::File::File ( const char *  path,
int  mode = FileMode::READ 
)

creates file object and opens fstream

Parameters
pathpath to a file (absolute or relative to executable directory)
modehow to treat file (see FileMode documentation)

Member Function Documentation

§ Exists() [1/3]

bool MxEngine::File::Exists ( const FilePath &  path)
static

checks if file exists

Parameters
pathpath of file to search for
Returns
true if file exists, false either

§ Exists() [2/3]

bool MxEngine::File::Exists ( const MxString &  path)
static

checks if file exists

Parameters
pathpath of file to search for
Returns
true if file exists, false either

§ Exists() [3/3]

bool MxEngine::File::Exists ( const char *  path)
static

checks if file exists

Parameters
pathpath of file to search for
Returns
true if file exists, false either

§ GetPath()

const FilePath & MxEngine::File::GetPath ( ) const

gets current path associated with File object

Returns
path to a file

§ GetStream()

FileStream & MxEngine::File::GetStream ( )

fileStream member getter

Returns
underlying std::fstream object

§ IsDirectory() [1/3]

bool MxEngine::File::IsDirectory ( const MxString &  path)
static

checks if path is directory

Parameters
pathpath to search for
Returns
true if path is directory, false either

§ IsDirectory() [2/3]

bool MxEngine::File::IsDirectory ( const FilePath &  path)
static

checks if path is directory

Parameters
pathpath to search for
Returns
true if path is directory, false either

§ IsDirectory() [3/3]

bool MxEngine::File::IsDirectory ( const char *  path)
static

checks if path is directory

Parameters
pathpath to search for
Returns
true if path is directory, false either

§ IsFile() [1/3]

bool MxEngine::File::IsFile ( const MxString &  path)
static

checks if path is regular file

Parameters
pathpath of file to search for
Returns
true if path is regular file, false either

§ IsFile() [2/3]

bool MxEngine::File::IsFile ( const FilePath &  path)
static

checks if path is regular file

Parameters
pathpath of file to search for
Returns
true if path is regular file, false either

§ IsFile() [3/3]

bool MxEngine::File::IsFile ( const char *  path)
static

checks if path is regular file

Parameters
pathpath of file to search for
Returns
true if path is regular file, false either

§ IsOpen()

bool MxEngine::File::IsOpen ( ) const

checks if current file is open or not

§ LastModifiedTime() [1/3]

FileSystemTime MxEngine::File::LastModifiedTime ( const FilePath &  path)
static

gets file last modified time

Parameters
pathpath to a file to check for
Returns
platform-dependent time point of last file modification

§ LastModifiedTime() [2/3]

FileSystemTime MxEngine::File::LastModifiedTime ( const MxString &  path)
static

gets file last modified time

Parameters
pathpath to a file to check for
Returns
platform-dependent time point of last file modification

§ LastModifiedTime() [3/3]

FileSystemTime MxEngine::File::LastModifiedTime ( const char *  path)
static

gets file last modified time

Parameters
pathpath to a file to check for
Returns
platform-dependent time point of last file modification

§ Open() [1/3]

void MxEngine::File::Open ( FilePath  path,
int  mode = FileMode::READ 
)

opens new file, old file associated with File is closed automatically

Parameters
pathpath to a file
modehow to treat file (see FileMode documentation)

§ Open() [2/3]

void MxEngine::File::Open ( const MxString &  path,
int  mode = FileMode::READ 
)

opens new file, old file associated with File is closed automatically

Parameters
pathpath to a file (absolute or relative to executable directory)
modehow to treat file (see FileMode documentation)

§ Open() [3/3]

void MxEngine::File::Open ( const char *  path,
int  mode = FileMode::READ 
)

opens new file, old file associated with File is closed automatically

Parameters
pathpath to a file (absolute or relative to executable directory)
modehow to treat file (see FileMode documentation)

§ operator<<()

template<typename T >
File & MxEngine::File::operator<< ( T &&  value)
inline

writes data of type T to a file

Parameters
valuevalue to write to

§ operator>>()

template<typename T >
File & MxEngine::File::operator>> ( T &&  value)
inline

reads data from a file and treats it as T type

Parameters
valuevalue to read to

§ ReadAllText() [1/4]

File::FileData MxEngine::File::ReadAllText ( )

reads all data from file into string object. File must be opened for read and NOT binary

Returns
file contents as string. If file is not opened returns empty string

§ ReadAllText() [2/4]

File::FileData MxEngine::File::ReadAllText ( const FilePath &  path)
static

creates temporary File object and reads its data into string.

Parameters
pathpath to a file
Returns
file contents as string. If file is not opened / not exists returns empty string

§ ReadAllText() [3/4]

File::FileData MxEngine::File::ReadAllText ( const MxString &  path)
static

creates temporary File object and reads its data into string.

Parameters
pathpath to a file (absolute or relative to executable directory)
Returns
file contents as string. If file is not opened / not exists returns empty string

§ ReadAllText() [4/4]

File::FileData MxEngine::File::ReadAllText ( const char *  path)
static

creates temporary File object and reads its data into string.

Parameters
pathpath to a file (absolute or relative to executable directory)
Returns
file contents as string. If file is not opened / not exists returns empty string

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