From b1e863bf2ae274da155446a8bb4aec5f975a86c5 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Thu, 25 Sep 2014 19:13:56 +0200 Subject: Increased tree constness and added constructor aliases * as with all Node classes the public member methods of the "Tree" class do not need to be non-const * both constructors are more easily expressed as aliases of a single constructor that takes both the term and a pointer to a constant map instance * the tree is now constructed during member initialization --- src/tree.cc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/tree.cc') 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::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_ ) { -- cgit v1.2.3