2014-02-22 04:57:53 -05:00
|
|
|
#pragma once
|
|
|
|
// Flush to file every X writes..
|
|
|
|
|
2014-03-06 17:52:50 -05:00
|
|
|
namespace c11log
|
|
|
|
{
|
|
|
|
namespace details
|
|
|
|
{
|
2014-03-14 08:35:46 -04:00
|
|
|
|
2014-03-06 17:52:50 -05:00
|
|
|
class file_flush_helper
|
|
|
|
{
|
2014-02-22 04:57:53 -05:00
|
|
|
public:
|
2014-03-14 08:35:46 -04:00
|
|
|
explicit file_flush_helper(const std::size_t flush_every):
|
|
|
|
_flush_every(flush_every),
|
|
|
|
_write_counter(0) {};
|
2014-05-07 19:23:07 -04:00
|
|
|
|
|
|
|
void write(const std::string& msg, std::ofstream& ofs)
|
2014-03-14 08:35:46 -04:00
|
|
|
{
|
2014-05-07 19:23:07 -04:00
|
|
|
ofs.write(msg.data(), msg.size());
|
2014-03-14 08:35:46 -04:00
|
|
|
if(++_write_counter == _flush_every)
|
|
|
|
{
|
2014-02-22 04:57:53 -05:00
|
|
|
ofs.flush();
|
2014-03-14 08:35:46 -04:00
|
|
|
_write_counter = 0;
|
2014-02-22 04:57:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-03-14 08:35:46 -04:00
|
|
|
const std::size_t _flush_every;
|
|
|
|
std::size_t _write_counter;
|
2014-02-22 04:57:53 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|