From acd15a3fa015caf2d1e3213a7694b05c92d5b49c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 21 Nov 2001 21:44:52 +0000 Subject: [PATCH] 1. removed wxObject::CopyObject() and Clone() - some objects just can't be copied 2. made wxEvent::Clone() pure virtual and added missing Clone()s to the other event classes which this changes has helped to discover git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12566 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dialup.h | 3 +++ include/wx/event.h | 6 ++++-- include/wx/generic/laywin.h | 18 ++++++++++++------ include/wx/object.h | 2 -- include/wx/process.h | 6 +++++- include/wx/sckaddr.h | 13 +++++++++---- include/wx/timer.h | 3 +++ src/common/event.cpp | 2 +- src/common/http.cpp | 4 ++-- src/common/object.cpp | 16 ---------------- src/common/sckaddr.cpp | 18 +++++------------- 11 files changed, 44 insertions(+), 47 deletions(-) diff --git a/include/wx/dialup.h b/include/wx/dialup.h index 765be09891..27a0c033c9 100644 --- a/include/wx/dialup.h +++ b/include/wx/dialup.h @@ -179,6 +179,9 @@ public: // process (i.e. does it result from our own attempt to establish the // connection)? bool IsOwnEvent() const { return m_id != 0; } + + // implement the base class pure virtual + virtual wxEvent *Clone() const { return new wxDialUpEvent(*this); } }; // the type of dialup event handler function diff --git a/include/wx/event.h b/include/wx/event.h index c13191c6f8..92f0ef19b1 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -359,8 +359,10 @@ public: // exists only for optimization purposes. bool IsCommandEvent() const { return m_isCommandEvent; } - // specialized clone function since it is done a lot - virtual wxEvent *Clone() const { return new wxEvent(*this); } + // this function is used to create a copy of the event polymorphically and + // all derived classes must implement it because otherwise wxPostEvent() + // for them wouldn't work (it needs to do a copy of the event) + virtual wxEvent *Clone() const = 0; public: wxObject* m_eventObject; diff --git a/include/wx/generic/laywin.h b/include/wx/generic/laywin.h index 7c241c701d..7f8b13cb39 100644 --- a/include/wx/generic/laywin.h +++ b/include/wx/generic/laywin.h @@ -91,6 +91,8 @@ public: void SetAlignment(wxLayoutAlignment align) { m_alignment = align; } wxLayoutAlignment GetAlignment() const { return m_alignment; } + virtual wxEvent *Clone() const { return new wxQueryLayoutInfoEvent(*this); } + protected: int m_flags; int m_requestedLength; @@ -119,13 +121,17 @@ public: m_flags = 0; m_id = id; } -// Read by the app - inline void SetFlags(int flags) { m_flags = flags; } - inline int GetFlags() const { return m_flags; } -// Set by the app - inline void SetRect(const wxRect& rect) { m_rect = rect; } - inline wxRect GetRect() const { return m_rect; } + // Read by the app + void SetFlags(int flags) { m_flags = flags; } + int GetFlags() const { return m_flags; } + + // Set by the app + void SetRect(const wxRect& rect) { m_rect = rect; } + wxRect GetRect() const { return m_rect; } + + virtual wxEvent *Clone() const { return new wxCalculateLayoutEvent(*this); } + protected: int m_flags; wxRect m_rect; diff --git a/include/wx/object.h b/include/wx/object.h index 845d0e238c..316d8d569c 100644 --- a/include/wx/object.h +++ b/include/wx/object.h @@ -221,8 +221,6 @@ class WXDLLEXPORT wxObject virtual ~wxObject(void); virtual wxClassInfo *GetClassInfo(void) const { return &sm_classwxObject; } - wxObject *Clone(void) const; - virtual void CopyObject(wxObject& object_dest) const; bool IsKindOf(wxClassInfo *info) const; diff --git a/include/wx/process.h b/include/wx/process.h index cfc4ca9627..91c71032eb 100644 --- a/include/wx/process.h +++ b/include/wx/process.h @@ -114,8 +114,12 @@ public: // the exit code int GetExitCode() { return m_exitcode; } + // implement the base class pure virtual + virtual wxEvent *Clone() const { return new wxProcessEvent(*this); } + public: - int m_pid, m_exitcode; + int m_pid, + m_exitcode; DECLARE_DYNAMIC_CLASS(wxProcessEvent) }; diff --git a/include/wx/sckaddr.h b/include/wx/sckaddr.h index 39e5188792..000673d1d2 100644 --- a/include/wx/sckaddr.h +++ b/include/wx/sckaddr.h @@ -39,7 +39,9 @@ public: void SetAddress(GAddress *address); const wxSockAddress& operator =(const wxSockAddress& addr); - void CopyObject(wxObject& dest) const; + // we need to be able to create copies of the addresses polymorphically (i.e. + // wihtout knowing the exact address class) + virtual wxSockAddress *Clone() const = 0; protected: GAddress *m_address; @@ -61,7 +63,8 @@ public: wxString Hostname(); unsigned short Service(); - inline int Type() { return wxSockAddress::IPV4; } + virtual int Type() { return wxSockAddress::IPV4; } + virtual wxSockAddress *Clone() const { return new wxIPV4address(*this); } }; #ifdef ENABLE_IPV6 @@ -82,7 +85,8 @@ public: wxString Hostname() const; unsigned short Service() const; - inline int Type() { return wxSockAddress::IPV6; } + virtual int Type() { return wxSockAddress::IPV6; } + virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); } }; #endif @@ -103,7 +107,8 @@ public: void Filename(const wxString& name); wxString Filename(); - inline int Type() { return wxSockAddress::UNIX; } + virtual int Type() { return wxSockAddress::UNIX; } + virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); } }; #endif // __UNIX__ diff --git a/include/wx/timer.h b/include/wx/timer.h index c7459e9152..f835029b3c 100644 --- a/include/wx/timer.h +++ b/include/wx/timer.h @@ -167,6 +167,9 @@ public: // accessors int GetInterval() const { return m_interval; } + // implement the base class pure virtual + virtual wxEvent *Clone() const { return new wxTimerEvent(*this); } + private: int m_interval; diff --git a/src/common/event.cpp b/src/common/event.cpp index 450a0faae9..5e618cc09f 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -638,7 +638,7 @@ void wxEvtHandler::AddPendingEvent(wxEvent& event) if ( !m_pendingEvents ) m_pendingEvents = new wxList; - wxEvent *event2 = (wxEvent *)event.Clone(); + wxEvent *event2 = event.Clone(); m_pendingEvents->Append(event2); diff --git a/src/common/http.cpp b/src/common/http.cpp index 4bcfd76870..8471c33926 100644 --- a/src/common/http.cpp +++ b/src/common/http.cpp @@ -185,11 +185,11 @@ bool wxHTTP::Connect(wxSockAddress& addr, bool WXUNUSED(wait)) { if (m_addr) { delete m_addr; - m_addr = NULL; Close(); } - m_addr = (wxSockAddress *) addr.Clone(); + m_addr = addr.Clone(); + return TRUE; } diff --git a/src/common/object.cpp b/src/common/object.cpp index 83a8fec5ad..a444c031ee 100644 --- a/src/common/object.cpp +++ b/src/common/object.cpp @@ -99,22 +99,6 @@ bool wxObject::IsKindOf(wxClassInfo *info) const return FALSE; } -wxObject *wxObject::Clone() const -{ - wxObject *object = GetClassInfo()->CreateObject(); - CopyObject(*object); - return object; -} - -#ifdef __WXDEBUG__ -void wxObject::CopyObject(wxObject& object_dest) const -#else // !Debug -void wxObject::CopyObject(wxObject& WXUNUSED(object_dest)) const -#endif // Debug/!Debug -{ - wxASSERT(object_dest.GetClassInfo()->IsKindOf(GetClassInfo())); -} - #if wxUSE_STD_IOSTREAM && (defined(__WXDEBUG__) || wxUSE_DEBUG_CONTEXT) void wxObject::Dump(wxSTD ostream& str) { diff --git a/src/common/sckaddr.cpp b/src/common/sckaddr.cpp index 93e0ab3266..474a0f3092 100644 --- a/src/common/sckaddr.cpp +++ b/src/common/sckaddr.cpp @@ -72,16 +72,8 @@ const wxSockAddress& wxSockAddress::operator=(const wxSockAddress& addr) return *this; } -void wxSockAddress::CopyObject(wxObject& dest) const -{ - wxSockAddress *addr = (wxSockAddress *)&dest; - - wxObject::CopyObject(dest); - addr->SetAddress(GetAddress()); -} - void wxSockAddress::Clear() -{ +{ GAddress_destroy(m_address); m_address = GAddress_new(); } @@ -102,7 +94,7 @@ wxIPV4address::~wxIPV4address() bool wxIPV4address::Hostname(const wxString& name) { // Some people are sometimes fool. - if (name == wxT("")) + if (name == wxT("")) { wxLogWarning( _("Trying to solve a NULL hostname: giving up") ); return FALSE; @@ -147,7 +139,7 @@ wxString wxIPV4address::Hostname() unsigned short wxIPV4address::Service() { - return GAddress_INET_GetPort(m_address); + return GAddress_INET_GetPort(m_address); } #if 0 @@ -196,7 +188,7 @@ const wxString& wxIPV6address::Hostname() unsigned short wxIPV6address::Service() { - return GAddress_INET_GetPort(m_address); + return GAddress_INET_GetPort(m_address); } #endif @@ -231,5 +223,5 @@ wxString wxUNIXaddress::Filename() #endif -#endif +#endif // wxUSE_SOCKETS -- 2.47.2