Use std::unordered_map<> in wxRichTextXMLHandler
Also move the map itself as well as the inline methods using it to the source file to avoid having to include <unordered_map> from the header unnecessarily.
This commit is contained in:
parent
01c73be2bb
commit
5adb77018b
2 changed files with 22 additions and 8 deletions
|
|
@ -15,7 +15,6 @@
|
|||
* Includes
|
||||
*/
|
||||
|
||||
#include "wx/hashmap.h"
|
||||
#include "wx/richtext/richtextbuffer.h"
|
||||
#include "wx/richtext/richtextstyles.h"
|
||||
|
||||
|
|
@ -217,12 +216,12 @@ public:
|
|||
Call with XML node name, C++ class name so that wxRTC can read in the node.
|
||||
If you add a custom object, call this.
|
||||
*/
|
||||
static void RegisterNodeName(const wxString& nodeName, const wxString& className) { sm_nodeNameToClassMap[nodeName] = className; }
|
||||
static void RegisterNodeName(const wxString& nodeName, const wxString& className);
|
||||
|
||||
/**
|
||||
Cleans up the mapping between node name and C++ class.
|
||||
*/
|
||||
static void ClearNodeToClassMap() { sm_nodeNameToClassMap.clear(); }
|
||||
static void ClearNodeToClassMap();
|
||||
|
||||
protected:
|
||||
#if wxUSE_STREAMS
|
||||
|
|
@ -231,8 +230,6 @@ protected:
|
|||
#endif
|
||||
|
||||
wxRichTextXMLHelper m_helper;
|
||||
|
||||
static wxStringToStringHashMap sm_nodeNameToClassMap;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@
|
|||
#include "wx/stopwatch.h"
|
||||
#include "wx/xml/xml.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
// Set to 1 for slower wxXmlDocument method, 0 for faster direct method.
|
||||
// If we make wxXmlDocument::Save more efficient, we might switch to this
|
||||
// method.
|
||||
|
|
@ -50,7 +52,12 @@
|
|||
|
||||
wxIMPLEMENT_DYNAMIC_CLASS(wxRichTextXMLHandler, wxRichTextFileHandler);
|
||||
|
||||
wxStringToStringHashMap wxRichTextXMLHandler::sm_nodeNameToClassMap;
|
||||
namespace
|
||||
{
|
||||
|
||||
std::unordered_map<wxString, wxString> gs_nodeNameToClassMap;
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
void wxRichTextXMLHandler::Init()
|
||||
{
|
||||
|
|
@ -111,12 +118,22 @@ bool wxRichTextXMLHandler::DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& s
|
|||
return success;
|
||||
}
|
||||
|
||||
void wxRichTextXMLHandler::RegisterNodeName(const wxString& nodeName, const wxString& className)
|
||||
{
|
||||
gs_nodeNameToClassMap[nodeName] = className;
|
||||
}
|
||||
|
||||
void wxRichTextXMLHandler::ClearNodeToClassMap()
|
||||
{
|
||||
gs_nodeNameToClassMap.clear();
|
||||
}
|
||||
|
||||
/// Creates an object given an XML element name
|
||||
wxRichTextObject* wxRichTextXMLHandler::CreateObjectForXMLName(wxRichTextObject* WXUNUSED(parent), const wxString& name) const
|
||||
{
|
||||
// The standard node to class mappings are added in wxRichTextModule::OnInit in richtextbuffer.cpp
|
||||
wxStringToStringHashMap::const_iterator it = sm_nodeNameToClassMap.find(name);
|
||||
if (it == sm_nodeNameToClassMap.end())
|
||||
const auto it = gs_nodeNameToClassMap.find(name);
|
||||
if (it == gs_nodeNameToClassMap.end())
|
||||
return nullptr;
|
||||
else
|
||||
return wxDynamicCast(wxCreateDynamicObject(it->second), wxRichTextObject);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue