From 47c84d7974c0f4eb3ff850b731e0360fca20c655 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 27 Aug 2017 09:08:44 -0700 Subject: [PATCH] Move part of write API (spec factories) to a separate header --- fmt/CMakeLists.txt | 2 +- fmt/format.h | 35 -------------------------- fmt/write.h | 61 +++++++++++++++++++++++++++++++++++++++++++++ test/format-test.cc | 1 + 4 files changed, 63 insertions(+), 36 deletions(-) create mode 100644 fmt/write.h diff --git a/fmt/CMakeLists.txt b/fmt/CMakeLists.txt index c6502a3d..c2c7f0fe 100644 --- a/fmt/CMakeLists.txt +++ b/fmt/CMakeLists.txt @@ -1,7 +1,7 @@ # Define the fmt library, its includes and the needed defines. # format.cc is added to FMT_HEADERS for the header-only configuration. set(FMT_HEADERS format.h format.cc ostream.h ostream.cc printf.h printf.cc - string.h time.h) + string.h time.h write.h) if (HAVE_OPEN) set(FMT_HEADERS ${FMT_HEADERS} posix.h) set(FMT_SOURCES ${FMT_SOURCES} posix.cc) diff --git a/fmt/format.h b/fmt/format.h index 3cc6d0c0..d0c89812 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -1747,30 +1747,6 @@ class fill_spec : public format_spec { typedef format_spec width_spec; typedef format_spec type_spec; -class fill_spec_factory { - public: - constexpr fill_spec_factory() {} - - template - fill_spec operator=(Char value) const { - return fill_spec(value); - } -}; - -template -class format_spec_factory { - public: - constexpr format_spec_factory() {} - - FormatSpec operator=(typename FormatSpec::value_type value) const { - return FormatSpec(value); - } -}; - -constexpr fill_spec_factory fill; -constexpr format_spec_factory width; -constexpr format_spec_factory type; - // An empty format specifier. struct empty_spec {}; @@ -2225,17 +2201,6 @@ class system_error : public std::runtime_error { FMT_API void format_system_error(fmt::buffer &out, int error_code, fmt::string_view message) FMT_NOEXCEPT; -namespace internal { -// Named format specifier. -template -class named_format_spec { - public: - constexpr named_format_spec() {} -}; - -constexpr named_format_spec width; -} - /** \rst This template provides operations for formatting and writing data into a diff --git a/fmt/write.h b/fmt/write.h new file mode 100644 index 00000000..c6aec5a7 --- /dev/null +++ b/fmt/write.h @@ -0,0 +1,61 @@ +/* + Formatting library for C++ + + Copyright (c) 2012 - 2016, Victor Zverovich + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef FMT_WRITE_H_ +#define FMT_WRITE_H_ + +#include "fmt/format.h" + +namespace fmt { + +class fill_spec_factory { + public: + constexpr fill_spec_factory() {} + + template + fill_spec operator=(Char value) const { + return fill_spec(value); + } +}; + +template +class format_spec_factory { + public: + constexpr format_spec_factory() {} + + FormatSpec operator=(typename FormatSpec::value_type value) const { + return FormatSpec(value); + } +}; + +constexpr fill_spec_factory fill; +constexpr format_spec_factory width; +constexpr format_spec_factory type; + +} // namespace fmt + +#endif // FMT_WRITE_H_ diff --git a/test/format-test.cc b/test/format-test.cc index 08dafb3b..8ab7e46b 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -43,6 +43,7 @@ #define None 0 #include "fmt/format.h" +#include "fmt/write.h" #include "util.h" #include "mock-allocator.h"