From e39d30c05b9febb396cd9f133b9df7718142e299 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Mon, 7 Jan 2008 15:12:46 +0000 Subject: [PATCH] Correct wxObjectDataPtr<> assignment from *T to not increase the ref count git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51076 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/objectdataptr.tex | 5 +++-- include/wx/object.h | 9 ++++++--- samples/dataview/dataview.cpp | 13 ++++++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/docs/latex/wx/objectdataptr.tex b/docs/latex/wx/objectdataptr.tex index d75a1bf10c..f6777ff59c 100644 --- a/docs/latex/wx/objectdataptr.tex +++ b/docs/latex/wx/objectdataptr.tex @@ -146,8 +146,9 @@ counted object to which this class points. \constfunc{T*}{operator->}{\void} -Gets a pointer to the reference counted object to which -this class points. Same as \helpref{get}{wxobjectdataptrget}. +Returns a pointer to the reference counted object to which +this class points. If this the internal pointer is NULL, +this method will assert in debug mode. \membersection{wxObjectDataPtr::operator=}\label{wxobjectdataptroperatorassign} diff --git a/include/wx/object.h b/include/wx/object.h index e24fc89e1c..df40c11d43 100644 --- a/include/wx/object.h +++ b/include/wx/object.h @@ -456,7 +456,12 @@ public: } T *get() const { return m_ptr; } - T *operator->() const { return get(); } + + T *operator->() const + { + wxASSERT(m_ptr != NULL); + return get(); + } void reset(T *ptr) { @@ -480,8 +485,6 @@ public: if (m_ptr) m_ptr->DecRef(); m_ptr = ptr; - if (m_ptr) - m_ptr->IncRef(); return *this; } diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index 96477f0ae4..1654696615 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -168,6 +168,11 @@ public: wxT("German Requiem"), wxT("Johannes Brahms"), 1868 ) ); m_classicalMusicIsKnownToControl = false; } + + ~MyMusicModel() + { + delete m_root; + } // helper method for wxLog @@ -575,6 +580,7 @@ class MyFrame : public wxFrame { public: MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int h); + ~MyFrame(); public: void OnQuit(wxCommandEvent& event); @@ -832,7 +838,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int child = treectrl2->AppendItem( parent,wxT("Child 1"), 0 ); child = treectrl2->AppendItem( parent,wxT("Child 2"), 0 ); child = treectrl2->AppendItem( parent,wxT("Child 3"), 0 ); - + bottom_sizer->Add( treectrl2 ); // main sizer @@ -842,6 +848,11 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int SetSizer( main_sizer ); } +MyFrame::~MyFrame() +{ + delete wxLog::SetActiveTarget(m_logOld); +} + void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) ) { Close(true); -- 2.45.2