From: John L. <jr...@us...> - 2006-09-07 22:42:26
|
Update of /cvsroot/wxlua/wxLua/modules/wxluadebug/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv4262/wxLua/modules/wxluadebug/src Modified Files: staktree.cpp wxldebug.cpp Log Message: make wxLuaDebugData derived from wxObject and ref counted so we don't have to remember to delete it or check NULL make the wxTread in wxLuaDebugServer part of the class as wxLuaDebugTarget does Index: wxldebug.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxluadebug/src/wxldebug.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** wxldebug.cpp 28 Aug 2006 05:26:20 -0000 1.16 --- wxldebug.cpp 7 Sep 2006 22:42:19 -0000 1.17 *************** *** 60,91 **** // ---------------------------------------------------------------------------- ! wxLuaDebugData::wxLuaDebugData() : wxLuaDebugDataItemArray(wxLuaDebugData::SortFunction) { } ! wxLuaDebugData::~wxLuaDebugData() { ! size_t idx, count = Count(); ! for (idx = 0; idx < count; ++idx) ! { ! const wxLuaDebugDataItem *pData = Item(idx); ! delete pData; ! } } ! wxLuaDebugData *wxLuaDebugData::Clone() const { ! wxLuaDebugData *pCloneData = new wxLuaDebugData; ! if (pCloneData != NULL) { ! size_t idx, count = Count(); ! for (idx = 0; idx < count; ++idx) ! { ! const wxLuaDebugDataItem *pOldData = Item(idx); ! if (pOldData != NULL) ! pCloneData->Add(new wxLuaDebugDataItem(*pOldData)); ! } } ! return pCloneData; } --- 60,107 ---- // ---------------------------------------------------------------------------- ! class wxLuaDebugDataRefData : public wxObjectRefData { + public: + wxLuaDebugDataRefData() : m_dataArray(wxLuaDebugData::SortFunction) {} + ~wxLuaDebugDataRefData() + { + size_t idx, count = m_dataArray.Count(); + for (idx = 0; idx < count; ++idx) + { + const wxLuaDebugDataItem *pData = m_dataArray.Item(idx); + delete pData; + } + } + + wxLuaDebugDataItemArray m_dataArray; + }; + + wxLuaDebugData::wxLuaDebugData() : wxObject() + { + m_refData = new wxLuaDebugDataRefData; } ! wxLuaDebugDataItemArray& wxLuaDebugData::GetDataArray() { ! return ((wxLuaDebugDataRefData*)m_refData)->m_dataArray; ! } ! const wxLuaDebugDataItemArray& wxLuaDebugData::GetDataArray() const ! { ! return ((wxLuaDebugDataRefData*)m_refData)->m_dataArray; } ! wxLuaDebugData wxLuaDebugData::Copy() const { ! wxLuaDebugData copyData; ! ! size_t idx, count = GetDataArray().Count(); ! for (idx = 0; idx < count; ++idx) { ! const wxLuaDebugDataItem *pOldData = GetDataArray().Item(idx); ! if (pOldData != NULL) ! copyData.GetDataArray().Add(new wxLuaDebugDataItem(*pOldData)); } ! ! return copyData; } *************** *** 130,134 **** if (item != NULL) { ! Add(item); count++; } --- 146,150 ---- if (item != NULL) { ! GetDataArray().Add(item); count++; } *************** *** 179,183 **** if (item != NULL) { ! Add(item); count++; } --- 195,199 ---- if (item != NULL) { ! GetDataArray().Add(item); count++; } *************** *** 201,205 **** lua_pushvalue(L, LUA_GLOBALSINDEX); int nRef = wxlState.tinsert(-1); ! Add(new wxLuaDebugDataItem(wxT("Globals"), wxT(""), wxT(""), wxT(""), nRef, 0)); references.Add(nRef); } --- 217,221 ---- lua_pushvalue(L, LUA_GLOBALSINDEX); int nRef = wxlState.tinsert(-1); ! GetDataArray().Add(new wxLuaDebugDataItem(wxT("Globals"), wxT(""), wxT(""), wxT(""), nRef, 0)); references.Add(nRef); } *************** *** 236,240 **** if (item != NULL) { ! Add(item); count++; } --- 252,256 ---- if (item != NULL) { ! GetDataArray().Add(item); count++; } *************** *** 403,443 **** } ! wxLuaDebugData *wxLuaInterface::EnumerateStack() { ! wxLuaDebugData *pSortedList = new wxLuaDebugData(); ! if (pSortedList != NULL) ! pSortedList->EnumerateStack(m_wxlState); ! ! return pSortedList; } ! wxLuaDebugData *wxLuaInterface::EnumerateStackEntry(int nEntry) { ! wxLuaDebugData *pSortedList = new wxLuaDebugData(); ! if (pSortedList != NULL) ! pSortedList->EnumerateStackEntry(m_wxlState, nEntry, m_references); ! ! return pSortedList; } ! wxLuaDebugData *wxLuaInterface::EnumerateTable(int nRef, int nIndex, long WXUNUSED(data)) { ! wxLuaDebugData *pSortedList = new wxLuaDebugData(); ! if (pSortedList != NULL) ! pSortedList->EnumerateTable(m_wxlState, nRef, nIndex, m_references); ! ! return pSortedList; } ! wxLuaDebugData *wxLuaInterface::GetGlobalData() { ! wxLuaDebugData *pSortedList = new wxLuaDebugData(); ! if (pSortedList != NULL) ! { ! m_wxlState.GetGlobals(); ! int nRef = Ref(); ! pSortedList->Add(new wxLuaDebugDataItem(wxT("Globals"), wxT(""), wxT(""), wxT(""), nRef, 0)); ! } ! return pSortedList; } --- 419,450 ---- } ! wxLuaDebugData wxLuaInterface::EnumerateStack() { ! wxLuaDebugData debugData; ! debugData.EnumerateStack(m_wxlState); ! return debugData; } ! wxLuaDebugData wxLuaInterface::EnumerateStackEntry(int nEntry) { ! wxLuaDebugData debugData; ! debugData.EnumerateStackEntry(m_wxlState, nEntry, m_references); ! return debugData; } ! wxLuaDebugData wxLuaInterface::EnumerateTable(int nRef, int nIndex, long WXUNUSED(data)) { ! wxLuaDebugData debugData; ! debugData.EnumerateTable(m_wxlState, nRef, nIndex, m_references); ! return debugData; } ! wxLuaDebugData wxLuaInterface::GetGlobalData() { ! wxLuaDebugData debugData; ! m_wxlState.GetGlobals(); ! int nRef = Ref(); ! debugData.GetDataArray().Add(new wxLuaDebugDataItem(wxT("Globals"), wxT(""), wxT(""), wxT(""), nRef, 0)); ! return debugData; } Index: staktree.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxluadebug/src/staktree.cpp,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** staktree.cpp 28 Aug 2006 05:26:20 -0000 1.26 --- staktree.cpp 7 Sep 2006 22:42:19 -0000 1.27 *************** *** 150,159 **** else { ! wxLuaDebugData *pSortedList = m_luaInterface->EnumerateStack(); ! if (pSortedList != NULL) ! { ! FillStackCombobox(pSortedList); ! delete pSortedList; ! } } --- 150,155 ---- else { ! wxLuaDebugData debugData = m_luaInterface->EnumerateStack(); ! FillStackCombobox(debugData); } *************** *** 166,177 **** } ! void wxLuaStackDialog::FillStackCombobox(const wxLuaDebugData *pSortedList) { m_stackComboBox->Clear(); ! size_t idx, count = pSortedList->Count(); for (idx = 0; idx < count; ++idx) { ! const wxLuaDebugDataItem *item = pSortedList->Item(idx); #if defined(__WXMAC__) // FIXME Mac is dying on the two parameter version...don't know how to fix. --- 162,173 ---- } ! void wxLuaStackDialog::FillStackCombobox(const wxLuaDebugData& debugData) { m_stackComboBox->Clear(); ! size_t idx, count = debugData.GetDataArray().Count(); for (idx = 0; idx < count; ++idx) { ! const wxLuaDebugDataItem *item = debugData.GetDataArray().Item(idx); #if defined(__WXMAC__) // FIXME Mac is dying on the two parameter version...don't know how to fix. *************** *** 182,186 **** } ! if (pSortedList->Count() > 0) { m_stackComboBox->SetSelection(0); --- 178,182 ---- } ! if (debugData.GetDataArray().Count() > 0) { m_stackComboBox->SetSelection(0); *************** *** 230,243 **** else { ! wxLuaDebugData *pSortedList = m_luaInterface->EnumerateStackEntry(nEntry); ! if (pSortedList != NULL) ! { ! FillStackEntry(nEntry, pSortedList); ! delete pSortedList; ! } } } ! void wxLuaStackDialog::FillStackEntry(int WXUNUSED(nEntry), const wxLuaDebugData *pSortedList) { m_treeControl->DeleteAllItems(); --- 226,235 ---- else { ! wxLuaDebugData debugData = m_luaInterface->EnumerateStackEntry(nEntry); ! FillStackEntry(nEntry, debugData); } } ! void wxLuaStackDialog::FillStackEntry(int WXUNUSED(nEntry), const wxLuaDebugData& debugData) { m_treeControl->DeleteAllItems(); *************** *** 245,252 **** m_treeControl->AdjustRemoteScrollbars(); ! size_t idx, count = pSortedList->Count(); for (idx = 0; idx < count; ++idx) { ! const wxLuaDebugDataItem *item = pSortedList->Item(idx); int nOffset = (item->GetReference() != LUA_NOREF) ? 0 : 1; --- 237,244 ---- m_treeControl->AdjustRemoteScrollbars(); ! size_t idx, count = debugData.GetDataArray().Count(); for (idx = 0; idx < count; ++idx) { ! const wxLuaDebugDataItem *item = debugData.GetDataArray().Item(idx); int nOffset = (item->GetReference() != LUA_NOREF) ? 0 : 1; *************** *** 268,273 **** else { ! wxLuaDebugData *pSortedList = m_luaInterface->GetGlobalData(); ! const wxLuaDebugDataItem *item = pSortedList->Item(0); wxTreeItemId treeNode = m_treeControl->AppendItem( rootItem, --- 260,265 ---- else { ! wxLuaDebugData globalDebugData = m_luaInterface->GetGlobalData(); ! const wxLuaDebugDataItem *item = globalDebugData.GetDataArray().Item(0); wxTreeItemId treeNode = m_treeControl->AppendItem( rootItem, *************** *** 281,286 **** GetDerivedAndTrackedItems(m_treeControl, rootItem); - - delete pSortedList; } } --- 273,276 ---- *************** *** 328,340 **** if (itemNode) { ! wxLuaDebugDataItem *pDebugData = (wxLuaDebugDataItem *)m_treeControl->GetItemData(itemNode); ! if ((pDebugData != NULL) && !pDebugData->IsExpanded()) { ! pDebugData->SetExpanded(true); ! int nRef = pDebugData->GetReference(); if (nRef != LUA_NOREF) { ! int nIndex = pDebugData->GetIndex() + 1; if (m_luaInterface->IsDebugServer()) --- 318,330 ---- if (itemNode) { ! wxLuaDebugDataItem *pDebugDataItem = (wxLuaDebugDataItem *)m_treeControl->GetItemData(itemNode); ! if ((pDebugDataItem != NULL) && !pDebugDataItem->IsExpanded()) { ! pDebugDataItem->SetExpanded(true); ! int nRef = pDebugDataItem->GetReference(); if (nRef != LUA_NOREF) { ! int nIndex = pDebugDataItem->GetIndex() + 1; if (m_luaInterface->IsDebugServer()) *************** *** 345,361 **** { // insert items ! wxLuaDebugData *pSortedList = m_luaInterface->EnumerateTable(nRef, nIndex); ! if (pSortedList != NULL) ! { ! FillTableEntry(itemNode, pSortedList); ! delete pSortedList; ! } } } else if (!m_luaInterface->IsDebugServer() && m_luaInterface->GetwxLuaState().Ok() && ! ((pDebugData->GetName() == _("Tracked List")) || ! (pDebugData->GetName() == _("Event Handler List")) || ! (pDebugData->GetName() == _("wxWindow List")))) { wxLuaState wxlState(m_luaInterface->GetwxLuaState()); --- 335,347 ---- { // insert items ! wxLuaDebugData debugData = m_luaInterface->EnumerateTable(nRef, nIndex); ! FillTableEntry(itemNode, debugData); } } else if (!m_luaInterface->IsDebugServer() && m_luaInterface->GetwxLuaState().Ok() && ! ((pDebugDataItem->GetName() == _("Tracked List")) || ! (pDebugDataItem->GetName() == _("Event Handler List")) || ! (pDebugDataItem->GetName() == _("wxWindow List")))) { wxLuaState wxlState(m_luaInterface->GetwxLuaState()); *************** *** 364,368 **** wxArrayInt counts; ! if (pDebugData->GetName() == _("Tracked List")) { wxLongToLongHashMap::iterator it; --- 350,354 ---- wxArrayInt counts; ! if (pDebugDataItem->GetName() == _("Tracked List")) { wxLongToLongHashMap::iterator it; *************** *** 386,390 **** } } ! else if (pDebugData->GetName() == _("Event Handler List")) { wxNode* node = wxlState.GetTrackedEventHandlerList()->GetFirst(); --- 372,376 ---- } } ! else if (pDebugDataItem->GetName() == _("Event Handler List")) { wxNode* node = wxlState.GetTrackedEventHandlerList()->GetFirst(); *************** *** 430,443 **** } ! wxLuaDebugData* dataArr = new wxLuaDebugData; size_t n, count = names.GetCount(); for (n = 0; n < count; n++) { ! wxLuaDebugDataItem *item = new wxLuaDebugDataItem(names[n], wxT("wxLuaData"), wxString::Format(wxT("%d"), counts[n]), wxT(""), LUA_NOREF, pDebugData->GetIndex() + 1); ! dataArr->Add(item); } FillTableEntry(itemNode, dataArr); - delete dataArr; } } --- 416,428 ---- } ! wxLuaDebugData dataArr; size_t n, count = names.GetCount(); for (n = 0; n < count; n++) { ! wxLuaDebugDataItem *item = new wxLuaDebugDataItem(names[n], wxT("wxLuaData"), wxString::Format(wxT("%d"), counts[n]), wxT(""), LUA_NOREF, pDebugDataItem->GetIndex() + 1); ! dataArr.GetDataArray().Add(item); } FillTableEntry(itemNode, dataArr); } } *************** *** 445,458 **** } ! void wxLuaStackDialog::FillTableEntry(wxTreeItemId itemNode, const wxLuaDebugData *pSortedList) { ! if (pSortedList->Count() == 0) m_treeControl->SetItemHasChildren(itemNode, false); else { ! size_t n, count = pSortedList->Count(); for (n = 0; n < count; ++n) { ! const wxLuaDebugDataItem *item = pSortedList->Item(n); int nOffset = (item->GetReference() != LUA_NOREF) ? 0 : 1; --- 430,443 ---- } ! void wxLuaStackDialog::FillTableEntry(wxTreeItemId itemNode, const wxLuaDebugData& debugData) { ! if (debugData.GetDataArray().Count() == 0) m_treeControl->SetItemHasChildren(itemNode, false); else { ! size_t n, count = debugData.GetDataArray().Count(); for (n = 0; n < count; ++n) { ! const wxLuaDebugDataItem *item = debugData.GetDataArray().Item(n); int nOffset = (item->GetReference() != LUA_NOREF) ? 0 : 1; |