\membersection{wxXmlNode::InsertChild}\label{wxxmlnodeinsertchild}
-\func{void}{InsertChild}{\param{wxXmlNode* }{child}, \param{wxXmlNode* }{before\_node}}
+\func{bool}{InsertChild}{\param{wxXmlNode* }{child}, \param{wxXmlNode* }{before\_node}}
Inserts the {\it child} node after {\it before\_node} in the children list.
+If {\it before\_node} is \NULL, then {\it child} is prepended to the list of children and
+becomes the first child of this node.
+Returns \true if {\it before\_node} has been found and the {\it child} node has been inserted.
\membersection{wxXmlNode::RemoveChild}\label{wxxmlnoderemovechild}
wxXmlNode(wxXmlNodeType type, const wxString& name,
const wxString& content = wxEmptyString);
virtual void AddChild(wxXmlNode *child);
- virtual void InsertChild(wxXmlNode *child, wxXmlNode *before_node);
+ virtual bool InsertChild(wxXmlNode *child, wxXmlNode *before_node);
virtual bool RemoveChild(wxXmlNode *child);
virtual void AddProperty(const wxString& name, const wxString& value);
virtual bool DeleteProperty(const wxString& name);
child->m_parent = this;
}
-void wxXmlNode::InsertChild(wxXmlNode *child, wxXmlNode *before_node)
+bool wxXmlNode::InsertChild(wxXmlNode *child, wxXmlNode *before_node)
{
- wxASSERT_MSG(before_node->GetParent() == this, wxT("wxXmlNode::InsertChild - the node has incorrect parent"));
+ wxCHECK_MSG(before_node == NULL || before_node->GetParent() == this, false,
+ wxT("wxXmlNode::InsertChild - the node has incorrect parent"));
+ wxCHECK_MSG(child, false, wxT("Cannot insert a NULL pointer!"));
if (m_children == before_node)
m_children = child;
+ else if (m_children == NULL)
+ {
+ if (before_node != NULL)
+ return false; // we have no children so we don't need to search
+ m_children = child;
+ }
+ else if (before_node == NULL)
+ {
+ // prepend child
+ child->m_parent = this;
+ child->m_next = m_children;
+ m_children = child;
+ return true;
+ }
else
{
wxXmlNode *ch = m_children;
- while (ch->m_next != before_node) ch = ch->m_next;
+ while (ch && ch->m_next != before_node) ch = ch->m_next;
+ if (!ch)
+ return false; // before_node not found
ch->m_next = child;
}
child->m_parent = this;
child->m_next = before_node;
+ return true;
}
bool wxXmlNode::RemoveChild(wxXmlNode *child)