diff options
author | Adrian Kummerlaender | 2014-09-25 19:05:01 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2014-09-25 19:05:01 +0200 |
commit | 2fcef9b48bb97da82d5828776e9be50be1fdafbc (patch) | |
tree | fb06fca2695fdf9dadb582b14ea846285edc63ee /src/nodes.h | |
parent | 0e3cfcde619fb60e6e43bf0ffe715df6d5c22218 (diff) | |
download | SimpleParser-2fcef9b48bb97da82d5828776e9be50be1fdafbc.tar SimpleParser-2fcef9b48bb97da82d5828776e9be50be1fdafbc.tar.gz SimpleParser-2fcef9b48bb97da82d5828776e9be50be1fdafbc.tar.bz2 SimpleParser-2fcef9b48bb97da82d5828776e9be50be1fdafbc.tar.lz SimpleParser-2fcef9b48bb97da82d5828776e9be50be1fdafbc.tar.xz SimpleParser-2fcef9b48bb97da82d5828776e9be50be1fdafbc.tar.zst SimpleParser-2fcef9b48bb97da82d5828776e9be50be1fdafbc.zip |
Increased Node constness and removed type member method
* marked "solve" and "print" implementations as const
* converted member variables into constants where possible
* "type" member method is not necessary and partially defeats the purpose of declaring virtual members
Diffstat (limited to 'src/nodes.h')
-rw-r--r-- | src/nodes.h | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/src/nodes.h b/src/nodes.h index 2581a2d..9559722 100644 --- a/src/nodes.h +++ b/src/nodes.h @@ -9,61 +9,56 @@ namespace SimpleParser { enum class TokenType; typedef std::map<std::string, double> ConstantMap; -enum class NodeType { - OPERAND, - OPERATOR, - CONSTANT, -}; - class Node { public: virtual ~Node() {}; - virtual double solve() = 0; - virtual NodeType type() = 0; - virtual std::string print() = 0; + virtual double solve() const = 0; + virtual std::string print() const = 0; Node* leftChild; Node* rightChild; + }; class OperatorNode: public Node { public: explicit OperatorNode(TokenType); - virtual double solve(); - virtual NodeType type(); - virtual std::string print(); + TokenType token() const; + + virtual double solve() const; + virtual std::string print() const; - TokenType token(); private: - TokenType operator_; + const TokenType operator_; + }; class OperandNode: public Node { public: explicit OperandNode(double); - virtual double solve(); - virtual NodeType type(); - virtual std::string print(); + virtual double solve() const; + virtual std::string print() const; private: - double value_; + const double value_; + }; class ConstantNode: public Node { public: - explicit ConstantNode(std::string, const ConstantMap*); + ConstantNode(const std::string&, const ConstantMap*); - virtual double solve(); - virtual NodeType type(); - virtual std::string print(); + virtual double solve() const; + virtual std::string print() const; private: - std::string identifier_; - const ConstantMap* constants_; + const std::string identifier_; + const ConstantMap* const constants_; + }; } |