![]() |
Scanframe Modular Application 0.1.0
|
#include <File.h>
Public Types | |
typedef struct stat | stat_type |
Public Member Functions | |
File () | |
File (const std::filesystem::path &path, int flags=O_CREAT|O_RDWR|O_APPEND, mode_t mode=S_IREAD|S_IWRITE|S_IRGRP|S_IWGRP) | |
~File () | |
void | initialize (const std::filesystem::path &path, int flags=O_CREAT|O_RDWR|O_APPEND, mode_t mode=S_IREAD|S_IWRITE|S_IRGRP|S_IWGRP) |
void | open (const std::string &path, int flags=O_CREAT|O_RDWR|O_APPEND, mode_t mode=S_IREAD|S_IWRITE|S_IRGRP|S_IWGRP) |
void | createTemporary (const std::string &name_tpl, int flags=O_CREAT|O_RDWR) |
void | allocate (size_t sz) |
void | open (bool reopen=false) |
bool | isOpen () const |
void | close () |
bool | close (bool exceptions) |
void | write (const File &f, size_t pos, size_t sz, size_t buf_sz=0) |
void | write (const void *buf, size_t sz, size_t *written=nullptr) |
void | write (const std::string &s) |
void | write (const char *s) |
template<typename T > | |
void | write (const T &t) |
ssize_t | read (void *buf, size_t pos, size_t sz) const |
void | read (DynamicBuffer buf, size_t pos, size_t sz) const |
template<typename T > | |
void | read (T &t, size_t pos) const |
void | getStat (stat_type &stat) const |
const stat_type & | getStatus () const |
const stat_type & | getStatus (bool update) |
std::string | getStatText () const |
void | rename (const std::string &path, bool assign=false) |
void | truncate (size_t length) |
void | remove () |
void | synchronise () |
std::string | getPath () const |
mode_t | getMode () const |
int | getFlags () const |
int | getDescriptor () const |
bool | exists () |
void | unlink () |
Implements a file handling class around a file descriptor.
typedef struct stat sf::lnx::File::stat_type |
Local simple type definition for statistics.
sf::lnx::File::File | ( | ) |
Default constructor.
|
explicit |
Initialization constructor.
sf::lnx::File::~File | ( | ) |
Destructor.
void sf::lnx::File::allocate | ( | size_t | sz | ) |
Allocates disk space for the file.
sz |
|
inline |
When open it closes the file. Throws an exception on failure to close when open.
bool sf::lnx::File::close | ( | bool | exceptions | ) |
When exceptions flag is false no exceptions are thrown. Useful when closing a file in destructors or exception cleanup.
void sf::lnx::File::createTemporary | ( | const std::string & | name_tpl, |
int | flags = O_CREAT|O_RDWR |
||
) |
Opens the file using a template path with flags. Flags O_CREAT and O_RDWR are always implied. Throws an exception on failure.
bool sf::lnx::File::exists | ( | ) |
Check if the file exist.
|
inline |
Returns the file descriptor.
|
inline |
Returns the flags of the opened files.
|
inline |
Returns the mode of the opened file.
|
inline |
Returns the path of the opened file.
void sf::lnx::File::getStat | ( | stat_type & | stat | ) | const |
Returns the stats of the file descriptor. Throws an exception on an error.
std::string sf::lnx::File::getStatText | ( | ) | const |
Returns the TStats struct as a meaningful text.
|
inline |
Returns the stat info structure on the opened file.
|
inline |
Returns the stat info structure on the opened file. When update is true the data is refreshed. Throws an exception on an error on doing so.
void sf::lnx::File::initialize | ( | const std::filesystem::path & | path, |
int | flags = O_CREAT|O_RDWR|O_APPEND , |
||
mode_t | mode = S_IREAD|S_IWRITE|S_IRGRP|S_IWGRP |
||
) |
Initializes this instance without opening the actual file or closes an open file. Throws an exception on failure.
|
inline |
Checks if the file is opened.
void sf::lnx::File::open | ( | bool | reopen = false | ) |
Opens a closed file using the same parameters. Throws an exception on failure.
void sf::lnx::File::open | ( | const std::string & | path, |
int | flags = O_CREAT|O_RDWR|O_APPEND , |
||
mode_t | mode = S_IREAD|S_IWRITE|S_IRGRP|S_IWGRP |
||
) |
Opens the file using the path, flags and mode. Throws an exception on failure.
void sf::lnx::File::read | ( | DynamicBuffer | buf, |
size_t | pos, | ||
size_t | sz | ||
) | const |
Reads data into a dynamic buffer,
buf | |
pos | |
sz |
|
inline |
Reads data into a structure.
T | Type of the structure. |
t | |
pos | File position. |
ssize_t sf::lnx::File::read | ( | void * | buf, |
size_t | pos, | ||
size_t | sz | ||
) | const |
Reads from the file and returns the actual amount read. Throws an exception in case of an error.
void sf::lnx::File::remove | ( | ) |
Closes an open file and Removes/Unlinks the current file. Throws an exception on an error on doing so.
void sf::lnx::File::rename | ( | const std::string & | path, |
bool | assign = false |
||
) |
Rename the current file and updates the path member when assign is true. Throws an exception on an error on doing so.
void sf::lnx::File::synchronise | ( | ) |
Syncs the current file.
void sf::lnx::File::truncate | ( | size_t | length | ) |
Truncates the file and can be performed on the open or closed file. Throws an exception on an error.
void sf::lnx::File::unlink | ( | ) |
Removes the file wen it exist.
|
inline |
void sf::lnx::File::write | ( | const File & | f, |
size_t | pos, | ||
size_t | sz, | ||
size_t | buf_sz = 0 |
||
) |
Writes data from the passed file into this file. When the buffer 'buf_sz' size is zero a default value is used in which the data is copied in chunks.
|
inline |
|
inline |
read template function
T | Type of the structure written. |
t |
void sf::lnx::File::write | ( | const void * | buf, |
size_t | sz, | ||
size_t * | written = nullptr |
||
) |
Writes a buffer to a file descriptor reporting errors when they occurred. Throws an exception on an error.