|
MeteoIODoc 20261119.86f8ff36
Environmental timeseries pre-processing
|
A class that extends std::ifstream, adding sandbox validation and a large read buffer.
The default stream buffer of the standard library is quite small (8 KiB for libstdc++), which leads to a very large number of read requests when parsing a file line by line. This is not an issue on local disks but on slow network mounts (such as webdav shares mounted through FUSE) each request is a round-trip to the remote server and reading becomes extremely slow. A much larger buffer is therefore used by default, so that typical input files are read in very few requests. When only a small part of a file will be read (for example, its headers), a smaller buffer size should be provided.
#include <FStream.h>
Public Member Functions | |
| ifilestream () | |
| ifilestream (const char *filename, std::ios_base::openmode mode=std::ios_base::in, const size_t &buffer_size=default_buffer_size) | |
| Constructor. | |
| ifilestream (const std::string &filename, std::ios_base::openmode mode=std::ios_base::in, const size_t &buffer_size=default_buffer_size) | |
| void | open (const char *filename, std::ios_base::openmode mode=std::ios_base::in, const size_t &buffer_size=default_buffer_size) |
| Open a file for reading. | |
Static Public Attributes | |
| static constexpr size_t | default_buffer_size = 4u << 20 |
| default read buffer size: 4 MiB | |
|
inline |
| mio::ifilestream::ifilestream | ( | const char * | filename, |
| std::ios_base::openmode | mode = std::ios_base::in, |
||
| const size_t & | buffer_size = default_buffer_size |
||
| ) |
Constructor.
| filename | file to read |
| mode | mode to open the file in |
| buffer_size | size of the read buffer (in bytes), 0 to keep the standard library's default buffering |
| mio::ifilestream::ifilestream | ( | const std::string & | filename, |
| std::ios_base::openmode | mode = std::ios_base::in, |
||
| const size_t & | buffer_size = default_buffer_size |
||
| ) |
| void mio::ifilestream::open | ( | const char * | filename, |
| std::ios_base::openmode | mode = std::ios_base::in, |
||
| const size_t & | buffer_size = default_buffer_size |
||
| ) |
Open a file for reading.
works the same as std::ifstream::open, but checks that the file is within the sandbox (if enabled) and sets up the read buffer.
| filename | file to read |
| mode | mode to open the file in |
| buffer_size | size of the read buffer (in bytes), 0 to keep the standard library's default buffering |
|
staticconstexpr |
default read buffer size: 4 MiB