X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dc259b792613550edda31cc6202b42e172e2a240..0d1cb8cb298ae68754575cb65695ff9567a36899:/src/common/variant.cpp?ds=inline diff --git a/src/common/variant.cpp b/src/common/variant.cpp index 52a4e270d5..7b2f9dd943 100644 --- a/src/common/variant.cpp +++ b/src/common/variant.cpp @@ -11,8 +11,6 @@ #ifdef __GNUG__ #pragma implementation "variant.h" -#pragma implementation "time.h" -#pragma implementation "date.h" #endif // For compilers that support precompilation, includes "wx/wx.h". @@ -30,6 +28,10 @@ #endif #endif +#if defined(__MWERKS__) && __MSL__ >= 0x6000 +using namespace std ; +#endif + #if wxUSE_STREAMS #include "wx/stream.h" #include "wx/txtstrm.h" @@ -40,15 +42,6 @@ #include "wx/variant.h" -#if wxUSE_TIMEDATE -IMPLEMENT_DYNAMIC_CLASS(wxDate, wxObject) -IMPLEMENT_DYNAMIC_CLASS(wxTime, wxObject) - -wxTime::tFormat wxTime::ms_Format = wxTime::wx12h; -wxTime::tPrecision wxTime::ms_Precision = wxTime::wxStdMinSec; -wxChar wxTime::ms_bufTime[128]; -#endif - IMPLEMENT_ABSTRACT_CLASS(wxVariantData, wxObject) wxVariant WXDLLEXPORT wxNullVariant; @@ -829,174 +822,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxVariantStringData, wxVariantData) IMPLEMENT_DYNAMIC_CLASS(wxVariantDataString, wxVariantData) #endif -/* - * wxVariantDataTime - */ - -// For some reason, Watcom C++ can't link variant.cpp with time/date classes compiled -#if wxUSE_TIMEDATE && !defined(__WATCOMC__) - -class wxVariantDataTime: public wxVariantData -{ - DECLARE_DYNAMIC_CLASS(wxVariantDataTime) -public: - wxVariantDataTime() { } - wxVariantDataTime(const wxTime& value) { m_value = value; } - - inline wxTime GetValue() const { return m_value; } - inline void SetValue(const wxTime& value) { m_value = value; } - - virtual void Copy(wxVariantData& data); - virtual bool Eq(wxVariantData& data) const; -#if wxUSE_STD_IOSTREAM - virtual bool Write(wxSTD ostream& str) const; -#endif - virtual bool Write(wxString& str) const; -#if wxUSE_STD_IOSTREAM - virtual bool Read(wxSTD istream& str); -#endif - virtual bool Read(wxString& str); - virtual wxString GetType() const { return wxT("time"); }; - virtual wxVariantData* Clone() { return new wxVariantDataTime; } - -protected: - wxTime m_value; -}; - -IMPLEMENT_DYNAMIC_CLASS(wxVariantDataTime, wxVariantData) - -void wxVariantDataTime::Copy(wxVariantData& data) -{ - wxASSERT_MSG( (data.GetType() == wxT("time")), wxT("wxVariantDataTime::Copy: Can't copy to this type of data") ); - - wxVariantDataTime& otherData = (wxVariantDataTime&) data; - - otherData.m_value = m_value; -} - -bool wxVariantDataTime::Eq(wxVariantData& data) const -{ - wxASSERT_MSG( (data.GetType() == wxT("time")), wxT("wxVariantDataTime::Eq: argument mismatch") ); - - wxVariantDataTime& otherData = (wxVariantDataTime&) data; - - return (otherData.m_value == m_value); -} - -#if wxUSE_STD_IOSTREAM -bool wxVariantDataTime::Write(wxSTD ostream& str) const -{ - wxString s; - Write(s); - str << (const char*) s.mb_str(); - return TRUE; -} -#endif - -bool wxVariantDataTime::Write(wxString& str) const -{ - wxChar*s = m_value.FormatTime(); - str = s; - return TRUE; -} - -#if wxUSE_STD_IOSTREAM -bool wxVariantDataTime::Read(wxSTD istream& WXUNUSED(str)) -{ - // Not implemented - return FALSE; -} -#endif - -bool wxVariantDataTime::Read(wxString& WXUNUSED(str)) -{ - // Not implemented - return FALSE; -} - -/* - * wxVariantDataDate - */ - -class wxVariantDataDate: public wxVariantData -{ - DECLARE_DYNAMIC_CLASS(wxVariantDataDate) -public: - wxVariantDataDate() { } - wxVariantDataDate(const wxDate& value) { m_value = value; } - - inline wxDate GetValue() const { return m_value; } - inline void SetValue(const wxDate& value) { m_value = value; } - - virtual void Copy(wxVariantData& data); - virtual bool Eq(wxVariantData& data) const; -#if wxUSE_STD_IOSTREAM - virtual bool Write(wxSTD ostream& str) const; -#endif - virtual bool Write(wxString& str) const; -#if wxUSE_STD_IOSTREAM - virtual bool Read(wxSTD istream& str); -#endif - virtual bool Read(wxString& str); - virtual wxString GetType() const { return wxT("date"); }; - virtual wxVariantData* Clone() { return new wxVariantDataDate; } - -protected: - wxDate m_value; -}; - -IMPLEMENT_DYNAMIC_CLASS(wxVariantDataDate, wxVariantData) - -void wxVariantDataDate::Copy(wxVariantData& data) -{ - wxASSERT_MSG( (data.GetType() == wxT("date")), wxT("wxVariantDataDate::Copy: Can't copy to this type of data") ); - - wxVariantDataDate& otherData = (wxVariantDataDate&) data; - - otherData.m_value = m_value; -} - -bool wxVariantDataDate::Eq(wxVariantData& data) const -{ - wxASSERT_MSG( (data.GetType() == wxT("date")), wxT("wxVariantDataDate::Eq: argument mismatch") ); - - wxVariantDataDate& otherData = (wxVariantDataDate&) data; - - return (otherData.m_value == m_value); -} - -#if wxUSE_STD_IOSTREAM -bool wxVariantDataDate::Write(wxSTD ostream& str) const -{ - wxString s; - Write(s); - str << (const char*) s.mb_str(); - return TRUE; -} -#endif - -bool wxVariantDataDate::Write(wxString& str) const -{ - str = m_value.FormatDate(); - return TRUE; -} - -#if wxUSE_STD_IOSTREAM -bool wxVariantDataDate::Read(wxSTD istream& WXUNUSED(str)) -{ - // Not implemented - return FALSE; -} -#endif - -bool wxVariantDataDate::Read(wxString& WXUNUSED(str)) -{ - // Not implemented - return FALSE; -} -#endif - // wxUSE_TIMEDATE - /* * wxVariantDataVoidPtr */ @@ -1084,6 +909,8 @@ bool wxVariantDataVoidPtr::Read(wxString& WXUNUSED(str)) * wxVariantDataDateTime */ +#if wxUSE_DATETIME + class wxVariantDataDateTime: public wxVariantData { DECLARE_DYNAMIC_CLASS(wxVariantDataDateTime) @@ -1176,6 +1003,8 @@ bool wxVariantDataDateTime::Read(wxString& str) return TRUE; } +#endif // wxUSE_DATETIME + // ---------------------------------------------------------------------------- // wxVariantDataArrayString // ---------------------------------------------------------------------------- @@ -1338,32 +1167,19 @@ wxVariant::wxVariant(const wxList& val, const wxString& name) // List of variant m_name = name; } -// For some reason, Watcom C++ can't link variant.cpp with time/date classes compiled -#if wxUSE_TIMEDATE && !defined(__WATCOMC__) -wxVariant::wxVariant(const wxTime& val, const wxString& name) // Time +wxVariant::wxVariant( void* val, const wxString& name) { - m_data = new wxVariantDataTime(val); - m_name = name; -} - -wxVariant::wxVariant(const wxDate& val, const wxString& name) // Date -{ - m_data = new wxVariantDataDate(val); - m_name = name; -} -#endif - -wxVariant::wxVariant(void* val, const wxString& name) // Void ptr -{ - m_data = new wxVariantDataVoidPtr(val); - m_name = name; + m_data = new wxVariantDataVoidPtr(val); + m_name = name; } +#if wxUSE_DATETIME wxVariant::wxVariant(const wxDateTime& val, const wxString& name) // Date { - m_data = new wxVariantDataDateTime(val); - m_name = name; + m_data = new wxVariantDataDateTime(val); + m_name = name; } +#endif // wxUSE_DATETIME #if wxUSE_ODBC wxVariant::wxVariant(const TIME_STRUCT* valptr, const wxString& name) // Date @@ -1678,65 +1494,6 @@ void wxVariant::operator= (const wxList& value) } } -// For some reason, Watcom C++ can't link variant.cpp with time/date classes compiled -#if wxUSE_TIMEDATE && !defined(__WATCOMC__) -bool wxVariant::operator== (const wxTime& value) const -{ - wxTime thisValue; - if (!Convert(&thisValue)) - return FALSE; - - return value == thisValue; -} - -bool wxVariant::operator!= (const wxTime& value) const -{ - return (!((*this) == value)); -} - -void wxVariant::operator= (const wxTime& value) -{ - if (GetType() == wxT("time")) - { - ((wxVariantDataTime*)GetData())->SetValue(value); - } - else - { - if (m_data) - delete m_data; - m_data = new wxVariantDataTime(value); - } -} - -bool wxVariant::operator== (const wxDate& value) const -{ - wxDate thisValue; - if (!Convert(&thisValue)) - return FALSE; - - return (value == thisValue); -} - -bool wxVariant::operator!= (const wxDate& value) const -{ - return (!((*this) == value)); -} - -void wxVariant::operator= (const wxDate& value) -{ - if (GetType() == wxT("date")) - { - ((wxVariantDataTime*)GetData())->SetValue(value); - } - else - { - if (m_data) - delete m_data; - m_data = new wxVariantDataDate(value); - } -} -#endif - bool wxVariant::operator== (void* value) const { return (value == ((wxVariantDataVoidPtr*)GetData())->GetValue()); @@ -1761,6 +1518,7 @@ void wxVariant::operator= (void* value) } } +#if wxUSE_DATETIME bool wxVariant::operator== (const wxDateTime& value) const { wxDateTime thisValue; @@ -1788,6 +1546,7 @@ void wxVariant::operator= (const wxDateTime& value) m_data = new wxVariantDataDateTime(value); } } +#endif // wxUSE_DATETIME #if wxUSE_ODBC void wxVariant::operator= (const DATE_STRUCT* value) @@ -1999,31 +1758,6 @@ wxString wxVariant::GetString() const return value; } -// For some reason, Watcom C++ can't link variant.cpp with time/date classes compiled -#if wxUSE_TIMEDATE && !defined(__WATCOMC__) -wxTime wxVariant::GetTime() const -{ - wxTime value; - if (!Convert(& value)) - { - wxFAIL_MSG(wxT("Could not convert to a time")); - } - - return value; -} - -wxDate wxVariant::GetDate() const -{ - wxDate value; - if (!Convert(& value)) - { - wxFAIL_MSG(wxT("Could not convert to a date")); - } - - return value; -} -#endif // wxUSE_TIMEDATE - void* wxVariant::GetVoidPtr() const { wxASSERT( (GetType() == wxT("void*")) ); @@ -2031,6 +1765,7 @@ void* wxVariant::GetVoidPtr() const return (void*) ((wxVariantDataVoidPtr*) m_data)->GetValue(); } +#if wxUSE_DATETIME wxDateTime wxVariant::GetDateTime() const { wxDateTime value; @@ -2041,6 +1776,7 @@ wxDateTime wxVariant::GetDateTime() const return value; } +#endif // wxUSE_DATETIME wxList& wxVariant::GetList() const { @@ -2215,33 +1951,7 @@ bool wxVariant::Convert(wxString* value) const return TRUE; } -// For some reason, Watcom C++ can't link variant.cpp with time/date classes compiled -#if wxUSE_TIMEDATE && !defined(__WATCOMC__) -bool wxVariant::Convert(wxTime* value) const -{ - wxString type(GetType()); - if (type == wxT("time")) - *value = ((wxVariantDataTime*)GetData())->GetValue(); - else if (type == wxT("date")) - *value = wxTime(((wxVariantDataDate*)GetData())->GetValue()); - else - return FALSE; - - return TRUE; -} - -bool wxVariant::Convert(wxDate* value) const -{ - wxString type(GetType()); - if (type == wxT("date")) - *value = ((wxVariantDataDate*)GetData())->GetValue(); - else - return FALSE; - - return TRUE; -} -#endif // wxUSE_TIMEDATE - +#if wxUSE_DATETIME bool wxVariant::Convert(wxDateTime* value) const { wxString type(GetType()); @@ -2254,3 +1964,5 @@ bool wxVariant::Convert(wxDateTime* value) const wxString val; return Convert(&val) && (value->ParseDate(val)); } +#endif // wxUSE_DATETIME +