Program Listing for File file_sink.hpp
↰ Return to documentation for file (rcppsw/metrics/file_sink.hpp
)
#pragma once
/*******************************************************************************
* Includes
******************************************************************************/
#include <iosfwd>
#include <memory>
#include <string>
#include <filesystem>
#include <functional>
#include "rcppsw/metrics/base_sink.hpp"
/*******************************************************************************
* Namespaces/Decls
******************************************************************************/
namespace fs = std::filesystem;
namespace rcppsw::metrics {
/*******************************************************************************
* Class Definitions
******************************************************************************/
class file_sink : public rer::client<file_sink>,
public rmetrics::base_sink {
public:
file_sink(fs::path fpath,
const rmetrics::output_mode& mode,
const rtypes::timestep& interval);
virtual ~file_sink(void);
const fs::path& fpath(void) const { return mc_fpath; }
protected:
std::ofstream* ofile(void) { return m_ofile.get(); }
bool retry_io(const std::function<void(void)>& cb);
private:
static constexpr size_t kN_RETRIES = 10;
/* clang-format off */
const fs::path mc_fpath;
std::unique_ptr<std::ofstream> m_ofile;
/* clang-format on */
};
} /* namespace rcppsw::metrics */