Use unique_ptr<> in wxXmlDocument
Replace manual use of raw pointer with std::unique_ptr<>. No real changes.
This commit is contained in:
parent
2a5eac26f4
commit
0b049be4b7
2 changed files with 15 additions and 15 deletions
|
|
@ -21,6 +21,8 @@
|
|||
#include "wx/textbuf.h"
|
||||
#include "wx/versioninfo.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#ifdef WXMAKINGDLL_XML
|
||||
#define WXDLLIMPEXP_XML WXEXPORT
|
||||
#elif defined(WXUSINGDLL)
|
||||
|
|
@ -231,7 +233,7 @@ public:
|
|||
const wxString& encoding = wxT("UTF-8"));
|
||||
wxXmlDocument(wxInputStream& stream,
|
||||
const wxString& encoding = wxT("UTF-8"));
|
||||
virtual ~wxXmlDocument() { delete m_docNode; }
|
||||
~wxXmlDocument() = default;
|
||||
|
||||
wxXmlDocument(const wxXmlDocument& doc);
|
||||
wxXmlDocument& operator=(const wxXmlDocument& doc);
|
||||
|
|
@ -252,7 +254,7 @@ public:
|
|||
// Returns root node of the document.
|
||||
wxXmlNode *GetRoot() const;
|
||||
// Returns the document node.
|
||||
wxXmlNode *GetDocumentNode() const { return m_docNode; }
|
||||
wxXmlNode *GetDocumentNode() const { return m_docNode.get(); }
|
||||
|
||||
|
||||
// Returns version of document (may be empty).
|
||||
|
|
@ -267,8 +269,8 @@ public:
|
|||
wxString GetEOL() const { return m_eol; }
|
||||
|
||||
// Write-access methods:
|
||||
wxXmlNode *DetachDocumentNode() { wxXmlNode *old=m_docNode; m_docNode=nullptr; return old; }
|
||||
void SetDocumentNode(wxXmlNode *node) { delete m_docNode; m_docNode = node; }
|
||||
wxXmlNode *DetachDocumentNode() { return m_docNode.release(); }
|
||||
void SetDocumentNode(wxXmlNode *node) { m_docNode.reset(node); }
|
||||
wxXmlNode *DetachRoot();
|
||||
void SetRoot(wxXmlNode *node);
|
||||
void SetVersion(const wxString& version) { m_version = version; }
|
||||
|
|
@ -283,7 +285,7 @@ private:
|
|||
wxString m_version;
|
||||
wxString m_fileEncoding;
|
||||
wxXmlDoctype m_doctype;
|
||||
wxXmlNode *m_docNode = nullptr;
|
||||
std::unique_ptr<wxXmlNode> m_docNode;
|
||||
wxTextFileType m_fileType = wxTextFileType_Unix;
|
||||
wxString m_eol = wxS("\n");
|
||||
|
||||
|
|
|
|||
|
|
@ -464,8 +464,6 @@ wxXmlDocument::wxXmlDocument(const wxXmlDocument& doc)
|
|||
|
||||
wxXmlDocument& wxXmlDocument::operator=(const wxXmlDocument& doc)
|
||||
{
|
||||
delete m_docNode;
|
||||
|
||||
DoCopy(doc);
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -479,9 +477,9 @@ void wxXmlDocument::DoCopy(const wxXmlDocument& doc)
|
|||
m_eol = doc.m_eol;
|
||||
|
||||
if (doc.m_docNode)
|
||||
m_docNode = new wxXmlNode(*doc.m_docNode);
|
||||
m_docNode.reset(new wxXmlNode(*doc.m_docNode));
|
||||
else
|
||||
m_docNode = nullptr;
|
||||
m_docNode.reset();
|
||||
}
|
||||
|
||||
bool wxXmlDocument::Load(const wxString& filename, const wxString& encoding, int flags)
|
||||
|
|
@ -502,7 +500,7 @@ bool wxXmlDocument::Save(const wxString& filename, int indentstep) const
|
|||
|
||||
wxXmlNode *wxXmlDocument::GetRoot() const
|
||||
{
|
||||
wxXmlNode *node = m_docNode;
|
||||
wxXmlNode *node = m_docNode.get();
|
||||
if (node)
|
||||
{
|
||||
node = m_docNode->GetChildren();
|
||||
|
|
@ -514,7 +512,7 @@ wxXmlNode *wxXmlDocument::GetRoot() const
|
|||
|
||||
wxXmlNode *wxXmlDocument::DetachRoot()
|
||||
{
|
||||
wxXmlNode *node = m_docNode;
|
||||
wxXmlNode *node = m_docNode.get();
|
||||
if (node)
|
||||
{
|
||||
node = m_docNode->GetChildren();
|
||||
|
|
@ -547,7 +545,7 @@ void wxXmlDocument::SetRoot(wxXmlNode *root)
|
|||
"Can only set an element type node as root" );
|
||||
}
|
||||
|
||||
wxXmlNode *node = m_docNode;
|
||||
wxXmlNode *node = m_docNode.get();
|
||||
if (node)
|
||||
{
|
||||
node = m_docNode->GetChildren();
|
||||
|
|
@ -569,11 +567,11 @@ void wxXmlDocument::SetRoot(wxXmlNode *root)
|
|||
}
|
||||
else
|
||||
{
|
||||
m_docNode = new wxXmlNode(wxXML_DOCUMENT_NODE, wxEmptyString);
|
||||
m_docNode.reset(new wxXmlNode(wxXML_DOCUMENT_NODE, wxEmptyString));
|
||||
m_docNode->SetChildren(root);
|
||||
}
|
||||
if (root)
|
||||
root->SetParent(m_docNode);
|
||||
root->SetParent(m_docNode.get());
|
||||
}
|
||||
|
||||
void wxXmlDocument::SetFileType(wxTextFileType fileType)
|
||||
|
|
@ -585,7 +583,7 @@ void wxXmlDocument::SetFileType(wxTextFileType fileType)
|
|||
void wxXmlDocument::AppendToProlog(wxXmlNode *node)
|
||||
{
|
||||
if (!m_docNode)
|
||||
m_docNode = new wxXmlNode(wxXML_DOCUMENT_NODE, wxEmptyString);
|
||||
m_docNode.reset(new wxXmlNode(wxXML_DOCUMENT_NODE, wxEmptyString));
|
||||
if (IsOk())
|
||||
m_docNode->InsertChild( node, GetRoot() );
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue