From b1ed81ef3216b212295afa76c5d20a56fb647204 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Mon, 13 Oct 2014 00:42:37 -0400 Subject: new kenlm --- klm/util/fake_ofstream.hh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'klm/util/fake_ofstream.hh') diff --git a/klm/util/fake_ofstream.hh b/klm/util/fake_ofstream.hh index bcdebe45..eefb1edc 100644 --- a/klm/util/fake_ofstream.hh +++ b/klm/util/fake_ofstream.hh @@ -2,6 +2,9 @@ * Does not support many data types. Currently, it's targeted at writing ARPA * files quickly. */ +#ifndef UTIL_FAKE_OFSTREAM_H +#define UTIL_FAKE_OFSTREAM_H + #include "util/double-conversion/double-conversion.h" #include "util/double-conversion/utils.h" #include "util/file.hh" @@ -17,7 +20,8 @@ class FakeOFStream { static const std::size_t kOutBuf = 1048576; // Does not take ownership of out. - explicit FakeOFStream(int out) + // Allows default constructor, but must call SetFD. + explicit FakeOFStream(int out = -1) : buf_(util::MallocOrThrow(kOutBuf)), builder_(static_cast(buf_.get()), kOutBuf), // Mostly the default but with inf instead. And no flags. @@ -28,6 +32,11 @@ class FakeOFStream { if (buf_.get()) Flush(); } + void SetFD(int to) { + if (builder_.position()) Flush(); + fd_ = to; + } + FakeOFStream &operator<<(float value) { // Odd, but this is the largest number found in the comments. EnsureRemaining(double_conversion::DoubleToStringConverter::kMaxPrecisionDigits + 8); @@ -92,3 +101,5 @@ class FakeOFStream { }; } // namespace + +#endif -- cgit v1.2.3