Calculator  Step 5
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();
31  node(std::istream& stream);
35  node(double number);
39  node(std::string identifier);
44  node(char op, node operand);
50  node(node left, char op, node right);
55  node(identifier_list parameters, node definition);
60  node(std::string name, node_list arguments);
61 
62  node(node const&) = default;
63  node(node&&) = default;
64  node& operator=(node const&) = default;
65  node& operator=(node&&) = default;
66  ~node() = default;
67 
74  void print(std::ostream& stream, int indent = 0) const;
75 
79  double evaluate() const;
84  std::string to_string() const;
89  identifier_list const& get_parameters() const;
90 
94  void save(std::ostream& stream) const;
95 
96 private:
98  static std::shared_ptr<node_impl> make_binary_operator(node, char, node);
99 
100  std::shared_ptr<node_impl> pimpl_;
101 };
102 
103 #endif
Definition: node.hpp:26
std::shared_ptr< node_impl > pimpl_
Definition: node.hpp:100
static std::shared_ptr< node_impl > make_binary_operator(node, char, node)
Factory function to make the binary operator nodes.
Definition: node.cpp:8
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:54
std::string to_string() const
Definition: node.cpp:66
double evaluate() const
Definition: node.cpp:60
node()
Definition: node.cpp:22
identifier_list const & get_parameters() const
Definition: node.cpp:72
std::vector< node > node_list
A sequence of nodes.
Definition: node.hpp:13
void save(std::ostream &stream) const
Definition: node.cpp:78
~node()=default