Calculator Step 3

- Main Page
- Classes
- Files

- File List
- File Members

node_impl.hpp
Go to the documentation of this file.
1 #ifndef NODE_IMPL_HPP_
2 #define NODE_IMPL_HPP_
3
4 #include <cstdlib>
5 #include <string>
6
7 #include "node.hpp"
8
17 class node_impl {
18 public:
19 node_impl();
20 virtual ~node_impl();
21
22 void print(std::ostream& stream, int indent) const;
23
24 double evaluate() const;
25
26 std::string to_string() const;
27
28 private:
29 node_impl(node_impl const& n) = delete;
30 node_impl& operator=(node_impl const& n) = delete;
31
32 virtual void print_node(std::ostream& stream, int indent) const = 0;
33 virtual double evaluate_node() const = 0;
34 virtual std::string evaluate_string() const;
35 };
36
40 class node_void : public node_impl {
41 public:
42 node_void();
43 private:
44 void print_node(std::ostream& stream, int indent) const override;
45 double evaluate_node() const override;
46 std::string evaluate_string() const override;
47 };
48
52 class node_number : public node_impl {
53 public:
54 node_number(double value);
55 double value() const;
56 private:
57 void print_node(std::ostream& stream, int indent) const override;
58 double evaluate_node() const override;
59
60 double value_;
61 };
62
66 class node_identifier : public node_impl {
67 public:
68 node_identifier(std::string identifier);
69 std::string const& identifier() const;
70 private:
71 virtual void print_node(std::ostream& stream, int indent) const override;
72 virtual double evaluate_node() const override;
73 virtual std::string evaluate_string() const override;
74
75 std::string identifier_;
76 };
77
81 class node_assign : public node_impl {
82 public:
83 node_assign(node identifier, node value);
84 node identifier() const;
85 node value() const;
86 private:
87 std::string get_identifier() const;
88 double evaluate_value() const;
89
90 virtual void print_node(std::ostream& stream, int indent) const override;
91 virtual double evaluate_node() const override;
92
93 node identifier_;
94 node value_;
95 };
96
98 class node_unary : public node_impl {
99 public:
100 node_unary(node operand);
101 node operand() const;
102 protected:
103 double evaluate_operand() const;
104 private:
105 virtual void print_node(std::ostream& stream, int indent) const override = 0;
106 virtual double evaluate_node() const override = 0;
107
108 node operand_;
109 };
110
112 class node_binary : public node_impl {
113 public:
114 node_binary(node left, node right);
115 node left() const;
116 node right() const;
117 protected:
118 double evaluate_left() const;
119 double evaluate_right() const;
120 private:
121 virtual void print_node(std::ostream& stream, int indent) const override = 0;
122 virtual double evaluate_node() const override = 0;
123
124 node left_;
125 node right_;
126 };
127
129 class node_negate : public node_unary {
130 public:
131 node_negate(node operand);
132 private:
133 virtual void print_node(std::ostream& stream, int indent) const override;
134 virtual double evaluate_node() const override;
135 };
136
138 class node_add : public node_binary {
139 public:
140 node_add(node left, node right);
141 private:
142 virtual void print_node(std::ostream& stream, int indent) const override;
143 virtual double evaluate_node() const override;
144 };
145
147 class node_subtract : public node_binary {
148 public:
149 node_subtract(node left, node right);
150 private:
151 virtual void print_node(std::ostream& stream, int indent) const override;
152 virtual double evaluate_node() const override;
153 };
154
156 class node_multiply : public node_binary {
157 public:
158 node_multiply(node left, node right);
159 private:
160 virtual void print_node(std::ostream& stream, int indent) const override;
161 virtual double evaluate_node() const override;
162 };
163
165 class node_divide : public node_binary {
166 public:
167 node_divide(node left, node right);
168 private:
169 virtual void print_node(std::ostream& stream, int indent) const override;
170 virtual double evaluate_node() const override;
171 };
172
173 #endif
node_identifier::evaluate_node
virtual double evaluate_node() const override
Definition: node_impl.cpp:104
node_number::node_number
node_number(double value)
Definition: node_impl.cpp:65
node_assign::identifier_
node identifier_
Definition: node_impl.hpp:93
node_binary::left_
node left_
Definition: node_impl.hpp:124
node_binary::evaluate_right
double evaluate_right() const
Definition: node_impl.cpp:200
node_subtract
Definition: node_impl.hpp:147
node_void
Definition: node_impl.hpp:40
node_unary::node_unary
node_unary(node operand)
Definition: node_impl.cpp:162
node_divide
Definition: node_impl.hpp:165
node_void::evaluate_string
std::string evaluate_string() const override
Definition: node_impl.cpp:58
node_impl::evaluate_string
virtual std::string evaluate_string() const
Definition: node_impl.cpp:33
node_negate
Definition: node_impl.hpp:129
node_identifier::print_node
virtual void print_node(std::ostream &stream, int indent) const override
Definition: node_impl.cpp:98
node_impl::evaluate_node
virtual double evaluate_node() const =0
node_assign::value
node value() const
Definition: node_impl.cpp:127
node_divide::print_node
virtual void print_node(std::ostream &stream, int indent) const override
Definition: node_impl.cpp:286
node_impl::node_impl
node_impl()
Definition: node_impl.cpp:9
node_subtract::print_node
virtual void print_node(std::ostream &stream, int indent) const override
Definition: node_impl.cpp:248
node_binary::evaluate_left
double evaluate_left() const
Definition: node_impl.cpp:194
node_identifier::node_identifier
node_identifier(std::string identifier)
Definition: node_impl.cpp:88
node_assign::print_node
virtual void print_node(std::ostream &stream, int indent) const override
Definition: node_impl.cpp:145
node_void::node_void
node_void()
Definition: node_impl.cpp:42
node_number::value_
double value_
Definition: node_impl.hpp:60
node_binary::node_binary
node_binary(node left, node right)
Definition: node_impl.cpp:178
node_impl
Definition: node_impl.hpp:17
node_unary::evaluate_node
virtual double evaluate_node() const override=0
node
Definition: node.hpp:16
node_subtract::evaluate_node
virtual double evaluate_node() const override
Definition: node_impl.cpp:256
node_multiply::evaluate_node
virtual double evaluate_node() const override
Definition: node_impl.cpp:275
node_void::print_node
void print_node(std::ostream &stream, int indent) const override
Definition: node_impl.cpp:46
node_identifier::evaluate_string
virtual std::string evaluate_string() const override
Definition: node_impl.cpp:110
node_identifier
Definition: node_impl.hpp:66
node_assign::value_
node value_
Definition: node_impl.hpp:94
node_number::evaluate_node
double evaluate_node() const override
Definition: node_impl.cpp:81
node_impl::print
void print(std::ostream &stream, int indent) const
Definition: node_impl.cpp:15
node_unary::operand_
node operand_
Definition: node_impl.hpp:108
node_assign::node_assign
node_assign(node identifier, node value)
Definition: node_impl.cpp:117
node_binary::evaluate_node
virtual double evaluate_node() const override=0
node_number::print_node
void print_node(std::ostream &stream, int indent) const override
Definition: node_impl.cpp:75
node_binary
Definition: node_impl.hpp:112
node_impl::~node_impl
virtual ~node_impl()
Definition: node_impl.cpp:12
node_unary
Definition: node_impl.hpp:98
node_binary::right
node right() const
Definition: node_impl.cpp:188
node_unary::evaluate_operand
double evaluate_operand() const
Definition: node_impl.cpp:172
node_assign::get_identifier
std::string get_identifier() const
Definition: node_impl.cpp:133
node_identifier::identifier_
std::string identifier_
Definition: node_impl.hpp:75
node_multiply::node_multiply
node_multiply(node left, node right)
Definition: node_impl.cpp:263
node_multiply
Definition: node_impl.hpp:156
node_impl::operator=
node_impl & operator=(node_impl const &n)=delete
node_assign::evaluate_value
double evaluate_value() const
Definition: node_impl.cpp:139
node_negate::print_node
virtual void print_node(std::ostream &stream, int indent) const override
Definition: node_impl.cpp:211
node_number
Definition: node_impl.hpp:52
node_impl::print_node
virtual void print_node(std::ostream &stream, int indent) const =0
node_assign::evaluate_node
virtual double evaluate_node() const override
Definition: node_impl.cpp:152
node_binary::right_
node right_
Definition: node_impl.hpp:125
node_subtract::node_subtract
node_subtract(node left, node right)
Definition: node_impl.cpp:244
node_impl::evaluate
double evaluate() const
Definition: node_impl.cpp:21
node_assign::identifier
node identifier() const
Definition: node_impl.cpp:121
node_void::evaluate_node
double evaluate_node() const override
Definition: node_impl.cpp:52
node_add::print_node
virtual void print_node(std::ostream &stream, int indent) const override
Definition: node_impl.cpp:229
node_add
Definition: node_impl.hpp:138
node.hpp
node_divide::evaluate_node
virtual double evaluate_node() const override
Definition: node_impl.cpp:294
node_number::value
double value() const
Definition: node_impl.cpp:69
node_impl::to_string
std::string to_string() const
Definition: node_impl.cpp:27
node_unary::operand
node operand() const
Definition: node_impl.cpp:166
node_negate::node_negate
node_negate(node operand)
Definition: node_impl.cpp:207
node_multiply::print_node
virtual void print_node(std::ostream &stream, int indent) const override
Definition: node_impl.cpp:267
node_add::evaluate_node
virtual double evaluate_node() const override
Definition: node_impl.cpp:237
node_divide::node_divide
node_divide(node left, node right)
Definition: node_impl.cpp:282
node_binary::print_node
virtual void print_node(std::ostream &stream, int indent) const override=0
node_add::node_add
node_add(node left, node right)
Definition: node_impl.cpp:225
node_binary::left
node left() const
Definition: node_impl.cpp:182
node_assign
Definition: node_impl.hpp:81
node_unary::print_node
virtual void print_node(std::ostream &stream, int indent) const override=0
node_negate::evaluate_node
virtual double evaluate_node() const override
Definition: node_impl.cpp:218
node_identifier::identifier
std::string const & identifier() const
Definition: node_impl.cpp:92