Make wxListItemData movable and not copyable

This class contains (sometimes) owned pointers and so can't be copied
but it can be moved, so make it moveable.

No real changes, this is done in preparation for storing objects of this
type in a std::vector.
This commit is contained in:
Vadim Zeitlin
2023-01-19 02:11:43 +01:00
parent f547bf0647
commit a5777cdcbd
2 changed files with 26 additions and 0 deletions
+4
View File
@@ -50,6 +50,10 @@ class wxListItemData
{
public:
wxListItemData(wxListMainWindow *owner);
wxListItemData(const wxListItemData&) = delete;
wxListItemData(wxListItemData&&);
wxListItemData& operator=(const wxListItemData&) = delete;
wxListItemData& operator=(wxListItemData&&);
~wxListItemData();
void SetItem( const wxListItem &info );
+22
View File
@@ -107,6 +107,28 @@ WX_DEFINE_LIST(wxListHeaderDataList)
// wxListItemData
// ----------------------------------------------------------------------------
wxListItemData::wxListItemData(wxListItemData&& other)
{
m_owner = other.m_owner;
// Take ownership of the pointers from the other object and reset them.
std::swap(m_attr, other.m_attr);
std::swap(m_rect, other.m_rect);
}
wxListItemData& wxListItemData::operator=(wxListItemData&& other)
{
m_image = other.m_image;
m_data = other.m_data;
m_owner = other.m_owner;
// Swap them to let our pointers be deleted by the other object if necessary.
std::swap(m_attr, other.m_attr);
std::swap(m_rect, other.m_rect);
return *this;
}
wxListItemData::~wxListItemData()
{
// in the virtual list control the attributes are managed by the main