From 4e333115971fb38005b0e4f461687e19afeccf71 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 29 Apr 2014 09:32:25 -0700 Subject: [PATCH] Get rid of FormatterProxy. --- format.h | 46 ++++++++++------------------------------------ 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/format.h b/format.h index e5c1e587..69bfa008 100644 --- a/format.h +++ b/format.h @@ -370,9 +370,6 @@ inline unsigned CountDigits(uint64_t n) { extern const char DIGITS[]; -template -class FormatterProxy; - // Formats a decimal unsigned integer value writing into buffer. template void FormatDecimal(Char *buffer, UInt value, unsigned num_digits) { @@ -1266,8 +1263,6 @@ class BasicFormatter { const Char *format_; // Format string. - friend class internal::FormatterProxy; - // Forbid copying from a temporary as in the following example: // // fmt::Formatter<> f = Format("test"); // not allowed @@ -1313,13 +1308,9 @@ class BasicFormatter { return *this; } - operator internal::FormatterProxy() { - return internal::FormatterProxy(this); - } - - operator StringRef() { + operator BasicStringRef() { CompleteFormatting(); - return StringRef(writer_->c_str(), writer_->size()); + return BasicStringRef(writer_->c_str(), writer_->size()); } }; @@ -1331,44 +1322,27 @@ inline std::basic_string str(const BasicWriter &f) { template inline const Char *c_str(const BasicWriter &f) { return f.c_str(); } -namespace internal { - -template -class FormatterProxy { - private: - BasicFormatter *formatter_; - - public: - explicit FormatterProxy(BasicFormatter *f) : formatter_(f) {} - - BasicWriter *Format() { - formatter_->CompleteFormatting(); - return formatter_->writer_; - } -}; -} - /** Returns the content of the output buffer as an `std::string`. */ -inline std::string str(internal::FormatterProxy p) { - return p.Format()->str(); +inline std::string str(StringRef s) { + return std::string(s.c_str(), s.size()); } /** Returns a pointer to the output buffer content with terminating null character appended. */ -inline const char *c_str(internal::FormatterProxy p) { - return p.Format()->c_str(); +inline const char *c_str(StringRef s) { + return s.c_str(); } -inline std::wstring str(internal::FormatterProxy p) { - return p.Format()->str(); +inline std::wstring str(WStringRef s) { + return std::wstring(s.c_str(), s.size()); } -inline const wchar_t *c_str(internal::FormatterProxy p) { - return p.Format()->c_str(); +inline const wchar_t *c_str(WStringRef s) { + return s.c_str(); } /**