X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3ba055acae99caf68da4bb201f66fc1030d2dbb0..a0d8a3052817fef6eef27e9a6ab8802495a39db8:/src/common/variant.cpp diff --git a/src/common/variant.cpp b/src/common/variant.cpp index 341329fc28..48a709bd5f 100644 --- a/src/common/variant.cpp +++ b/src/common/variant.cpp @@ -6,7 +6,7 @@ // Created: 10/09/98 // RCS-ID: $Id$ // Copyright: (c) -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -17,16 +17,13 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #if wxUSE_IOSTREAMH # include #else # include -# ifdef _MSC_VER - using namespace std; -# endif #endif #include "wx/stream.h" @@ -293,12 +290,17 @@ public: virtual void Copy(wxVariantData& data); virtual bool Eq(wxVariantData& data) const; - virtual bool Write(ostream& str) const; + + virtual bool Read(wxString& str); virtual bool Write(wxString& str) const; - virtual bool Write(wxOutputStream &str) const; virtual bool Read(istream& str); + virtual bool Write(ostream& str) const; + +#if wxUSE_STREAMS virtual bool Read(wxInputStream& str); - virtual bool Read(wxString& str); + virtual bool Write(wxOutputStream &str) const; +#endif // wxUSE_STREAMS + virtual wxString GetType() const { return "long"; }; protected: @@ -333,12 +335,6 @@ bool wxVariantDataLong::Write(ostream& str) const return TRUE; } -bool wxVariantDataLong::Write(wxOutputStream& str) const -{ - str << m_value; - return TRUE; -} - bool wxVariantDataLong::Write(wxString& str) const { str.Printf("%ld", m_value); @@ -351,11 +347,19 @@ bool wxVariantDataLong::Read(istream& str) return TRUE; } +#if wxUSE_STREAMS +bool wxVariantDataLong::Write(wxOutputStream& str) const +{ + str << m_value; + return TRUE; +} + bool wxVariantDataLong::Read(wxInputStream& str) { str >> m_value; return TRUE; } +#endif // wxUSE_STREAMS bool wxVariantDataLong::Read(wxString& str) { @@ -379,12 +383,14 @@ public: virtual void Copy(wxVariantData& data); virtual bool Eq(wxVariantData& data) const; + virtual bool Read(wxString& str); virtual bool Write(ostream& str) const; virtual bool Write(wxString& str) const; - virtual bool Write(wxOutputStream &str) const; virtual bool Read(istream& str); +#if wxUSE_STREAMS virtual bool Read(wxInputStream& str); - virtual bool Read(wxString& str); + virtual bool Write(wxOutputStream &str) const; +#endif // wxUSE_STREAMS virtual wxString GetType() const { return "double"; }; protected: @@ -419,12 +425,6 @@ bool wxVariantDataReal::Write(ostream& str) const return TRUE; } -bool wxVariantDataReal::Write(wxOutputStream& str) const -{ - str << m_value; - return TRUE; -} - bool wxVariantDataReal::Write(wxString& str) const { str.Printf("%.4f", m_value); @@ -437,11 +437,19 @@ bool wxVariantDataReal::Read(istream& str) return TRUE; } +#if wxUSE_STREAMS +bool wxVariantDataReal::Write(wxOutputStream& str) const +{ + str << m_value; + return TRUE; +} + bool wxVariantDataReal::Read(wxInputStream& str) { str >> (float&)m_value; return TRUE; } +#endif // wxUSE_STREAMS bool wxVariantDataReal::Read(wxString& str) { @@ -449,6 +457,7 @@ bool wxVariantDataReal::Read(wxString& str) return TRUE; } +#ifdef HAVE_BOOL /* * wxVariantDataBool */ @@ -466,11 +475,13 @@ public: virtual void Copy(wxVariantData& data); virtual bool Eq(wxVariantData& data) const; virtual bool Write(ostream& str) const; - virtual bool Write(wxOutputStream& str) const; virtual bool Write(wxString& str) const; + virtual bool Read(wxString& str); virtual bool Read(istream& str); +#if wxUSE_STREAMS virtual bool Read(wxInputStream& str); - virtual bool Read(wxString& str); + virtual bool Write(wxOutputStream& str) const; +#endif // wxUSE_STREAMS virtual wxString GetType() const { return "bool"; }; protected: @@ -505,12 +516,6 @@ bool wxVariantDataBool::Write(ostream& str) const return TRUE; } -bool wxVariantDataBool::Write(wxOutputStream& str) const -{ - str << (char)m_value; - return TRUE; -} - bool wxVariantDataBool::Write(wxString& str) const { str.Printf("%d", (int) m_value); @@ -524,17 +529,26 @@ bool wxVariantDataBool::Read(istream& WXUNUSED(str)) return FALSE; } +#if wxUSE_STREAMS +bool wxVariantDataBool::Write(wxOutputStream& str) const +{ + str << (char)m_value; + return TRUE; +} + bool wxVariantDataBool::Read(wxInputStream& str) { str >> (char&)m_value; return TRUE; } +#endif // wxUSE_STREAMS bool wxVariantDataBool::Read(wxString& str) { m_value = (atol((const char*) str) != 0); return TRUE; } +#endif // HAVE_BOOL /* * wxVariantDataChar @@ -552,12 +566,14 @@ public: virtual void Copy(wxVariantData& data); virtual bool Eq(wxVariantData& data) const; + virtual bool Read(istream& str); virtual bool Write(ostream& str) const; - virtual bool Write(wxOutputStream& str) const; + virtual bool Read(wxString& str); virtual bool Write(wxString& str) const; - virtual bool Read(istream& str); +#if wxUSE_STREAMS virtual bool Read(wxInputStream& str); - virtual bool Read(wxString& str); + virtual bool Write(wxOutputStream& str) const; +#endif // wxUSE_STREAMS virtual wxString GetType() const { return "char"; }; protected: @@ -592,12 +608,6 @@ bool wxVariantDataChar::Write(ostream& str) const return TRUE; } -bool wxVariantDataChar::Write(wxOutputStream& str) const -{ - str << m_value; - return TRUE; -} - bool wxVariantDataChar::Write(wxString& str) const { str.Printf("%c", m_value); @@ -611,11 +621,19 @@ bool wxVariantDataChar::Read(istream& WXUNUSED(str)) return FALSE; } +#if wxUSE_STREAMS +bool wxVariantDataChar::Write(wxOutputStream& str) const +{ + str << m_value; + return TRUE; +} + bool wxVariantDataChar::Read(wxInputStream& str) { str >> m_value; return TRUE; } +#endif // wxUSE_STREAMS bool wxVariantDataChar::Read(wxString& str) { @@ -649,11 +667,13 @@ public: virtual void Copy(wxVariantData& data); virtual bool Eq(wxVariantData& data) const; virtual bool Write(ostream& str) const; - virtual bool Write(wxOutputStream& str) const; + virtual bool Read(wxString& str); virtual bool Write(wxString& str) const; virtual bool Read(istream& str); +#if wxUSE_STREAMS virtual bool Read(wxInputStream& str); - virtual bool Read(wxString& str); + virtual bool Write(wxOutputStream& str) const; +#endif // wxUSE_STREAMS virtual wxString GetType() const { return "string"; }; protected: @@ -684,12 +704,6 @@ bool wxVariantDataString::Write(ostream& str) const return TRUE; } -bool wxVariantDataString::Write(wxOutputStream& str) const -{ - str << (const char*) m_value; - return TRUE; -} - bool wxVariantDataString::Write(wxString& str) const { str = m_value; @@ -702,11 +716,19 @@ bool wxVariantDataString::Read(istream& str) return TRUE; } +#if wxUSE_STREAMS +bool wxVariantDataString::Write(wxOutputStream& str) const +{ + str << (const char*) m_value; + return TRUE; +} + bool wxVariantDataString::Read(wxInputStream& str) { str >> m_value; return TRUE; } +#endif // wxUSE_STREAMS bool wxVariantDataString::Read(wxString& str) { @@ -971,11 +993,13 @@ wxVariant::wxVariant(long val, const wxString& name) m_name = name; } +#ifdef HAVE_BOOL wxVariant::wxVariant(bool val, const wxString& name) { m_data = new wxVariantDataBool(val); m_name = name; } +#endif wxVariant::wxVariant(char val, const wxString& name) { @@ -1185,6 +1209,7 @@ void wxVariant::operator= (char value) } } +#ifdef HAVE_BOOL bool wxVariant::operator== (bool value) const { bool thisValue; @@ -1212,6 +1237,7 @@ void wxVariant::operator= (bool value) m_data = new wxVariantDataBool(value); } } +#endif // HAVE_BOOL bool wxVariant::operator== (const wxString& value) const { @@ -1660,8 +1686,10 @@ bool wxVariant::Convert(long* value) const *value = (long) (((wxVariantDataReal*)GetData())->GetValue()); else if (type == "long") *value = ((wxVariantDataLong*)GetData())->GetValue(); +#ifdef HAVE_BOOL else if (type == "bool") *value = (long) (((wxVariantDataBool*)GetData())->GetValue()); +#endif else if (type == "string") *value = atol((const char*) ((wxVariantDataString*)GetData())->GetValue()); else @@ -1677,8 +1705,10 @@ bool wxVariant::Convert(bool* value) const *value = ((int) (((wxVariantDataReal*)GetData())->GetValue()) != 0); else if (type == "long") *value = (((wxVariantDataLong*)GetData())->GetValue() != 0); +#ifdef HAVE_BOOL else if (type == "bool") *value = ((wxVariantDataBool*)GetData())->GetValue(); +#endif else if (type == "string") { wxString val(((wxVariantDataString*)GetData())->GetValue()); @@ -1703,8 +1733,10 @@ bool wxVariant::Convert(double* value) const *value = ((wxVariantDataReal*)GetData())->GetValue(); else if (type == "long") *value = (double) (((wxVariantDataLong*)GetData())->GetValue()); +#ifdef HAVE_BOOL else if (type == "bool") *value = (double) (((wxVariantDataBool*)GetData())->GetValue()); +#endif else if (type == "string") *value = (double) atof((const char*) ((wxVariantDataString*)GetData())->GetValue()); else @@ -1720,8 +1752,10 @@ bool wxVariant::Convert(char* value) const *value = ((wxVariantDataChar*)GetData())->GetValue(); else if (type == "long") *value = (char) (((wxVariantDataLong*)GetData())->GetValue()); +#ifdef HAVE_BOOL else if (type == "bool") *value = (char) (((wxVariantDataBool*)GetData())->GetValue()); +#endif else return FALSE;