omw
0.2.1-beta
|
Public Types | |
using | fstream = std::fstream |
using | iostate = fstream::iostate |
using | openmode = fstream::openmode |
Public Member Functions | |
FileInterface_Base (const std::string &filename) | |
const omw::string & | filename () const |
void | setFileName (const std::string &filename) |
void | open (openmode mode) const |
void | openRead () const |
void | openWrite () |
void | close () const |
size_t | size () const |
void | read (char *buffer, size_t count) const |
void | write (const char *data) |
void | write (const char *data, size_t count) |
iostate | getState () const |
Static Public Attributes | |
static constexpr iostate | good = fstream::goodbit |
static constexpr iostate | badbit = fstream::badbit |
static constexpr iostate | failbit = fstream::failbit |
static constexpr iostate | eofbit = fstream::eofbit |
static constexpr openmode | rd = fstream::in |
static constexpr openmode | wr = fstream::out |
#include <omw/io/file.h>
Wrapper class for std::fstream
.
Alldought this method of reading and writing a file is not very efficient, it's convenient, easy to use and fine for small files.
The constness of the member functions is to let the file (because of this interface class) act like a C++ object.
using omw::io::FileInterface_Base::iostate = fstream::iostate |
Stream state type
using omw::io::FileInterface_Base::openmode = fstream::openmode |
Open mode type
void omw::io::FileInterface_Base::close | ( | ) | const |
Exceptions
fstream::failure
if an error occures omw::io::FileInterface_Base::iostate omw::io::FileInterface_Base::getState | ( | ) | const |
Returns the state flags of the file stream.
See also std::ios::rdstate()
and std::ios::iostate
.
void omw::io::FileInterface_Base::open | ( | openmode | mode | ) | const |
mode | Either FileInterface_Base::rd or FileInterface_Base::wr |
Exceptions
fstream::failure
if an error occures
|
inline |
Opens the file in read mode.
Exceptions
fstream::failure
if an error occures
|
inline |
Opens the file in write mode.
Exceptions
fstream::failure
if an error occures void omw::io::FileInterface_Base::read | ( | char * | buffer, |
size_t | count | ||
) | const |
Allways starts reading at stream position 0.
Exceptions
std::invalid_argument
if buffer is nullstd::out_of_range
see omw::io::size_to_streamsize()
std::ios::failure
thrown by
size_t omw::io::FileInterface_Base::size | ( | ) | const |
Exceptions
std::out_of_range
if the file is too big (file size can't be represented by size_t
)std::runtime_error
if the evaluated file size (std::streampos
) was negativestd::ios::failure
thrown by
void omw::io::FileInterface_Base::write | ( | const char * | str | ) |
str | Null terminated string |
Examines the string length and then passes both to omw::io::FileInterface_Base::write(const char* data, size_t count)
.
void omw::io::FileInterface_Base::write | ( | const char * | data, |
size_t | count | ||
) |
Allways starts writing at stream position 0.
Exceptions
std::invalid_argument
if data is nullstd::out_of_range
see omw::io::size_to_streamsize()
std::ios::failure
thrown by
|
staticconstexpr |
Open file in read mode
|
staticconstexpr |
Open file in write mode