From a2ebc9daf60d136fef16170d3e85a7a9d9a6e8c4 Mon Sep 17 00:00:00 2001 From: Catalin Date: Mon, 22 Jun 2015 14:41:11 +0300 Subject: [PATCH] Add wxTextOutputStream::Write<>(). The new method allows to write into wxTextOutputStream anything that can be streamed into wxString and allows to simplify the existing code. --- include/wx/txtstrm.h | 9 +++++++++ interface/wx/txtstrm.h | 8 ++++++++ src/common/txtstrm.cpp | 24 ++++++++---------------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/include/wx/txtstrm.h b/include/wx/txtstrm.h index b0ffbd6293..465a277164 100644 --- a/include/wx/txtstrm.h +++ b/include/wx/txtstrm.h @@ -123,6 +123,15 @@ public: void SetMode( wxEOL mode = wxEOL_NATIVE ); wxEOL GetMode() { return m_mode; } + template + void Write(const T& i) + { + wxString str; + str << i; + + WriteString(str); + } + void Write64(wxUint64 i); void Write32(wxUint32 i); void Write16(wxUint16 i); diff --git a/interface/wx/txtstrm.h b/interface/wx/txtstrm.h index 9d7f187ec5..9b6facd26e 100644 --- a/interface/wx/txtstrm.h +++ b/interface/wx/txtstrm.h @@ -300,6 +300,14 @@ public: */ void SetMode(wxEOL mode = wxEOL_NATIVE); + /** + Writes @a i to the stream using wxString::operator<<(). + + @since 3.1.0 + */ + template + void Write(const T& i); + /** Writes the 64 bit integer @a i64 to the stream. diff --git a/src/common/txtstrm.cpp b/src/common/txtstrm.cpp index 60846f004b..09823296da 100644 --- a/src/common/txtstrm.cpp +++ b/src/common/txtstrm.cpp @@ -526,63 +526,55 @@ wxTextOutputStream& wxTextOutputStream::operator<<(wchar_t wc) wxTextOutputStream& wxTextOutputStream::operator<<(wxInt16 c) { - wxString str; - str.Printf(wxT("%d"), (signed int)c); - WriteString(str); + Write(c); return *this; } wxTextOutputStream& wxTextOutputStream::operator<<(wxInt32 c) { - wxString str; - str.Printf(wxT("%ld"), (signed long)c); - WriteString(str); + Write(c); return *this; } wxTextOutputStream& wxTextOutputStream::operator<<(wxInt64 c) { - WriteString(wxString::Format("%" wxLongLongFmtSpec "d", c)); + Write(c); return *this; } wxTextOutputStream& wxTextOutputStream::operator<<(wxUint16 c) { - wxString str; - str.Printf(wxT("%u"), (unsigned int)c); - WriteString(str); + Write(c); return *this; } wxTextOutputStream& wxTextOutputStream::operator<<(wxUint32 c) { - wxString str; - str.Printf(wxT("%lu"), (unsigned long)c); - WriteString(str); + Write(c); return *this; } wxTextOutputStream& wxTextOutputStream::operator<<(wxUint64 c) { - WriteString(wxString::Format("%" wxLongLongFmtSpec "u", c)); + Write(c); return *this; } wxTextOutputStream &wxTextOutputStream::operator<<(double f) { - WriteDouble(f); + Write(f); return *this; } wxTextOutputStream& wxTextOutputStream::operator<<(float f) { - WriteDouble((double)f); + Write(f); return *this; }