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.
This commit is contained in:
Catalin
2015-06-22 14:41:11 +03:00
committed by Vadim Zeitlin
parent aa62a65130
commit a2ebc9daf6
3 changed files with 25 additions and 16 deletions

View File

@@ -123,6 +123,15 @@ public:
void SetMode( wxEOL mode = wxEOL_NATIVE );
wxEOL GetMode() { return m_mode; }
template<typename T>
void Write(const T& i)
{
wxString str;
str << i;
WriteString(str);
}
void Write64(wxUint64 i);
void Write32(wxUint32 i);
void Write16(wxUint16 i);

View File

@@ -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<typename T>
void Write(const T& i);
/**
Writes the 64 bit integer @a i64 to the stream.

View File

@@ -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;
}