lfilesystem
0.0.1
C++ filesystem library
|
This class is a wrapper around a C-style FILE*
that takes care of freeing the file when the object is destroyed, and provides a few other convenience methods.
More...
#include <lfilesystem_CFile.h>
Public Types | |
enum class | Mode { Read , Write , Append , ReadExtended , WriteExtended , AppendExtended } |
Represents possible modes a file can be opened in. More... | |
Public Member Functions | |
CFile (const CFile &)=delete | |
~CFile () noexcept | |
Destructor. More... | |
void | close () noexcept |
If the file is currently open, this closes it by calling fclose() . More... | |
File | getFile () const |
Returns a File object representing this file. More... | |
bool | isOpen () const noexcept |
Returns true if the file is currently open. More... | |
bool | open (const Path &filepath, Mode mode) noexcept |
Closes the current file (if one is open) and opens the file at the specified path. More... | |
operator bool () const noexcept | |
Evaluates to true if the file is currently open. More... | |
CFile & | operator= (CFile &&other) noexcept |
Move assignment operator. More... | |
CFile & | operator= (const CFile &)=delete |
Constructors | |
CFile ()=default | |
Creates a default CFile that holds a nullptr. More... | |
CFile (std::FILE *fileHandle) noexcept | |
Creates a CFile that takes ownership of the passed FILE* . More... | |
CFile (const Path &filepath, Mode mode) noexcept | |
Creates a CFile referencing the given filepath, in the given mode. More... | |
CFile (CFile &&other) noexcept | |
Move constructor. More... | |
Accessors | |
std::FILE * | get () const noexcept |
Returns the pointer this object holds. More... | |
std::FILE * | operator-> () const noexcept |
Returns the pointer this object holds. More... | |
std::FILE & | operator* () const |
Dereferences the pointer this object holds. More... | |
Path | getPath () const |
Returns the path of the file this object represents. More... | |
operator std::FILE * () const noexcept | |
Returns the pointer held by this object. More... | |
Static Public Member Functions | |
static CFile | createTempFile () |
Creates an automatically named, self-deleting temporary file using the C function std::tmpfile . More... | |
This class is a wrapper around a C-style FILE*
that takes care of freeing the file when the object is destroyed, and provides a few other convenience methods.
This class is intended as a way to allow interfacing with C APIs that require a FILE*
while maintaining RAII-style resource management.
For example:
Definition at line 50 of file lfilesystem_CFile.h.
|
strong |
Represents possible modes a file can be opened in.
Definition at line 54 of file lfilesystem_CFile.h.
|
default |
|
explicitnoexcept |
|
noexcept |
Move constructor.
|
noexcept |
Destructor.
If the file is open when the destructor is called, the destructor will close the file.
|
noexcept |
|
static |
Creates an automatically named, self-deleting temporary file using the C function std::tmpfile
.
|
noexcept |
Returns the pointer this object holds.
Note that the CFile object still retains ownership of this pointer, you should not free it!
File limes::files::CFile::getFile | ( | ) | const |
Path limes::files::CFile::getPath | ( | ) | const |
Returns the path of the file this object represents.
Returns an empty path if no file is currently open.
|
noexcept |
Returns true if the file is currently open.
Closes the current file (if one is open) and opens the file at the specified path.
fopen()
is called to open the file.
|
explicitnoexcept |
Evaluates to true if the file is currently open.
|
noexcept |
Returns the pointer held by this object.
std::FILE& limes::files::CFile::operator* | ( | ) | const |
Dereferences the pointer this object holds.
Note that the pointer may be null, so be careful!
|
noexcept |
Returns the pointer this object holds.