Tree::addBranch

- Now returns a pointer to the new node, for convenience.  Throws on error.
This commit is contained in:
Paul Beckingham 2013-08-30 12:35:22 -07:00
parent e651f7f759
commit f03d1af431
2 changed files with 6 additions and 2 deletions

View file

@ -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;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -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 ();