#ifdef __GNUG__
#pragma implementation "variant.h"
-#pragma implementation "time.h"
-#pragma implementation "date.h"
#endif
// For compilers that support precompilation, includes "wx/wx.h".
#endif
#endif
+#if defined(__MWERKS__) && __MSL__ >= 0x6000
+using namespace std ;
+#endif
+
#if wxUSE_STREAMS
#include "wx/stream.h"
#include "wx/txtstrm.h"
#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;
void wxVariantDataList::SetValue(const wxList& value)
{
Clear();
- wxNode* node = value.First();
+ wxNode* node = value.GetFirst();
while (node)
{
- wxVariant* var = (wxVariant*) node->Data();
+ wxVariant* var = (wxVariant*) node->GetData();
m_value.Append(new wxVariant(*var));
- node = node->Next();
+ node = node->GetNext();
}
}
void wxVariantDataList::Clear()
{
- wxNode* node = m_value.First();
+ wxNode* node = m_value.GetFirst();
while (node)
{
- wxVariant* var = (wxVariant*) node->Data();
+ wxVariant* var = (wxVariant*) node->GetData();
delete var;
- node = node->Next();
+ node = node->GetNext();
}
m_value.Clear();
}
wxVariantDataList& listData = (wxVariantDataList&) data;
listData.Clear();
- wxNode* node = m_value.First();
+ wxNode* node = m_value.GetFirst();
while (node)
{
- wxVariant* var = (wxVariant*) node->Data();
+ wxVariant* var = (wxVariant*) node->GetData();
listData.m_value.Append(new wxVariant(*var));
- node = node->Next();
+ node = node->GetNext();
}
}
wxASSERT_MSG( (data.GetType() == wxT("list")), wxT("wxVariantDataList::Eq: argument mismatch") );
wxVariantDataList& listData = (wxVariantDataList&) data;
- wxNode* node1 = m_value.First();
- wxNode* node2 = listData.GetValue().First();
+ wxNode* node1 = m_value.GetFirst();
+ wxNode* node2 = listData.GetValue().GetFirst();
while (node1 && node2)
{
- wxVariant* var1 = (wxVariant*) node1->Data();
- wxVariant* var2 = (wxVariant*) node2->Data();
+ wxVariant* var1 = (wxVariant*) node1->GetData();
+ wxVariant* var2 = (wxVariant*) node2->GetData();
if ((*var1) != (*var2))
return FALSE;
- node1 = node1->Next();
- node2 = node2->Next();
+ node1 = node1->GetNext();
+ node2 = node2->GetNext();
}
if (node1 || node2) return FALSE;
return TRUE;
bool wxVariantDataList::Write(wxString& str) const
{
str = wxT("");
- wxNode* node = m_value.First();
+ wxNode* node = m_value.GetFirst();
while (node)
{
- wxVariant* var = (wxVariant*) node->Data();
- if (node != m_value.First())
+ wxVariant* var = (wxVariant*) node->GetData();
+ if (node != m_value.GetFirst())
str += wxT(" ");
wxString str1;
str += var->MakeString();
- node = node->Next();
+ node = node->GetNext();
}
return TRUE;
wxASSERT_MSG( (data.GetType() == wxT("stringlist")), wxT("wxVariantDataStringList::Eq: argument mismatch") );
wxVariantDataStringList& listData = (wxVariantDataStringList&) data;
- wxNode* node1 = m_value.First();
- wxNode* node2 = listData.GetValue().First();
+ wxStringList::Node *node1 = m_value.GetFirst();
+ wxStringList::Node *node2 = listData.GetValue().GetFirst();
while (node1 && node2)
{
- wxString str1 ((wxChar*) node1->Data());
- wxString str2 ((wxChar*) node2->Data());
+ wxString str1 ( node1->GetData() );
+ wxString str2 ( node2->GetData() );
if (str1 != str2)
return FALSE;
- node1 = node1->Next();
- node2 = node2->Next();
+ node1 = node1->GetNext();
+ node2 = node2->GetNext();
}
if (node1 || node2) return FALSE;
return TRUE;
bool wxVariantDataStringList::Write(wxString& str) const
{
- str = wxT("");
- wxNode* node = m_value.First();
+ str.Empty();
+ wxStringList::Node *node = m_value.GetFirst();
while (node)
{
- wxChar* s = (wxChar*) node->Data();
- if (node != m_value.First())
+ wxChar* s = node->GetData();
+ if (node != m_value.GetFirst())
str += wxT(" ");
str += s;
- node = node->Next();
+ node = node->GetNext();
}
return TRUE;
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
*/
#endif
virtual bool Read(wxString& str);
virtual wxString GetType() const { return wxT("void*"); };
- virtual wxVariantData* Clone() { return new wxVariantDataVoidPtr; }
+ virtual wxVariantData* Clone() { return new wxVariantDataVoidPtr; }
protected:
void* m_value;
+
+ DECLARE_NO_COPY_CLASS(wxVariantDataVoidPtr)
};
IMPLEMENT_DYNAMIC_CLASS(wxVariantDataVoidPtr, wxVariantData)
* wxVariantDataDateTime
*/
+#if wxUSE_DATETIME
+
class wxVariantDataDateTime: public wxVariantData
{
DECLARE_DYNAMIC_CLASS(wxVariantDataDateTime)
return TRUE;
}
+#endif // wxUSE_DATETIME
+
// ----------------------------------------------------------------------------
// wxVariantDataArrayString
// ----------------------------------------------------------------------------
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
-{
- m_data = new wxVariantDataTime(val);
- m_name = name;
-}
-
-wxVariant::wxVariant(const wxDate& val, const wxString& name) // Date
+wxVariant::wxVariant( void* val, const wxString& name)
{
- 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;
-}
-
-wxVariant::wxVariant(const wxDateTime& val, const wxString& name) // Date
-{
- m_data = new wxVariantDataDateTime(val);
- m_name = name;
+ m_data = new wxVariantDataVoidPtr(val);
+ m_name = name;
}
#if wxUSE_ODBC
}
}
-// 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());
}
}
+#if wxUSE_DATETIME
bool wxVariant::operator== (const wxDateTime& value) const
{
wxDateTime thisValue;
m_data = new wxVariantDataDateTime(value);
}
}
+#endif // wxUSE_DATETIME
#if wxUSE_ODBC
void wxVariant::operator= (const DATE_STRUCT* value)
if (GetType() == wxT("list"))
{
wxVariantDataList* data = (wxVariantDataList*) m_data;
- wxASSERT_MSG( (idx < (size_t) data->GetValue().Number()), wxT("Invalid index for array") );
- return * (wxVariant*) (data->GetValue().Nth(idx)->Data());
+ wxASSERT_MSG( (idx < (size_t) data->GetValue().GetCount()), wxT("Invalid index for array") );
+ return * (wxVariant*) (data->GetValue().Item(idx)->GetData());
}
else if (GetType() == wxT("stringlist"))
{
wxVariantDataStringList* data = (wxVariantDataStringList*) m_data;
- wxASSERT_MSG( (idx < (size_t) data->GetValue().Number()), wxT("Invalid index for array") );
+ wxASSERT_MSG( (idx < (size_t) data->GetValue().GetCount()), wxT("Invalid index for array") );
- wxVariant variant( wxString( (wxChar*) (data->GetValue().Nth(idx)->Data()) ));
+ wxVariant variant( wxString( (wxChar*) (data->GetValue().Item(idx)->GetData()) ));
return variant;
}
return wxNullVariant;
wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for array operator") );
wxVariantDataList* data = (wxVariantDataList*) m_data;
- wxASSERT_MSG( (idx < (size_t) data->GetValue().Number()), wxT("Invalid index for array") );
+ wxASSERT_MSG( (idx < (size_t) data->GetValue().GetCount()), wxT("Invalid index for array") );
- return * (wxVariant*) (data->GetValue().Nth(idx)->Data());
+ return * (wxVariant*) (data->GetValue().Item(idx)->GetData());
}
// Return the number of elements in a list
if (GetType() == wxT("list"))
{
wxVariantDataList* data = (wxVariantDataList*) m_data;
- return data->GetValue().Number();
+ return data->GetValue().GetCount();
}
else if (GetType() == wxT("stringlist"))
{
wxVariantDataStringList* data = (wxVariantDataStringList*) m_data;
- return data->GetValue().Number();
+ return data->GetValue().GetCount();
}
return 0;
}
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*")) );
return (void*) ((wxVariantDataVoidPtr*) m_data)->GetValue();
}
+#if wxUSE_DATETIME
wxDateTime wxVariant::GetDateTime() const
{
wxDateTime value;
return value;
}
+#endif // wxUSE_DATETIME
wxList& wxVariant::GetList() const
{
{
wxList& list = GetList();
- wxNode* node = list.First();
+ wxNode* node = list.GetFirst();
while (node)
{
- wxVariant* other = (wxVariant*) node->Data();
+ wxVariant* other = (wxVariant*) node->GetData();
if (value == *other)
return TRUE;
- node = node->Next();
+ node = node->GetNext();
}
return FALSE;
}
{
wxList& list = GetList();
- wxASSERT_MSG( (item < list.Number()), wxT("Invalid index to Delete") );
- wxNode* node = list.Nth(item);
- wxVariant* variant = (wxVariant*) node->Data();
+ wxASSERT_MSG( (item < (int) list.GetCount()), wxT("Invalid index to Delete") );
+ wxNode* node = list.Item(item);
+ wxVariant* variant = (wxVariant*) node->GetData();
delete variant;
delete node;
return TRUE;
{
wxString val(((wxVariantDataString*)GetData())->GetValue());
val.MakeLower();
- if (val == wxT("true") || val == wxT("yes"))
+ if (val == wxT("TRUE") || val == wxT("yes"))
*value = TRUE;
- else if (val == wxT("false") || val == wxT("no"))
+ else if (val == wxT("FALSE") || val == wxT("no"))
*value = FALSE;
else
return FALSE;
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());
if (type == wxT("datetime"))
{
*value = ((wxVariantDataDateTime*)GetData())->GetValue();
- return TRUE;
- }
+ return TRUE;
+ }
// Fallback to string conversion
wxString val;
return Convert(&val) && (value->ParseDate(val));
}
+#endif // wxUSE_DATETIME
+