Cleanup direct_buffered_file

This commit is contained in:
Victor Zverovich 2020-07-11 08:27:37 -07:00
parent 04a1f6e991
commit ba8d98cbb7

View File

@ -343,16 +343,10 @@ class file {
// Returns the memory page size. // Returns the memory page size.
long getpagesize(); long getpagesize();
class direct_buffered_file;
template <typename S, typename... Args>
void print(direct_buffered_file& f, const S& format_str, const Args&... args);
// A buffered file with a direct buffer access and no synchronization. // A buffered file with a direct buffer access and no synchronization.
class direct_buffered_file : private detail::buffer<char> { class direct_buffered_file : private detail::buffer<char> {
private: private:
file file_; file file_;
char buffer_[BUFSIZ]; char buffer_[BUFSIZ];
void flush() { void flush() {
@ -361,13 +355,10 @@ class direct_buffered_file : private detail::buffer<char> {
clear(); clear();
} }
int free_capacity() const { return static_cast<int>(BUFSIZ - size()); }
protected:
void grow(size_t) final; void grow(size_t) final;
public: public:
direct_buffered_file(const char* path, int oflag) direct_buffered_file(cstring_view path, int oflag)
: buffer<char>(buffer_, 0, BUFSIZ), file_(path, oflag) {} : buffer<char>(buffer_, 0, BUFSIZ), file_(path, oflag) {}
~direct_buffered_file() { flush(); } ~direct_buffered_file() { flush(); }
@ -379,10 +370,13 @@ class direct_buffered_file : private detail::buffer<char> {
template <typename S, typename... Args> template <typename S, typename... Args>
friend void print(direct_buffered_file& f, const S& format_str, friend void print(direct_buffered_file& f, const S& format_str,
const Args&... args) { const Args&... args);
fmt::format_to(detail::buffer_appender<char>(f), format_str, args...);
}
}; };
template <typename S, typename... Args>
void print(direct_buffered_file& f, const S& format_str, const Args&... args) {
format_to(detail::buffer_appender<char>(f), format_str, args...);
}
#endif // FMT_USE_FCNTL #endif // FMT_USE_FCNTL
#ifdef FMT_LOCALE #ifdef FMT_LOCALE