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