Calculator  Step 4
node.hpp
Go to the documentation of this file.
1 #ifndef NODE_HPP_
2 #define NODE_HPP_
3 
4 #include <iosfwd>
5 #include <memory>
6 #include <string>
7 #include <vector>
8 
10 class node_impl;
11 
13 class node;
14 
16 typedef std::vector<node> node_list;
17 
19 typedef std::vector<std::string> identifier_list;
20 
26 class node {
27 public:
29  node();
33  node(double number);
37  node(std::string identifier);
42  node(char op, node operand);
48  node(node left, char op, node right);
53  node(identifier_list parameters, node definition);
58  node(std::string name, node_list const& arguments);
59 
60  node(node const&) = default;
61  node(node&&) = default;
62  node& operator=(node const&) = default;
63  node& operator=(node&&) = default;
64  ~node();
65 
72  void print(std::ostream& stream, int indent = 0) const;
76  double evaluate() const;
81  std::string to_string() const;
86  identifier_list const& get_parameters() const;
87 
88 private:
90  static std::shared_ptr<node_impl> make_binary_operator(node, char, node);
91 
92  std::shared_ptr<node_impl> pimpl_;
93 };
94 
95 #endif
~node()
Definition: node.cpp:24
Definition: node.hpp:26
std::shared_ptr< node_impl > pimpl_
Definition: node.hpp:92
static std::shared_ptr< node_impl > make_binary_operator(node, char, node)
Factory function to make the binary operator nodes.
Definition: node.cpp:6
std::vector< std::string > identifier_list
A sequence of identifiers (e.g., parameter names).
Definition: node.hpp:19
node & operator=(node const &)=default
void print(std::ostream &stream, int indent=0) const
Definition: node.cpp:51
std::string to_string() const
Definition: node.cpp:63
double evaluate() const
Definition: node.cpp:57
node()
Definition: node.cpp:20
identifier_list const & get_parameters() const
Definition: node.cpp:69
std::vector< node > node_list
A sequence of nodes.
Definition: node.hpp:13