From f03d1af43160cdf26dd710540cd053c0b373406a Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 30 Aug 2013 12:35:22 -0700 Subject: [PATCH] Tree::addBranch - Now returns a pointer to the new node, for convenience. Throws on error. --- src/parser/Tree.cpp | 6 +++++- src/parser/Tree.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/parser/Tree.cpp b/src/parser/Tree.cpp index a6e77490f..c7956c455 100644 --- a/src/parser/Tree.cpp +++ b/src/parser/Tree.cpp @@ -76,10 +76,14 @@ Tree* Tree::operator[] (const int branch) } //////////////////////////////////////////////////////////////////////////////// -void Tree::addBranch (Tree* branch) +Tree* Tree::addBranch (Tree* branch) { + if (! branch) + throw "Failed to allocate memory for parse tree."; + branch->_trunk = this; _branches.push_back (branch); + return branch; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/parser/Tree.h b/src/parser/Tree.h index 6ef10b36e..fae8ebfd1 100644 --- a/src/parser/Tree.h +++ b/src/parser/Tree.h @@ -42,7 +42,7 @@ public: Tree& operator= (const Tree&); Tree* operator[] (const int); - void addBranch (Tree*); + Tree* addBranch (Tree*); void removeBranch (Tree*); void replaceBranch (Tree*, Tree*); int branches ();