diff options
Diffstat (limited to 'src/tree.cc')
-rw-r--r-- | src/tree.cc | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/tree.cc b/src/tree.cc index 77d9f4e..8ccb108 100644 --- a/src/tree.cc +++ b/src/tree.cc @@ -28,17 +28,23 @@ namespace { namespace SimpleParser { -Tree::Tree(std::string term, const ConstantMap* constants): +Tree::Tree( + const std::string& term, + const ConstantMap* constants +): term_(term), - constants_(constants) { - this->root_node_ = this->buildTree(term); -} + constants_(constants), + node_collection_(), + root_node_{ this->buildTree(term) } { } + +Tree::Tree(const std::string& term): + Tree(term, nullptr) { } -double Tree::solve() { +double Tree::solve() const { return this->root_node_->solve(); } -std::string Tree::print() { +std::string Tree::print() const { std::stringstream out; out.precision(std::numeric_limits<double>::digits10); @@ -60,7 +66,8 @@ std::string Tree::print() { << "\"];" << std::endl; - if ( node->type() == NodeType::OPERATOR ) { + if ( node->rightChild != nullptr && + node->leftChild != nullptr ) { size_t j{}; for ( auto&& child : this->node_collection_ ) { |