MeteoIODoc 20261119.86f8ff36
Environmental timeseries pre-processing
Loading...
Searching...
No Matches
mio::ifilestream Class Reference

Detailed Description

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.

Author
Mathias Bavay
Date
2024-03-25

#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
 

Constructor & Destructor Documentation

◆ ifilestream() [1/3]

mio::ifilestream::ifilestream ( )
inline

◆ ifilestream() [2/3]

mio::ifilestream::ifilestream ( const char *  filename,
std::ios_base::openmode  mode = std::ios_base::in,
const size_t &  buffer_size = default_buffer_size 
)

Constructor.

Parameters
filenamefile to read
modemode to open the file in
buffer_sizesize of the read buffer (in bytes), 0 to keep the standard library's default buffering

◆ ifilestream() [3/3]

mio::ifilestream::ifilestream ( const std::string &  filename,
std::ios_base::openmode  mode = std::ios_base::in,
const size_t &  buffer_size = default_buffer_size 
)

Member Function Documentation

◆ open()

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.

Parameters
filenamefile to read
modemode to open the file in
buffer_sizesize of the read buffer (in bytes), 0 to keep the standard library's default buffering

Member Data Documentation

◆ default_buffer_size

constexpr size_t mio::ifilestream::default_buffer_size = 4u << 20
staticconstexpr

default read buffer size: 4 MiB


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