X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fstrings%2Fformat.h;h=7969ef3930c01979e1948d63b97dccd9b6f2a026;hb=HEAD;hp=6d8f739a436c3abaa8fdbbbdc7292e5dfb803d1d;hpb=c7afef88380ebebc8c2b04e48664d73281ec8848;p=libs%2Fcore.git diff --git a/source/strings/format.h b/source/strings/format.h index 6d8f739..7969ef3 100644 --- a/source/strings/format.h +++ b/source/strings/format.h @@ -2,6 +2,7 @@ #define MSP_STRINGS_FORMAT_H_ #include +#include #include "lexicalcast.h" namespace Msp { @@ -9,7 +10,7 @@ namespace Msp { /** Printf-like string formatter class. */ -class Formatter +class MSPCORE_API Formatter { private: std::string fmt; @@ -18,17 +19,25 @@ private: public: Formatter(const std::string &); + Formatter(const Formatter &); + Formatter &operator=(const Formatter &); /** Extracts the next conversion from the format string and formats the given value with it. Will throw if no more conversions are found. */ template Formatter &operator()(const T &a) { - result += lexical_cast(a, get_conversion()); + result += lexical_cast(a, get_conversion()); advance(); return *this; } + template + Formatter &operator()(const T &a, const Tail &... tail) + { + return (*this)(a)(tail...); + } + /** Returns the result of the formatting operation. Will throw if not enough values have been fed to the formatter. */ const std::string &str() const; @@ -47,25 +56,11 @@ private: inline Formatter format(const std::string &f) { return Formatter(f); } -template -inline std::string format(const std::string &f, const A1 &a1) -{ return Formatter(f)(a1).str(); } - -template -inline std::string format(const std::string &f, const A1 &a1, const A2 &a2) -{ return Formatter(f)(a1)(a2).str(); } - -template -inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3) -{ return Formatter(f)(a1)(a2)(a3).str(); } - -template -inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4) -{ return Formatter(f)(a1)(a2)(a3)(a4).str(); } - -template -inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5) -{ return Formatter(f)(a1)(a2)(a3)(a4)(a5).str(); } +template +inline std::string format(const std::string &f, const Args &... args) +{ + return Formatter(f)(args...).str(); +} } // namespace Msp