X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cee8636e94d49319b1c108d8b2d826e080e2e366..20125017a4bccd0920ee21e178950b0de0e4d63b:/src/xml/xml.cpp?ds=sidebyside diff --git a/src/xml/xml.cpp b/src/xml/xml.cpp index 0e82fffd01..0fc27c246b 100644 --- a/src/xml/xml.cpp +++ b/src/xml/xml.cpp @@ -58,6 +58,8 @@ wxXmlNode::wxXmlNode(wxXmlNode *parent,wxXmlNodeType type, m_lineNo(lineNo), m_noConversion(false) { + wxASSERT_MSG ( type != wxXML_ELEMENT_NODE || content.empty(), "element nodes can't have content" ); + if (m_parent) { if (m_parent->m_children) @@ -77,7 +79,9 @@ wxXmlNode::wxXmlNode(wxXmlNodeType type, const wxString& name, m_attrs(NULL), m_parent(NULL), m_children(NULL), m_next(NULL), m_lineNo(lineNo), m_noConversion(false) -{} +{ + wxASSERT_MSG ( type != wxXML_ELEMENT_NODE || content.empty(), "element nodes can't have content" ); +} wxXmlNode::wxXmlNode(const wxXmlNode& node) { @@ -87,6 +91,22 @@ wxXmlNode::wxXmlNode(const wxXmlNode& node) } wxXmlNode::~wxXmlNode() +{ + DoFree(); +} + +wxXmlNode& wxXmlNode::operator=(const wxXmlNode& node) +{ + if ( &node != this ) + { + DoFree(); + DoCopy(node); + } + + return *this; +} + +void wxXmlNode::DoFree() { wxXmlNode *c, *c2; for (c = m_children; c; c = c2) @@ -103,14 +123,6 @@ wxXmlNode::~wxXmlNode() } } -wxXmlNode& wxXmlNode::operator=(const wxXmlNode& node) -{ - wxDELETE(m_attrs); - wxDELETE(m_children); - DoCopy(node); - return *this; -} - void wxXmlNode::DoCopy(const wxXmlNode& node) { m_type = node.m_type; @@ -451,7 +463,7 @@ void wxXmlDocument::DoCopy(const wxXmlDocument& doc) bool wxXmlDocument::Load(const wxString& filename, const wxString& encoding, int flags) { wxFileInputStream stream(filename); - if (!stream.Ok()) + if (!stream.IsOk()) return false; return Load(stream, encoding, flags); } @@ -459,7 +471,7 @@ bool wxXmlDocument::Load(const wxString& filename, const wxString& encoding, int bool wxXmlDocument::Save(const wxString& filename, int indentstep) const { wxFileOutputStream stream(filename); - if (!stream.Ok()) + if (!stream.IsOk()) return false; return Save(stream, indentstep); } @@ -505,6 +517,12 @@ wxXmlNode *wxXmlDocument::DetachRoot() void wxXmlDocument::SetRoot(wxXmlNode *root) { + if (root) + { + wxASSERT_MSG( root->GetType() == wxXML_ELEMENT_NODE, + "Can only set an element type node as root" ); + } + wxXmlNode *node = m_docNode; if (node) { @@ -515,7 +533,7 @@ void wxXmlDocument::SetRoot(wxXmlNode *root) prev = node; node = node->GetNext(); } - if (node) + if (node && root) { root->SetNext( node->GetNext() ); wxDELETE(node); @@ -528,8 +546,10 @@ void wxXmlDocument::SetRoot(wxXmlNode *root) else { m_docNode = new wxXmlNode(wxXML_DOCUMENT_NODE, wxEmptyString); + m_docNode->SetChildren(root); } - root->SetParent(m_docNode); + if (root) + root->SetParent(m_docNode); } void wxXmlDocument::AppendToProlog(wxXmlNode *node)