mirror of
https://github.com/fmtlib/fmt.git
synced 2025-08-01 03:34:45 +02:00
Simplify ostream
This commit is contained in:
@@ -18,7 +18,6 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib> // for strtod_l
|
#include <cstdlib> // for strtod_l
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#if defined __APPLE__ || defined(__FreeBSD__)
|
#if defined __APPLE__ || defined(__FreeBSD__)
|
||||||
# include <xlocale.h> // for LC_NUMERIC_MASK on OS X
|
# include <xlocale.h> // for LC_NUMERIC_MASK on OS X
|
||||||
@@ -380,32 +379,28 @@ static constexpr detail::buffer_size buffer_size;
|
|||||||
class ostream : private detail::buffer<char> {
|
class ostream : private detail::buffer<char> {
|
||||||
private:
|
private:
|
||||||
file file_;
|
file file_;
|
||||||
size_t buffer_size_;
|
|
||||||
std::unique_ptr<char[]> buffer_;
|
|
||||||
|
|
||||||
void flush() {
|
void flush() {
|
||||||
if (size() == 0) return;
|
if (size() == 0) return;
|
||||||
file_.write(buffer_.get(), size());
|
file_.write(data(), size());
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void grow(size_t) final;
|
void grow(size_t) final;
|
||||||
|
|
||||||
ostream(cstring_view path, const detail::ostream_params& params)
|
ostream(cstring_view path, const detail::ostream_params& params)
|
||||||
: file_(path, params.oflag),
|
: file_(path, params.oflag) {
|
||||||
buffer_size_(params.buffer_size),
|
set(new char[params.buffer_size], params.buffer_size);
|
||||||
buffer_(new char[params.buffer_size]) {
|
|
||||||
set(buffer_.get(), params.buffer_size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ostream(ostream&& other)
|
ostream(ostream&& other) : file_(std::move(other.file_)) {
|
||||||
: file_(std::move(other.file_)),
|
other.set(nullptr, 0);
|
||||||
buffer_size_(other.buffer_size_),
|
}
|
||||||
buffer_(std::move(other.buffer_)) {
|
~ostream() {
|
||||||
other.clear();
|
flush();
|
||||||
|
delete[] data();
|
||||||
}
|
}
|
||||||
~ostream() { flush(); }
|
|
||||||
|
|
||||||
template <typename... T>
|
template <typename... T>
|
||||||
friend ostream output_file(cstring_view path, T... params);
|
friend ostream output_file(cstring_view path, T... params);
|
||||||
|
@@ -315,7 +315,7 @@ long getpagesize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ostream::grow(size_t) {
|
void ostream::grow(size_t) {
|
||||||
if (this->size() == buffer_size_) flush();
|
if (this->size() == this->capacity()) flush();
|
||||||
}
|
}
|
||||||
#endif // FMT_USE_FCNTL
|
#endif // FMT_USE_FCNTL
|
||||||
FMT_END_NAMESPACE
|
FMT_END_NAMESPACE
|
||||||
|
Reference in New Issue
Block a user