Initial support for header-only configuration

This commit is contained in:
Victor Zverovich 2014-11-28 06:40:57 -08:00
parent aca49379a5
commit d9c605c61f
2 changed files with 18 additions and 10 deletions

View File

@ -81,6 +81,10 @@ using fmt::internal::Arg;
# endif
#endif
#ifdef FMT_HEADER_ONLY
# define FMT_FUNC inline
#endif
#if _MSC_VER
# pragma warning(push)
# pragma warning(disable: 4127) // conditional expression is constant
@ -348,7 +352,7 @@ inline Arg::StringValue<wchar_t> ignore_incompatible_str(
Arg::StringValue<wchar_t> s) { return s; }
} // namespace
void fmt::SystemError::init(
FMT_FUNC void fmt::SystemError::init(
int error_code, StringRef format_str, ArgList args) {
error_code_ = error_code;
MemoryWriter w;
@ -413,7 +417,7 @@ const uint64_t fmt::internal::POWERS_OF_10_64[] = {
ULongLong(1000000000) * ULongLong(1000000000) * 10
};
void fmt::internal::report_unknown_type(char code, const char *type) {
FMT_FUNC void fmt::internal::report_unknown_type(char code, const char *type) {
if (std::isprint(static_cast<unsigned char>(code))) {
FMT_THROW(fmt::FormatError(
fmt::format("unknown format code '{}' for {}", code, type)));
@ -468,7 +472,7 @@ void fmt::WindowsError::init(
#endif
void fmt::internal::format_system_error(
FMT_FUNC void fmt::internal::format_system_error(
fmt::Writer &out, int error_code,
fmt::StringRef message) FMT_NOEXCEPT(true) {
FMT_TRY {
@ -619,7 +623,7 @@ inline Arg fmt::BasicFormatter<Char>::parse_arg_index(const Char *&s) {
return arg;
}
Arg fmt::internal::FormatterBase::do_get_arg(
FMT_FUNC Arg fmt::internal::FormatterBase::do_get_arg(
unsigned arg_index, const char *&error) {
Arg arg = args_[arg_index];
if (arg.type == Arg::NONE)
@ -1042,7 +1046,7 @@ void fmt::BasicFormatter<Char>::format(
write(writer_, start_, s);
}
void fmt::report_system_error(
FMT_FUNC void fmt::report_system_error(
int error_code, fmt::StringRef message) FMT_NOEXCEPT(true) {
report_error(internal::format_system_error, error_code, message);
}
@ -1054,23 +1058,23 @@ void fmt::report_windows_error(
}
#endif
void fmt::print(std::FILE *f, StringRef format_str, ArgList args) {
FMT_FUNC void fmt::print(std::FILE *f, StringRef format_str, ArgList args) {
MemoryWriter w;
w.write(format_str, args);
std::fwrite(w.data(), 1, w.size(), f);
}
void fmt::print(StringRef format_str, ArgList args) {
FMT_FUNC void fmt::print(StringRef format_str, ArgList args) {
print(stdout, format_str, args);
}
void fmt::print(std::ostream &os, StringRef format_str, ArgList args) {
FMT_FUNC void fmt::print(std::ostream &os, StringRef format_str, ArgList args) {
MemoryWriter w;
w.write(format_str, args);
os.write(w.data(), w.size());
}
void fmt::print_colored(Color c, StringRef format, ArgList args) {
FMT_FUNC void fmt::print_colored(Color c, StringRef format, ArgList args) {
char escape[] = "\x1b[30m";
escape[3] = '0' + static_cast<char>(c);
std::fputs(escape, stdout);
@ -1078,7 +1082,7 @@ void fmt::print_colored(Color c, StringRef format, ArgList args) {
std::fputs(RESET_COLOR, stdout);
}
int fmt::fprintf(std::FILE *f, StringRef format, ArgList args) {
FMT_FUNC int fmt::fprintf(std::FILE *f, StringRef format, ArgList args) {
MemoryWriter w;
printf(w, format, args);
std::size_t size = w.size();

View File

@ -2427,4 +2427,8 @@ FMT_VARIADIC(int, fprintf, std::FILE *, StringRef)
# pragma GCC diagnostic pop
#endif
#ifdef FMT_HEADER_ONLY
# include "format.cc"
#endif
#endif // FMT_FORMAT_H_