diff -r ec5387e121fa -r 146825d63b9a sources/format.h --- a/sources/format.h Wed Dec 10 19:26:13 2014 +0200 +++ b/sources/format.h Thu Dec 11 05:58:55 2014 +0200 @@ -105,29 +105,24 @@ return result; } -// // ------------------------------------------------------------------------------------------------- -// // Formats the given string with the given args. // -auto format_args (const String& fmtstr, const Vector& args) -> String; +FUNCTION format_args (const String& fmtstr, const Vector& args) -> String; -// // ------------------------------------------------------------------------------------------------- -// // Expands the given arguments into a vector of strings. // -template -auto expand_format_arguments (Vector& data, const T& arg, const RestTypes& ... rest) -> void +template FUNCTION +expand_format_arguments (Vector& data, const T& arg, const RestTypes& ... rest) -> void { data.append (make_format_argument (arg).text()); expand_format_arguments (data, rest...); } -static void expand_format_arguments (Vector&) __attribute__( (unused)); +static void expand_format_arguments (Vector&) __attribute__((unused)); static void expand_format_arguments (Vector&) {} -// // ------------------------------------------------------------------------------------------------- // // Formats the given formatter string and args and returns the string. @@ -153,40 +148,37 @@ // argument did not expand into a number in the first place, 0 is used // and 0x0 is printed. // -template -String format (const String& fmtstr, const argtypes&... raw_args) +template FUNCTION +format (const String& fmtstr, const argtypes&... raw_args) -> String { Vector args; expand_format_arguments (args, raw_args...); return format_args (fmtstr, args); } -// // ------------------------------------------------------------------------------------------------- -// // This is an overload of format() where no arguments are supplied. // It returns the formatter string as-is. // static String format (const String& fmtstr) __attribute__ ((unused)); -static String format (const String& fmtstr) +static String // FUNCTION +format (const String& fmtstr) // -> String { return fmtstr; } -// // ------------------------------------------------------------------------------------------------- +// Prints the formatting result to the given file handle // - -template -void print_to (FILE* fp, const String& fmtstr, Args const& ...args) +template FUNCTION +print_to (FILE* fp, const String& fmtstr, Args const& ...args) -> void { std::fprintf (fp, "%s", format (fmtstr, args...).chars()); } +// ------------------------------------------------------------------------------------------------- +// Appends the formatting result to the given filename, if opening it succeeds // -// ------------------------------------------------------------------------------------------------- -// - template void print_to (const String& filename, const String& fmtstr, const argtypes&... args) { @@ -199,18 +191,11 @@ } } +// ------------------------------------------------------------------------------------------------- +// Prints the formatting result to stdout // -// ------------------------------------------------------------------------------------------------- -// - template void print (const String& fmtstr, const argtypes&... args) { print_to (stdout, fmtstr, args...); } - -#define PRINT_TO_LOG(...) \ -{ \ - print_to (LOGFILE, "%1:%2: ", __PRETTY_FUNCTION__, __LINE__); \ - print_to (LOGFILE, __VA_ARGS__); \ -}