fennec
Loading...
Searching...
No Matches
fennec::file

Structure for handling streams of data. More...

#include <file.h>

Detailed Description

operations, when errored, will return a corresponding error. Use file::get_error() to check if an error is present and return a corresponding string. Use file::clear_error() to clear the errored state. Some operations, specifically file::rename() and file::copy().

Public Member Functions

 file ()
 default constructor, initializes an empty stream
 
 ~file ()
 default destructor, cleans up an open stream
 
 file (file &&file) noexcept
 move constructor
 
const pathget_path () const
 
uint8_t mode () const
 
bool is_open () const
 
bool open (const cstring &path, uint8_t mode)
 open a file
 
bool open (const string &path, uint8_t mode)
 open a file
 
bool open (const path &path, uint8_t mode)
 open a file
 
bool close ()
 close a stream
 
bool commit ()
 commit the streams buffer to the file
 
bool erase ()
 closes the stream and erases the file
 
bool rename (const cstring &path)
 rebinds the stream, copying contents to path, and erasing the old file
 
bool rename (const string &path)
 rebinds the stream, copying contents to path, and erasing the old file
 
bool rename (const path &path)
 rebinds the stream, copying contents to path, and erasing the old file
 
file copy (const cstring &path)
 copies the contents of this file to path.
 
file copy (const string &path)
 copies the contents of this file to path.
 
file copy (const path &path)
 copies the contents of this file to path.
 

Static Public Member Functions

static constexpr bool is_valid (uint8_t mode)
 Check if the provided mode bitflags are a valid combination.
 
static filecout ()
 
static filecin ()
 
static filecerr ()
 

Static Public Attributes

static constexpr size_t npos = -1
 value of an invalid position
 

Constructor & Destructor Documentation

◆ file()

fennec::file::file ( file &&  file)
noexcept
Parameters
filethe stream to take ownership of

Member Function Documentation

◆ is_valid()

static constexpr bool fennec::file::is_valid ( uint8_t  mode)
inlinestaticconstexpr
Parameters
modethe bitfield
Returns
true if the combination of flags is valid, false otherwise

◆ cout()

file & fennec::file::cout ( )
static
Returns
the c stdout

◆ cin()

file & fennec::file::cin ( )
static
Returns
the c stdin

◆ cerr()

file & fennec::file::cerr ( )
static
Returns
the c stderr

◆ get_path()

const path & fennec::file::get_path ( ) const
inline
Returns
the path the stream

◆ mode()

uint8_t fennec::file::mode ( ) const
inline
Returns
the mode of the stream

◆ is_open()

bool fennec::file::is_open ( ) const
inline
Returns
true if there is a valid, open stream.

◆ open() [1/3]

bool fennec::file::open ( const cstring path,
uint8_t  mode 
)
Parameters
paththe path to the file
modethe mode flags to open the file with
Returns
false on success, true on error

◆ open() [2/3]

bool fennec::file::open ( const string path,
uint8_t  mode 
)
Parameters
paththe path to the file
modethe mode flags to open the file with
Returns
false on success, true on error

◆ open() [3/3]

bool fennec::file::open ( const path path,
uint8_t  mode 
)
Parameters
paththe path to the file
modethe mode flags to open the file with
Returns
false on success, true on error

◆ close()

bool fennec::file::close ( )
Returns
false on success, true on error

◆ commit()

bool fennec::file::commit ( )
Returns
false on success, true on error

◆ erase()

bool fennec::file::erase ( )
Returns
false on success, true on error

◆ rename() [1/3]

bool fennec::file::rename ( const cstring path)
Parameters
paththe new path
Returns
false on success, true on error

attempts to open a write-only stream at path, attempts to reopen this file as read-only, copies the contents of this file to the new stream, reopen the new stream with the flags of this file and binds to it, closes the old file.

◆ rename() [2/3]

bool fennec::file::rename ( const string path)
Parameters
paththe new path
Returns
false on success, true on error

attempts to open a write-only stream at path, attempts to reopen this file as read-only, copies the contents of this file to the new stream, reopen the new stream with the flags of this file and binds to it, closes the old file.

◆ rename() [3/3]

bool fennec::file::rename ( const path path)
Parameters
paththe new path
Returns
false on success, true on error

attempts to open a write-only stream at path, attempts to reopen this file as read-only, copies the contents of this file to the new stream, reopen the new stream with the flags of this file and binds to it, closes the old file.

◆ copy() [1/3]

file fennec::file::copy ( const cstring path)
Parameters
paththe path to copy to
Returns
a file at the new path with the copied contents

◆ copy() [2/3]

file fennec::file::copy ( const string path)
Parameters
paththe path to copy to
Returns
a file at the new path with the copied contents

◆ copy() [3/3]

file fennec::file::copy ( const path path)
Parameters
paththe path to copy to
Returns
a file at the new path with the copied contents

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