git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49246
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
- Removed global GetLine() function from wx/protocol/protocol.h, use
wxProtocol::ReadLine() instead.
- Removed global GetLine() function from wx/protocol/protocol.h, use
wxProtocol::ReadLine() instead.
+
+- wxVariant no longer derives from wxObject. wxVariantData also no longer
+ derives from wxObject; instead of using wxDynamicCast with wxVariantData you
+ can use the macro wxDynamicCastVariantData with the same arguments.
Deprecated methods and their replacements
Deprecated methods and their replacements
- Documentation now includes the wx library in which each class is defined.
- wxrc --gettext now generates references to source .xrc files (Heikki
Linnakangas).
- Documentation now includes the wx library in which each class is defined.
- wxrc --gettext now generates references to source .xrc files (Heikki
Linnakangas).
+- wxVariant::Unshare allows exclusive allocation of data that must be shared,
+ if the wxVariantData::Clone function is implemented.
Note that as of wxWidgets 2.9.0, wxVariantData no longer inherits from wxObject
and wxVariant no longer uses the type-unsafe wxList class for list
Note that as of wxWidgets 2.9.0, wxVariantData no longer inherits from wxObject
and wxVariant no longer uses the type-unsafe wxList class for list
-operations but the type-safe wxVariantList class.
+operations but the type-safe wxVariantList class. Also, wxVariantData now
+supports the Clone function for implementing the \helpref{wxVariant::Unshare}{wxvariantunshare} function.
+Clone is implemented automatically by IMPLEMENT\_VARIANT\_OBJECT.
+
+Since wxVariantData no longer derives from wxObject, any code that tests the type
+of the data using wxDynamicCast will require adjustment. You can use the macro
+wxDynamicCastVariantData with the same arguments as wxDynamicCast, to use C++ RTTI
+type information instead of wxWidgets RTTI.
Sets the internal variant data, deleting the existing data if there is any.
Sets the internal variant data, deleting the existing data if there is any.
+\membersection{wxVariant::Unshare}\label{wxvariantunshare}
+
+\func{bool}{Unshare}{\void}
+
+Makes sure that any data associated with this variant is not shared with other
+variants. For this to work, \helpref{wxVariantData::Clone}{wxvariantdataclone} must
+be implemented for the data types you are working with. Clone is implemented
+for all the default data types.
+
\membersection{wxVariant::operator $=$}\label{wxvariantassignment}
\func{void}{operator $=$}{\param{const wxVariant\& }{value}}
\membersection{wxVariant::operator $=$}\label{wxvariantassignment}
\func{void}{operator $=$}{\param{const wxVariant\& }{value}}
+\membersection{wxVariantData::Clone}\label{wxvariantdataclone}
+
+\constfunc{wxVariantData*}{Clone}{\void}
+
+This function can be overridden to clone the data.
+Implement Clone if you wish \helpref{wxVariant::Unshare}{wxvariantunshare} to work
+for your data. This function is implemented for all built-in data types.
+
\membersection{wxVariantData::DecRef}\label{wxvariantdatadecref}
\func{void}{DecRef}{\void}
\membersection{wxVariantData::DecRef}\label{wxvariantdatadecref}
\func{void}{DecRef}{\void}
cannot be used as normal. Instead, \helpref{DecRef}{wxvariantdatadecref} should be called.
cannot be used as normal. Instead, \helpref{DecRef}{wxvariantdatadecref} should be called.
\membersection{wxVariantData::Eq}\label{wxvariantdataeq}
\constfunc{bool}{Eq}{\param{wxVariantData\&}{ data}}
\membersection{wxVariantData::Eq}\label{wxvariantdataeq}
\constfunc{bool}{Eq}{\param{wxVariantData\&}{ data}}
// If it based on wxObject return the ClassInfo.
virtual wxClassInfo* GetValueClassInfo() { return NULL; }
// If it based on wxObject return the ClassInfo.
virtual wxClassInfo* GetValueClassInfo() { return NULL; }
+ // Implement this to make wxVariant::AllocExcusive work. Returns
+ // a copy of the data.
+ virtual wxVariantData* Clone() const { return NULL; }
+
void IncRef() { m_count++; }
void DecRef()
{
void IncRef() { m_count++; }
void DecRef()
{
* wxVariant can store any kind of data, but has some basic types
* built in.
*/
* wxVariant can store any kind of data, but has some basic types
* built in.
*/
class WXDLLIMPEXP_FWD_BASE wxVariant;
WX_DECLARE_LIST_WITH_DECL(wxVariant, wxVariantList, class WXDLLIMPEXP_BASE);
class WXDLLIMPEXP_FWD_BASE wxVariant;
WX_DECLARE_LIST_WITH_DECL(wxVariant, wxVariantList, class WXDLLIMPEXP_BASE);
// destroy a reference
void UnRef();
// destroy a reference
void UnRef();
+ // ensure that the data is exclusive to this variant, and not shared
+ bool Unshare();
+
// Make NULL (i.e. delete the data)
void MakeNull();
// Make NULL (i.e. delete the data)
void MakeNull();
\
virtual wxString GetType() const; \
virtual wxClassInfo* GetValueClassInfo(); \
\
virtual wxString GetType() const; \
virtual wxClassInfo* GetValueClassInfo(); \
+\
+ virtual wxVariantData* Clone() const { return new classname##VariantData(m_value); } \
\
protected:\
classname m_value; \
\
protected:\
classname m_value; \
((classname*)(var.IsValueKindOf(&classname::ms_classInfo) ?\
var.GetWxObjectPtr() : NULL));
((classname*)(var.IsValueKindOf(&classname::ms_classInfo) ?\
var.GetWxObjectPtr() : NULL));
+// Replacement for using wxDynamicCast on a wxVariantData object
+#define wxDynamicCastVariantData(data, classname) dynamic_cast<classname*>(data)
+
extern wxVariant WXDLLIMPEXP_BASE wxNullVariant;
#endif // wxUSE_VARIANT
extern wxVariant WXDLLIMPEXP_BASE wxNullVariant;
#endif // wxUSE_VARIANT
return (!(*this == variant));
}
return (!(*this == variant));
}
wxString wxVariant::MakeString() const
{
if (!IsNull())
wxString wxVariant::MakeString() const
{
if (!IsNull())
+bool wxVariant::Unshare()
+{
+ if ( m_data && m_data->GetRefCount() > 1 )
+ {
+ // note that ref is not going to be destroyed in this case...
+ const wxVariantData* ref = m_data;
+ UnRef();
+
+ // ... so we can still access it
+ m_data = ref->Clone();
+
+ wxASSERT_MSG( (m_data && m_data->GetRefCount() == 1),
+ _T("wxVariant::AllocExclusive() failed.") );
+
+ if (!m_data || m_data->GetRefCount() != 1)
+ return false;
+ else
+ return true;
+ }
+ //else: data is null or ref count is 1, so we are exclusive owners of m_refData anyhow
+ else
+ return true;
+}
+
// Returns a string representing the type of the variant,
// e.g. "string", "bool", "list", "double", "long"
// Returns a string representing the type of the variant,
// e.g. "string", "bool", "list", "double", "long"
virtual bool Write(wxOutputStream &str) const;
#endif // wxUSE_STREAMS
virtual bool Write(wxOutputStream &str) const;
#endif // wxUSE_STREAMS
+ wxVariantData* Clone() const { return new wxVariantDataLong(m_value); }
+
virtual wxString GetType() const { return wxT("long"); }
protected:
virtual wxString GetType() const { return wxT("long"); }
protected:
#endif // wxUSE_STREAMS
virtual wxString GetType() const { return wxT("double"); }
#endif // wxUSE_STREAMS
virtual wxString GetType() const { return wxT("double"); }
+ wxVariantData* Clone() const { return new wxVariantDoubleData(m_value); }
protected:
double m_value;
};
protected:
double m_value;
};
#endif // wxUSE_STREAMS
virtual wxString GetType() const { return wxT("bool"); }
#endif // wxUSE_STREAMS
virtual wxString GetType() const { return wxT("bool"); }
+ wxVariantData* Clone() const { return new wxVariantDataBool(m_value); }
protected:
bool m_value;
};
protected:
bool m_value;
};
virtual bool Write(wxOutputStream& str) const;
#endif // wxUSE_STREAMS
virtual wxString GetType() const { return wxT("char"); }
virtual bool Write(wxOutputStream& str) const;
#endif // wxUSE_STREAMS
virtual wxString GetType() const { return wxT("char"); }
+ wxVariantData* Clone() const { return new wxVariantDataChar(m_value); }
protected:
wxUniChar m_value;
protected:
wxUniChar m_value;
virtual bool Write(wxOutputStream& str) const;
#endif // wxUSE_STREAMS
virtual wxString GetType() const { return wxT("string"); }
virtual bool Write(wxOutputStream& str) const;
#endif // wxUSE_STREAMS
virtual wxString GetType() const { return wxT("string"); }
+ wxVariantData* Clone() const { return new wxVariantDataString(m_value); }
protected:
wxString m_value;
protected:
wxString m_value;
#endif
virtual bool Read(wxString& str);
virtual wxString GetType() const ;
#endif
virtual bool Read(wxString& str);
virtual wxString GetType() const ;
- virtual wxVariantData* Clone() { return new wxVariantDataWxObjectPtr; }
+ virtual wxVariantData* Clone() const { return new wxVariantDataWxObjectPtr(m_value); }
virtual wxClassInfo* GetValueClassInfo();
virtual wxClassInfo* GetValueClassInfo();
protected:
wxObject* m_value;
};
protected:
wxObject* m_value;
};
wxString wxVariantDataWxObjectPtr::GetType() const
{
wxString returnVal(wxT("wxObject*"));
wxString wxVariantDataWxObjectPtr::GetType() const
{
wxString returnVal(wxT("wxObject*"));
if (m_value)
{
returnVal = m_value->GetClassInfo()->GetClassName();
returnVal += wxT("*");
}
if (m_value)
{
returnVal = m_value->GetClassInfo()->GetClassName();
returnVal += wxT("*");
}
#endif
virtual bool Read(wxString& str);
virtual wxString GetType() const { return wxT("void*"); }
#endif
virtual bool Read(wxString& str);
virtual wxString GetType() const { return wxT("void*"); }
- virtual wxVariantData* Clone() { return new wxVariantDataVoidPtr; }
+ virtual wxVariantData* Clone() const { return new wxVariantDataVoidPtr(m_value); }
protected:
void* m_value;
protected:
void* m_value;
#endif
virtual bool Read(wxString& str);
virtual wxString GetType() const { return wxT("datetime"); }
#endif
virtual bool Read(wxString& str);
virtual wxString GetType() const { return wxT("datetime"); }
- virtual wxVariantData* Clone() { return new wxVariantDataDateTime; }
+ virtual wxVariantData* Clone() const { return new wxVariantDataDateTime(m_value); }
protected:
wxDateTime m_value;
protected:
wxDateTime m_value;
#endif
virtual bool Read(wxString& str);
virtual wxString GetType() const { return wxT("arrstring"); }
#endif
virtual bool Read(wxString& str);
virtual wxString GetType() const { return wxT("arrstring"); }
- virtual wxVariantData* Clone() { return new wxVariantDataArrayString; }
+ virtual wxVariantData* Clone() const { return new wxVariantDataArrayString(m_value); }
protected:
wxArrayString m_value;
protected:
wxArrayString m_value;
+ wxVariantData* Clone() const { return new wxVariantDataList(m_value); }
protected:
wxVariantList m_value;
};
protected:
wxVariantList m_value;
};