Move part of write API (spec factories) to a separate header

This commit is contained in:
Victor Zverovich 2017-08-27 09:08:44 -07:00
parent 20168147dd
commit 47c84d7974
4 changed files with 63 additions and 36 deletions

View File

@ -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)

View File

@ -1747,30 +1747,6 @@ class fill_spec : public format_spec<Char, fill_tag> {
typedef format_spec<unsigned, width_tag> width_spec;
typedef format_spec<char, type_tag> type_spec;
class fill_spec_factory {
public:
constexpr fill_spec_factory() {}
template <typename Char>
fill_spec<Char> operator=(Char value) const {
return fill_spec<Char>(value);
}
};
template <typename FormatSpec>
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_spec> width;
constexpr format_spec_factory<type_spec> 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 <typename T>
class named_format_spec {
public:
constexpr named_format_spec() {}
};
constexpr named_format_spec<unsigned> width;
}
/**
\rst
This template provides operations for formatting and writing data into a

61
fmt/write.h Normal file
View File

@ -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 <typename Char>
fill_spec<Char> operator=(Char value) const {
return fill_spec<Char>(value);
}
};
template <typename FormatSpec>
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_spec> width;
constexpr format_spec_factory<type_spec> type;
} // namespace fmt
#endif // FMT_WRITE_H_

View File

@ -43,6 +43,7 @@
#define None 0
#include "fmt/format.h"
#include "fmt/write.h"
#include "util.h"
#include "mock-allocator.h"