- 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   identifier_list const& get_parameters() const;
    00031
    00032   void add_ref();
    00033   void del_ref();
    00034
    00035 private:
    00036   node_impl(node_impl const& n);
    00037   node_impl& operator=(node_impl const& n);
    00038
    00039   virtual void print_node(std::ostream& stream, int indent) const = 0;
    00040   virtual double evaluate_node() const = 0;
    00041   virtual std::string evaluate_string() const;
    00042   virtual identifier_list const& evaluate_parameters() const;
    00043
    00044   std::size_t refcount_;
    00045 };
    00046
    00050 class node_void : public node_impl {
    00051 public:
    00052   node_void();
    00053 private:
    00054   virtual void print_node(std::ostream& stream, int indent) const;
    00055   virtual double evaluate_node() const;
    00056   virtual std::string evaluate_string() const;
    00057 };
    00058
    00062 class node_number : public node_impl {
    00063 public:
    00064   node_number(double value);
    00065   double value() const;
    00066 private:
    00067   virtual void print_node(std::ostream& stream, int indent) const;
    00068   virtual double evaluate_node() const;
    00069
    00070   double value_;
    00071 };
    00072
    00076 class node_identifier : public node_impl {
    00077 public:
    00078   node_identifier(std::string const& name);
    00079   std::string const& name() const;
    00080 private:
    00081   virtual void print_node(std::ostream& stream, int indent) const;
    00082   virtual double evaluate_node() const;
    00083   virtual std::string evaluate_string() const;
    00084
    00085   std::string name_;
    00086 };
    00087
    00091 class node_function : public node_impl {
    00092 public:
    00093   node_function(identifier_list const& parameters, node definition);
    00094   identifier_list const& parameters() const;
    00095   node definition() const;
    00096 private:
    00097   virtual void print_node(std::ostream& stream, int indent) const;
    00098   virtual double evaluate_node() const;
    00099   virtual identifier_list const& evaluate_parameters() const;
    00100
    00101   identifier_list parameters_;
    00102   node definition_;
    00103 };
    00104
    00106 class node_function_call : public node_impl {
    00107 public:
    00108   node_function_call(std::string const& name, node_list const& arguments);
    00109   std::string name() const;
    00110   node_list const& arguments() const;
    00111 private:
    00112   virtual void print_node(std::ostream& stream, int indent) const;
    00113   virtual double evaluate_node() const;
    00114
    00115   std::string name_;
    00116   node_list arguments_;
    00117 };
    00118
    00120 class node_unary : public node_impl {
    00121 public:
    00122   node_unary(node operand);
    00123   node operand()  const;
    00124 protected:
    00125   double evaluate_operand() const;
    00126 private:
    00127   virtual void print_node(std::ostream& stream, int indent) const = 0;
    00128   virtual double evaluate_node() const = 0;
    00129
    00130   node operand_;
    00131 };
    00132
    00134 class node_binary : public node_impl {
    00135 public:
    00136   node_binary(node left, node right);
    00137   node left()  const;
    00138   node right() const;
    00139 protected:
    00140   double evaluate_left() const;
    00141   double evaluate_right() const;
    00142 private:
    00143   virtual void print_node(std::ostream& stream, int indent) const = 0;
    00144   virtual double evaluate_node() const = 0;
    00145
    00146   node left_;
    00147   node right_;
    00148 };
    00149
    00151 class node_negate : public node_unary {
    00152 public:
    00153   node_negate(node operand);
    00154 private:
    00155   virtual void print_node(std::ostream& stream, int indent) const;
    00156   virtual double evaluate_node() const;
    00157 };
    00158
    00160 class node_add : public node_binary {
    00161 public:
    00162   node_add(node left, node right);
    00163 private:
    00164   virtual void print_node(std::ostream& stream, int indent) const;
    00165   virtual double evaluate_node() const;
    00166 };
    00167
    00169 class node_subtract : public node_binary {
    00170 public:
    00171   node_subtract(node left, node right);
    00172 private:
    00173   virtual void print_node(std::ostream& stream, int indent) const;
    00174   virtual double evaluate_node() const;
    00175 };
    00176
    00178 class node_multiply : public node_binary {
    00179 public:
    00180   node_multiply(node left, node right);
    00181 private:
    00182   virtual void print_node(std::ostream& stream, int indent) const;
    00183   virtual double evaluate_node() const;
    00184 };
    00185
    00187 class node_divide : public node_binary {
    00188 public:
    00189   node_divide(node left, node right);
    00190 private:
    00191   virtual void print_node(std::ostream& stream, int indent) const;
    00192   virtual double evaluate_node() const;
    00193 };
    00194
    00195 #endif