- Main Page
- Classes
- Files

# node_impl.hpp

Go to the documentation of this file.

    00001 #ifndef NODE_IMPL_HPP_
    00002 #define NODE_IMPL_HPP_
    00003
    00004 #include <cstdlib>
    00005 #include <string>
    00006
    00007 #include "node.hpp"
    00008
    00019 class node_impl {
    00020 public:
    00021   node_impl();
    00022   virtual ~node_impl();
    00023
    00024   void print(std::ostream& stream, int indent) const;
    00025
    00026   double evaluate() const;
    00027
    00028   std::string to_string() const;
    00029
    00030   void add_ref();
    00031   void del_ref();
    00032
    00033 private:
    00034   node_impl(node_impl const& n);
    00035   node_impl& operator=(node_impl const& n);
    00036
    00037   virtual void print_node(std::ostream& stream, int indent) const = 0;
    00038   virtual double evaluate_node() const = 0;
    00039   virtual std::string evaluate_string() const;
    00040
    00041   std::size_t refcount_;
    00042 };
    00043
    00047 class node_void : public node_impl {
    00048 public:
    00049   node_void();
    00050 private:
    00051   virtual void print_node(std::ostream& stream, int indent) const;
    00052   virtual double evaluate_node() const;
    00053   virtual std::string evaluate_string() const;
    00054 };
    00055
    00059 class node_number : public node_impl {
    00060 public:
    00061   node_number(double value);
    00062   double value() const;
    00063 private:
    00064   virtual void print_node(std::ostream& stream, int indent) const;
    00065   virtual double evaluate_node() const;
    00066
    00067   double value_;
    00068 };
    00069
    00073 class node_identifier : public node_impl {
    00074 public:
    00075   node_identifier(std::string const& identifier);
    00076   std::string identifier() const;
    00077 private:
    00078   virtual void print_node(std::ostream& stream, int indent) const;
    00079   virtual double evaluate_node() const;
    00080   virtual std::string evaluate_string() const;
    00081
    00082   std::string identifier_;
    00083 };
    00084
    00088 class node_assign : public node_impl {
    00089 public:
    00090   node_assign(node identifier, node value);
    00091   node identifier() const;
    00092   node value() const;
    00093 private:
    00094   std::string get_identifier() const;
    00095   double evaluate_value() const;
    00096
    00097   virtual void print_node(std::ostream& stream, int indent) const;
    00098   virtual double evaluate_node() const;
    00099
    00100   node identifier_;
    00101   node value_;
    00102 };
    00103
    00105 class node_unary : public node_impl {
    00106 public:
    00107   node_unary(node operand);
    00108   node operand()  const;
    00109 protected:
    00110   double evaluate_operand() const;
    00111 private:
    00112   virtual void print_node(std::ostream& stream, int indent) const = 0;
    00113   virtual double evaluate_node() const = 0;
    00114
    00115   node operand_;
    00116 };
    00117
    00119 class node_binary : public node_impl {
    00120 public:
    00121   node_binary(node left, node right);
    00122   node left()  const;
    00123   node right() const;
    00124 protected:
    00125   double evaluate_left() const;
    00126   double evaluate_right() const;
    00127 private:
    00128   virtual void print_node(std::ostream& stream, int indent) const = 0;
    00129   virtual double evaluate_node() const = 0;
    00130
    00131   node left_;
    00132   node right_;
    00133 };
    00134
    00136 class node_negate : public node_unary {
    00137 public:
    00138   node_negate(node operand);
    00139 private:
    00140   virtual void print_node(std::ostream& stream, int indent) const;
    00141   virtual double evaluate_node() const;
    00142 };
    00143
    00145 class node_add : public node_binary {
    00146 public:
    00147   node_add(node left, node right);
    00148 private:
    00149   virtual void print_node(std::ostream& stream, int indent) const;
    00150   virtual double evaluate_node() const;
    00151 };
    00152
    00154 class node_subtract : public node_binary {
    00155 public:
    00156   node_subtract(node left, node right);
    00157 private:
    00158   virtual void print_node(std::ostream& stream, int indent) const;
    00159   virtual double evaluate_node() const;
    00160 };
    00161
    00163 class node_multiply : public node_binary {
    00164 public:
    00165   node_multiply(node left, node right);
    00166 private:
    00167   virtual void print_node(std::ostream& stream, int indent) const;
    00168   virtual double evaluate_node() const;
    00169 };
    00170
    00172 class node_divide : public node_binary {
    00173 public:
    00174   node_divide(node left, node right);
    00175 private:
    00176   virtual void print_node(std::ostream& stream, int indent) const;
    00177   virtual double evaluate_node() const;
    00178 };
    00179
    00180 #endif