Add wxThreadEvent::SetPayload<T>().
This makes it possible to easily pass custom data between threads, in type-safe way (thanks to internal use of wxAny). This adds sizeof(wxAny)==16+sizeof(void*) overhead to wxThreadEvent, but I think it's cheaper than doing malloc/free on copying. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63187 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include "wx/thread.h"
|
||||
#include "wx/tracker.h"
|
||||
#include "wx/typeinfo.h"
|
||||
#include "wx/any.h"
|
||||
|
||||
#ifdef wxHAS_EVENT_BIND
|
||||
#include "wx/meta/convertible.h"
|
||||
@@ -1203,6 +1204,10 @@ public:
|
||||
// make sure our string member (which uses COW, aka refcounting) is not
|
||||
// shared by other wxString instances:
|
||||
SetString(GetString().c_str());
|
||||
|
||||
#if wxUSE_ANY && (!defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7))
|
||||
m_payload = event.m_payload;
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual wxEvent *Clone() const
|
||||
@@ -1215,6 +1220,23 @@ public:
|
||||
virtual wxEventCategory GetEventCategory() const
|
||||
{ return wxEVT_CATEGORY_THREAD; }
|
||||
|
||||
#if wxUSE_ANY && (!defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7))
|
||||
template<typename T>
|
||||
void SetPayload(const T& payload)
|
||||
{
|
||||
m_payload = payload;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T GetPayload() const
|
||||
{
|
||||
return m_payload.As<T>();
|
||||
}
|
||||
|
||||
protected:
|
||||
wxAny m_payload;
|
||||
#endif // wxUSE_ANY && (!defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7))
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxThreadEvent)
|
||||
};
|
||||
|
Reference in New Issue
Block a user