--- 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<String>& args) -> String; +FUNCTION format_args (const String& fmtstr, const Vector<String>& args) -> String; -// // ------------------------------------------------------------------------------------------------- -// // Expands the given arguments into a vector of strings. // -template<typename T, typename... RestTypes> -auto expand_format_arguments (Vector<String>& data, const T& arg, const RestTypes& ... rest) -> void +template<typename T, typename... RestTypes> FUNCTION +expand_format_arguments (Vector<String>& 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<String>&) __attribute__( (unused)); +static void expand_format_arguments (Vector<String>&) __attribute__((unused)); static void expand_format_arguments (Vector<String>&) {} -// // ------------------------------------------------------------------------------------------------- // // 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<typename... argtypes> -String format (const String& fmtstr, const argtypes&... raw_args) +template<typename... argtypes> FUNCTION +format (const String& fmtstr, const argtypes&... raw_args) -> String { Vector<String> 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<typename... Args> -void print_to (FILE* fp, const String& fmtstr, Args const& ...args) +template<typename... Args> 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<typename... argtypes> void print_to (const String& filename, const String& fmtstr, const argtypes&... args) { @@ -199,18 +191,11 @@ } } +// ------------------------------------------------------------------------------------------------- +// Prints the formatting result to stdout // -// ------------------------------------------------------------------------------------------------- -// - template<typename... argtypes> 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__); \ -}