Skip to content

Commit

Permalink
Make wxXmlResource::ms_subclassFactories vector of smart pointers
Browse files Browse the repository at this point in the history
Replace another (pointer to a) wxVector of raw pointers with a vector of
smart pointers.

This is just another simplification.
  • Loading branch information
vadz committed Jan 27, 2023
1 parent f457f99 commit 2c49a6c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
3 changes: 1 addition & 2 deletions include/wx/xrc/xmlres.h
Expand Up @@ -46,7 +46,6 @@ class WXDLLIMPEXP_FWD_CORE wxToolBar;
class WXDLLIMPEXP_FWD_XML wxXmlDocument;
class WXDLLIMPEXP_FWD_XML wxXmlNode;
class WXDLLIMPEXP_FWD_XRC wxXmlSubclassFactory;
class wxXmlSubclassFactories;
class wxXmlResourceModule;
class wxXmlResourceDataRecords;

Expand Down Expand Up @@ -427,7 +426,7 @@ class WXDLLIMPEXP_XRC wxXmlResource : public wxObject
friend class wxIdRangeManager;
friend class wxIdRange;

static wxXmlSubclassFactories *ms_subclassFactories;
static std::vector<std::unique_ptr<wxXmlSubclassFactory>> ms_subclassFactories;

// singleton instance:
static wxXmlResource *ms_instance;
Expand Down
28 changes: 5 additions & 23 deletions src/xrc/xmlres.cpp
Expand Up @@ -1385,20 +1385,11 @@ void wxIdRangeManager::FinaliseRanges(const wxXmlNode* node)
}


class wxXmlSubclassFactories : public wxVector<wxXmlSubclassFactory*>
{
// this is a class so that it can be forward-declared
};

wxXmlSubclassFactories *wxXmlResource::ms_subclassFactories = nullptr;
std::vector<std::unique_ptr<wxXmlSubclassFactory>> wxXmlResource::ms_subclassFactories;

/*static*/ void wxXmlResource::AddSubclassFactory(wxXmlSubclassFactory *factory)
{
if (!ms_subclassFactories)
{
ms_subclassFactories = new wxXmlSubclassFactories;
}
ms_subclassFactories->push_back(factory);
ms_subclassFactories.push_back(std::unique_ptr<wxXmlSubclassFactory>{factory});
}

class wxXmlSubclassFactoryCXX : public wxXmlSubclassFactory
Expand Down Expand Up @@ -1453,10 +1444,9 @@ wxObject *wxXmlResourceHandlerImpl::CreateResource(wxXmlNode *node, wxObject *pa
wxString subclass = node->GetAttribute(wxT("subclass"), wxEmptyString);
if (!subclass.empty())
{
for (wxXmlSubclassFactories::iterator i = wxXmlResource::ms_subclassFactories->begin();
i != wxXmlResource::ms_subclassFactories->end(); ++i)
for (auto& factory : wxXmlResource::ms_subclassFactories)
{
m_handler->m_instance = (*i)->Create(subclass);
m_handler->m_instance = factory->Create(subclass);
if (m_handler->m_instance)
break;
}
Expand Down Expand Up @@ -3171,15 +3161,7 @@ class wxXmlResourceModule: public wxModule
{
delete wxXmlResource::Set(nullptr);
delete wxIdRangeManager::Set(nullptr);
if(wxXmlResource::ms_subclassFactories)
{
for ( wxXmlSubclassFactories::iterator i = wxXmlResource::ms_subclassFactories->begin();
i != wxXmlResource::ms_subclassFactories->end(); ++i )
{
delete *i;
}
wxDELETE(wxXmlResource::ms_subclassFactories);
}
wxXmlResource::ms_subclassFactories.clear();
CleanXRCID_Records();
}
};
Expand Down

0 comments on commit 2c49a6c

Please sign in to comment.