matador::file Class Reference

#include <file.hpp>

Public Member Functions

 file ()=default
 
 file (const char *path, const char *mode)
 
 file (const std::string &path, const char *mode)
 
 file (const file &)=delete
 
file operator= (const file &)=delete
 
void open (const char *path, const char *mode)
 
void open (const std::string &path, const char *mode)
 
void close ()
 
size_t size () const
 
std::string path () const
 
FILE * stream () const
 
bool is_open () const
 

Detailed Description

File class representing file stream

The open methods uses internally fopen() thus the open modes are the same:

"r" read: Open file for input operations. The file must exist. "w" write: Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file. "a" append: Open file for output at the end of a file. Output operations always write data at the end of the file, expanding it. Repositioning operations (fseek, fsetpos, rewind) are ignored. The file is created if it does not exist. "r+" read/update: Open a file for update (both for input and output). The file must exist. "w+" write/update: Create an empty file and open it for update (both for input and output). If a file with the same name already exists its contents are discarded and the file is treated as a new empty file. "a+" append/update: Open a file for update (both for input and output) with all output operations writing data at the end of the file. Repositioning operations (fseek, fsetpos, rewind) affects the next input operations, but output operations move the position back to the end of file. The file is created if it does not exist.

Constructor & Destructor Documentation

◆ file() [1/3]

matador::file::file ( )
default

Creates an uninitialized file.

◆ file() [2/3]

matador::file::file ( const char *  path,
const char *  mode 
)

Creates and open a file stream.

Parameters
pathPath of the file to create
modeThe file mode to open

◆ file() [3/3]

matador::file::file ( const std::string &  path,
const char *  mode 
)

Creates and open a file stream.

Parameters
pathPath of the file to create
modeThe file mode to open

Member Function Documentation

◆ close()

void matador::file::close ( )

Closes the file stream if it is open

◆ is_open()

bool matador::file::is_open ( ) const

Returns true if file is open.

Returns
True if file is open

◆ open() [1/2]

void matador::file::open ( const char *  path,
const char *  mode 
)

Opens a file stream with the given path. If the file is already open it is closed

Parameters
pathPath of the file to create
modeThe file mode to open

◆ open() [2/2]

void matador::file::open ( const std::string &  path,
const char *  mode 
)

Opens a file stream with the given path. If the file is already open it is closed

Parameters
pathPath of the file to create
modeThe file mode to open

◆ path()

std::string matador::file::path ( ) const

Returns the path to the file

Returns
The path to the file

◆ size()

size_t matador::file::size ( ) const

Returns the size of the file

Returns
The size of the file

◆ stream()

FILE * matador::file::stream ( ) const

Returns the internal file stream pointer

Returns
The internal file stream pointer

The documentation for this class was generated from the following file:
  • matador/utils/file.hpp