aboutsummaryrefslogtreecommitdiff
path: root/src/nodes.h
diff options
context:
space:
mode:
authorAdrian Kummerlaender2014-10-01 20:30:08 +0200
committerAdrian Kummerlaender2014-10-01 20:30:08 +0200
commit0840f434541b57fbd6d3c9d7b2a8b127cc680912 (patch)
tree330df31c2083a48c33be95a2bc7d40f8b5d25470 /src/nodes.h
parent6498a968cd34e49e355cc0765ca2dafb842bc12b (diff)
downloadSimpleParser-0840f434541b57fbd6d3c9d7b2a8b127cc680912.tar
SimpleParser-0840f434541b57fbd6d3c9d7b2a8b127cc680912.tar.gz
SimpleParser-0840f434541b57fbd6d3c9d7b2a8b127cc680912.tar.bz2
SimpleParser-0840f434541b57fbd6d3c9d7b2a8b127cc680912.tar.lz
SimpleParser-0840f434541b57fbd6d3c9d7b2a8b127cc680912.tar.xz
SimpleParser-0840f434541b57fbd6d3c9d7b2a8b127cc680912.tar.zst
SimpleParser-0840f434541b57fbd6d3c9d7b2a8b127cc680912.zip
Moved child pointers to OperatorNode class
* access was restricted by declaring them private and offering member methods such as "hasChildren" * only OperatorNode instances have children, there is no reason for wasting space by keeping empty pointers around in all other instances * this enabled the removal of all nullptr comparisons from tree construction * changed "Tree::addNode" factory method template to return a pointer to the type of the constructed node instance instead of a plain node pointer
Diffstat (limited to 'src/nodes.h')
-rw-r--r--src/nodes.h21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/nodes.h b/src/nodes.h
index 9559722..95bf772 100644
--- a/src/nodes.h
+++ b/src/nodes.h
@@ -13,11 +13,10 @@ class Node {
public:
virtual ~Node() {};
- virtual double solve() const = 0;
- virtual std::string print() const = 0;
-
- Node* leftChild;
- Node* rightChild;
+ virtual double solve() const = 0;
+ virtual std::string print() const = 0;
+ virtual bool hasChildren() const;
+ virtual bool isParentOf(Node*const) const;
};
@@ -25,15 +24,21 @@ class OperatorNode: public Node {
public:
explicit OperatorNode(TokenType);
- TokenType token() const;
+ virtual double solve() const;
+ virtual std::string print() const;
+ virtual bool hasChildren() const;
+ virtual bool isParentOf(Node*const) const;
- virtual double solve() const;
- virtual std::string print() const;
+ TokenType token() const;
+ void setChildren(Node*const, Node*const);
private:
const TokenType operator_;
+ Node* right_;
+ Node* left_;
+
};
class OperandNode: public Node {