From 941663d038abac2073c46a1dc24d752a81340a54 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 17 Dec 2017 09:33:12 -0800 Subject: [PATCH] Merge ostream.cc into ostream.h --- CMakeLists.txt | 4 ++-- include/fmt/ostream.cc | 36 ------------------------------------ include/fmt/ostream.h | 25 +++++++++++++++++++------ 3 files changed, 21 insertions(+), 44 deletions(-) delete mode 100644 include/fmt/ostream.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index a2c69cf9..d0300120 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,8 +82,8 @@ endfunction() # Define the fmt library, its includes and the needed defines. # format.cc is added to FMT_HEADERS for the header-only configuration. -add_headers(FMT_HEADERS core.h format.h format.cc locale.h ostream.h ostream.cc - printf.h string.h time.h) +add_headers(FMT_HEADERS core.h format.h format.cc locale.h ostream.h printf.h + string.h time.h) if (HAVE_OPEN) add_headers(FMT_HEADERS posix.h) add_headers(FMT_SOURCES posix.cc) diff --git a/include/fmt/ostream.cc b/include/fmt/ostream.cc deleted file mode 100644 index 0810f254..00000000 --- a/include/fmt/ostream.cc +++ /dev/null @@ -1,36 +0,0 @@ -/* - Formatting library for C++ - std::ostream support - - Copyright (c) 2012 - 2016, Victor Zverovich - All rights reserved. - - For the license information refer to format.h. - */ - -#include "fmt/ostream.h" - -namespace fmt { - -namespace internal { -FMT_FUNC void write(std::ostream &os, buffer &buf) { - const char *data = buf.data(); - typedef std::make_unsigned::type UnsignedStreamSize; - UnsignedStreamSize size = buf.size(); - UnsignedStreamSize max_size = - internal::to_unsigned((std::numeric_limits::max)()); - do { - UnsignedStreamSize n = size <= max_size ? size : max_size; - os.write(data, static_cast(n)); - data += n; - size -= n; - } while (size != 0); -} -} - -FMT_FUNC void vprint(std::ostream &os, string_view format_str, - format_args args) { - memory_buffer buffer; - vformat_to(buffer, format_str, args); - internal::write(os, buffer); -} -} // namespace fmt diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index af0e91ff..964c9a19 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -69,7 +69,20 @@ struct convert_to_int_impl { }; // Write the content of buf to os. -void write(std::ostream &os, buffer &buf); +template +void write(std::basic_ostream &os, basic_buffer &buf) { + const Char *data = buf.data(); + typedef std::make_unsigned::type UnsignedStreamSize; + UnsignedStreamSize size = buf.size(); + UnsignedStreamSize max_size = + internal::to_unsigned((std::numeric_limits::max)()); + do { + UnsignedStreamSize n = size <= max_size ? size : max_size; + os.write(data, static_cast(n)); + data += n; + size -= n; + } while (size != 0); +} template void format_value(basic_buffer &buffer, const T &value) { @@ -100,7 +113,11 @@ struct formatter