From 61eb6bb67389fdb59484ee710d20d8689f2cd3f6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 6 May 2013 00:30:42 +0000 Subject: [PATCH] Extract common parts of wxData{In,Out}putStream in a common base class. No real changes, just put BigEndianOrdered() and SetConv() methods and the corresponding fields in a common wxDataStreamBase class instead of duplicating them in wxDataInputStream and wxDataOutputStream. This will make it simpler to add more features common to both classes in the future, see #10625. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73933 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/datstrm.h | 64 ++++++++++++++++++++---------------------- src/common/datstrm.cpp | 64 ++++++++++++++++++------------------------ 2 files changed, 58 insertions(+), 70 deletions(-) diff --git a/include/wx/datstrm.h b/include/wx/datstrm.h index 6882bab2a3..e231f4f761 100644 --- a/include/wx/datstrm.h +++ b/include/wx/datstrm.h @@ -18,15 +18,38 @@ #if wxUSE_STREAMS -class WXDLLIMPEXP_BASE wxDataInputStream +// Common wxDataInputStream and wxDataOutputStream parameters. +class WXDLLIMPEXP_BASE wxDataStreamBase { public: + void BigEndianOrdered(bool be_order) { m_be_order = be_order; } + +#if wxUSE_UNICODE + void SetConv( const wxMBConv &conv ); + wxMBConv *GetConv() const { return m_conv; } +#endif + +protected: + // Ctor and dtor are both protected, this class is never used directly but + // only by its derived classes. + wxDataStreamBase(const wxMBConv& conv); + ~wxDataStreamBase(); + + + bool m_be_order; + #if wxUSE_UNICODE - wxDataInputStream(wxInputStream& s, const wxMBConv& conv = wxConvUTF8 ); -#else - wxDataInputStream(wxInputStream& s); + wxMBConv *m_conv; #endif - ~wxDataInputStream(); + + wxDECLARE_NO_COPY_CLASS(wxDataStreamBase); +}; + + +class WXDLLIMPEXP_BASE wxDataInputStream : public wxDataStreamBase +{ +public: + wxDataInputStream(wxInputStream& s, const wxMBConv& conv = wxConvUTF8); bool IsOk() { return m_input->IsOk(); } @@ -77,32 +100,16 @@ public: wxDataInputStream& operator>>(double& i); wxDataInputStream& operator>>(float& f); - void BigEndianOrdered(bool be_order) { m_be_order = be_order; } - -#if wxUSE_UNICODE - void SetConv( const wxMBConv &conv ); - wxMBConv *GetConv() const { return m_conv; } -#endif - protected: wxInputStream *m_input; - bool m_be_order; -#if wxUSE_UNICODE - wxMBConv *m_conv; -#endif wxDECLARE_NO_COPY_CLASS(wxDataInputStream); }; -class WXDLLIMPEXP_BASE wxDataOutputStream +class WXDLLIMPEXP_BASE wxDataOutputStream : public wxDataStreamBase { public: -#if wxUSE_UNICODE - wxDataOutputStream(wxOutputStream& s, const wxMBConv& conv = wxConvUTF8 ); -#else - wxDataOutputStream(wxOutputStream& s); -#endif - ~wxDataOutputStream(); + wxDataOutputStream(wxOutputStream& s, const wxMBConv& conv = wxConvUTF8); bool IsOk() { return m_output->IsOk(); } @@ -155,19 +162,8 @@ public: wxDataOutputStream& operator<<(double f); wxDataOutputStream& operator<<(float f); - void BigEndianOrdered(bool be_order) { m_be_order = be_order; } - -#if wxUSE_UNICODE - void SetConv( const wxMBConv &conv ); - wxMBConv *GetConv() const { return m_conv; } -#endif - protected: wxOutputStream *m_output; - bool m_be_order; -#if wxUSE_UNICODE - wxMBConv *m_conv; -#endif wxDECLARE_NO_COPY_CLASS(wxDataOutputStream); }; diff --git a/src/common/datstrm.cpp b/src/common/datstrm.cpp index cb76a5528e..c15d0af639 100644 --- a/src/common/datstrm.cpp +++ b/src/common/datstrm.cpp @@ -24,34 +24,45 @@ #include "wx/math.h" #endif //WX_PRECOMP -// --------------------------------------------------------------------------- -// wxDataInputStream -// --------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// wxDataStreamBase +// ---------------------------------------------------------------------------- +wxDataStreamBase::wxDataStreamBase(const wxMBConv& conv) #if wxUSE_UNICODE -wxDataInputStream::wxDataInputStream(wxInputStream& s, const wxMBConv& conv) - : m_input(&s), m_be_order(false), m_conv(conv.Clone()) -#else -wxDataInputStream::wxDataInputStream(wxInputStream& s) - : m_input(&s), m_be_order(false) -#endif + : m_conv(conv.Clone()) +#endif // wxUSE_UNICODE +{ + // It is unused in non-Unicode build, so suppress a warning there. + wxUnusedVar(conv); + + m_be_order = false; +} + +#if wxUSE_UNICODE +void wxDataStreamBase::SetConv( const wxMBConv &conv ) { + delete m_conv; + m_conv = conv.Clone(); } +#endif -wxDataInputStream::~wxDataInputStream() +wxDataStreamBase::~wxDataStreamBase() { #if wxUSE_UNICODE delete m_conv; #endif // wxUSE_UNICODE } -#if wxUSE_UNICODE -void wxDataInputStream::SetConv( const wxMBConv &conv ) +// --------------------------------------------------------------------------- +// wxDataInputStream +// --------------------------------------------------------------------------- + +wxDataInputStream::wxDataInputStream(wxInputStream& s, const wxMBConv& conv) + : wxDataStreamBase(conv), + m_input(&s) { - delete m_conv; - m_conv = conv.Clone(); } -#endif #if wxHAS_INT64 wxUint64 wxDataInputStream::Read64() @@ -463,30 +474,11 @@ wxDataInputStream& wxDataInputStream::operator>>(float& f) // wxDataOutputStream // --------------------------------------------------------------------------- -#if wxUSE_UNICODE wxDataOutputStream::wxDataOutputStream(wxOutputStream& s, const wxMBConv& conv) - : m_output(&s), m_be_order(false), m_conv(conv.Clone()) -#else -wxDataOutputStream::wxDataOutputStream(wxOutputStream& s) - : m_output(&s), m_be_order(false) -#endif -{ -} - -wxDataOutputStream::~wxDataOutputStream() + : wxDataStreamBase(conv), + m_output(&s) { -#if wxUSE_UNICODE - delete m_conv; -#endif // wxUSE_UNICODE -} - -#if wxUSE_UNICODE -void wxDataOutputStream::SetConv( const wxMBConv &conv ) -{ - delete m_conv; - m_conv = conv.Clone(); } -#endif #if wxHAS_INT64 void wxDataOutputStream::Write64(wxUint64 i) -- 2.45.2