Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
sf::lnx::File Class Reference

#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_typegetStatus () const
 
const stat_typegetStatus (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 ()
 

Detailed Description

Implements a file handling class around a file descriptor.

Member Typedef Documentation

◆ stat_type

typedef struct stat sf::lnx::File::stat_type

Local simple type definition for statistics.

Constructor & Destructor Documentation

◆ File() [1/2]

sf::lnx::File::File ( )

Default constructor.

◆ File() [2/2]

sf::lnx::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 
)
explicit

Initialization constructor.

◆ ~File()

sf::lnx::File::~File ( )

Destructor.

Member Function Documentation

◆ allocate()

void sf::lnx::File::allocate ( size_t  sz)

Allocates disk space for the file.

Parameters
sz

◆ close() [1/2]

void sf::lnx::File::close ( )
inline

When open it closes the file. Throws an exception on failure to close when open.

◆ close() [2/2]

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.

◆ createTemporary()

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.

◆ exists()

bool sf::lnx::File::exists ( )

Check if the file exist.

Returns

◆ getDescriptor()

int sf::lnx::File::getDescriptor ( ) const
inline

Returns the file descriptor.

◆ getFlags()

int sf::lnx::File::getFlags ( ) const
inline

Returns the flags of the opened files.

◆ getMode()

mode_t sf::lnx::File::getMode ( ) const
inline

Returns the mode of the opened file.

◆ getPath()

std::string sf::lnx::File::getPath ( ) const
inline

Returns the path of the opened file.

◆ getStat()

void sf::lnx::File::getStat ( stat_type stat) const

Returns the stats of the file descriptor. Throws an exception on an error.

◆ getStatText()

std::string sf::lnx::File::getStatText ( ) const

Returns the TStats struct as a meaningful text.

◆ getStatus() [1/2]

const File::stat_type & sf::lnx::File::getStatus ( ) const
inline

Returns the stat info structure on the opened file.

◆ getStatus() [2/2]

const File::stat_type & sf::lnx::File::getStatus ( bool  update)
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.

◆ initialize()

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.

◆ isOpen()

bool sf::lnx::File::isOpen ( ) const
inline

Checks if the file is opened.

Returns
True when the file is open.

◆ open() [1/2]

void sf::lnx::File::open ( bool  reopen = false)

Opens a closed file using the same parameters. Throws an exception on failure.

◆ open() [2/2]

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.

◆ read() [1/3]

void sf::lnx::File::read ( DynamicBuffer  buf,
size_t  pos,
size_t  sz 
) const

Reads data into a dynamic buffer,

Parameters
buf
pos
sz

◆ read() [2/3]

template<typename T >
void sf::lnx::File::read ( T &  t,
size_t  pos 
) const
inline

Reads data into a structure.

Template Parameters
TType of the structure.
Parameters
t
posFile position.

◆ read() [3/3]

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.

◆ remove()

void sf::lnx::File::remove ( )

Closes an open file and Removes/Unlinks the current file. Throws an exception on an error on doing so.

◆ rename()

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.

◆ synchronise()

void sf::lnx::File::synchronise ( )

Syncs the current file.

◆ truncate()

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.

◆ unlink()

void sf::lnx::File::unlink ( )

Removes the file wen it exist.

◆ write() [1/5]

void sf::lnx::File::write ( const char *  s)
inline

◆ write() [2/5]

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.

◆ write() [3/5]

void sf::lnx::File::write ( const std::string &  s)
inline

◆ write() [4/5]

template<typename T >
void sf::lnx::File::write ( const T &  t)
inline

read template function

Template Parameters
TType of the structure written.
Parameters
t

◆ write() [5/5]

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.


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