summaryrefslogtreecommitdiff
path: root/src/nodetree.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nodetree.cc')
-rw-r--r--src/nodetree.cc35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/nodetree.cc b/src/nodetree.cc
index f0877ff..f4baebb 100644
--- a/src/nodetree.cc
+++ b/src/nodetree.cc
@@ -111,11 +111,6 @@ NodeIdList NodeTree::insertAsChild(nodeid_t parentid, nodeid_t id,
{
NodeIdList affectedNodes;
- if(parentid == id)
- {
- throw Error::NewParentIsSelf(); // Node and new parent are the same node.
- }
-
// Initialized?
if(!root)
{
@@ -124,24 +119,28 @@ NodeIdList NodeTree::insertAsChild(nodeid_t parentid, nodeid_t id,
root = node;
node->data = data;
affectedNodes.push_back(id);
+ return affectedNodes;
}
- else
+
+ if(parentid == id)
{
- if(!hasId(parentid))
- {
- throw Error::MissingParent();
- }
+ throw Error::NewParentIsSelf(); // Node and new parent are the same node.
+ }
- Node* parent = id2node.at(parentid);
- Node* child = createNode(id);
+ if(!hasId(parentid))
+ {
+ throw Error::MissingParent();
+ }
- child->data = data;
- insertChild(parent, child, insertBeforeId);
- affectedNodes.push_back(id);
+ Node* parent = id2node.at(parentid);
+ Node* child = createNode(id);
- NodeIdList ancestors = ancestorList(id);
- concatNodeIdLists(affectedNodes, ancestors);
- }
+ child->data = data;
+ insertChild(parent, child, insertBeforeId);
+ affectedNodes.push_back(id);
+
+ NodeIdList ancestors = ancestorList(id);
+ concatNodeIdLists(affectedNodes, ancestors);
return affectedNodes;
}