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   number 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   void save(std::ostream& stream) const;
00036 
00038   static node_impl* read_node(std::istream& stream);
00039 private:
00040   node_impl(node_impl const& n); 
00041   node_impl& operator=(node_impl const& n); 
00042 
00043   virtual void print_node(std::ostream& stream, int indent) const = 0;
00044   virtual number evaluate_node() const = 0;
00045   virtual std::string evaluate_string() const;
00046   virtual identifier_list const& evaluate_parameters() const;
00047   virtual void save_node(std::ostream& stream) const = 0;
00048 
00049   std::size_t refcount_;
00050 };
00051 
00055 class node_void : public node_impl {
00056 public:
00057   node_void();
00058   node_void(std::istream& stream);
00059 private:
00060   virtual void print_node(std::ostream& stream, int indent) const;
00061   virtual number evaluate_node() const;
00062   virtual std::string evaluate_string() const;
00063   virtual void save_node(std::ostream& stream) const;
00064 };
00065 
00069 class node_number : public node_impl {
00070 public:
00071   node_number(number value);
00072   node_number(std::istream& stream);
00073   number value() const;
00074 private:
00075   virtual void print_node(std::ostream& stream, int indent) const;
00076   virtual number evaluate_node() const;
00077   virtual void save_node(std::ostream& stream) const;
00078 
00079   number value_;
00080 };
00081 
00085 class node_identifier : public node_impl {
00086 public:
00087   node_identifier(std::string const& name);
00088   node_identifier(std::istream& stream);
00089   std::string const& name() const;
00090 private:
00091   virtual void print_node(std::ostream& stream, int indent) const;
00092   virtual number evaluate_node() const;
00093   virtual std::string evaluate_string() const;
00094   virtual void save_node(std::ostream& stream) const;
00095 
00096   std::string name_;
00097 };
00098 
00102 class node_function : public node_impl {
00103 public:
00104   node_function(identifier_list const& parameters, node definition);
00105   node_function(std::istream& stream);
00106   identifier_list const& parameters() const;
00107   node definition() const;
00108 private:
00109   virtual void print_node(std::ostream& stream, int indent) const;
00110   virtual number evaluate_node() const;
00111   virtual identifier_list const& evaluate_parameters() const;
00112   virtual void save_node(std::ostream& stream) const;
00113 
00114   identifier_list parameters_;
00115   node definition_;
00116 };
00117 
00119 class node_function_call : public node_impl {
00120 public:
00121   node_function_call(std::string const& name, node_list const& arguments);
00122   node_function_call(std::istream& stream);
00123   std::string name() const;
00124   node_list const& arguments() const;
00125 private:
00126   virtual void print_node(std::ostream& stream, int indent) const;
00127   virtual number evaluate_node() const;
00128   virtual void save_node(std::ostream& stream) const;
00129 
00130   std::string name_;
00131   node_list arguments_;
00132 };
00133 
00135 class node_unary : public node_impl {
00136 public:
00137   node_unary(node operand);
00138   node operand()  const;
00139 protected:
00140   node_unary(std::istream& stream);
00141   number evaluate_operand() const;
00142 private:
00143   virtual void print_node(std::ostream& stream, int indent) const = 0;
00144   virtual number evaluate_node() const = 0;
00145   virtual void save_node(std::ostream& stream) const = 0;
00146 
00147   node operand_;
00148 };
00149 
00151 class node_binary : public node_impl {
00152 public:
00153   node_binary(node left, node right);
00154   node left()  const;
00155   node right() const;
00156 protected:
00157   node_binary(std::istream& stream);
00158   number evaluate_left() const;
00159   number evaluate_right() const;
00160 private:
00161   virtual void print_node(std::ostream& stream, int indent) const = 0;
00162   virtual number evaluate_node() const = 0;
00163   virtual void save_node(std::ostream& stream) const = 0;
00164 
00165   node left_;
00166   node right_;
00167 };
00168 
00170 class node_negate : public node_unary {
00171 public:
00172   node_negate(node operand);
00173   node_negate(std::istream& stream);
00174 private:
00175   virtual void print_node(std::ostream& stream, int indent) const;
00176   virtual number evaluate_node() const;
00177   virtual void save_node(std::ostream& stream) const;
00178 };
00179 
00181 class node_add : public node_binary {
00182 public:
00183   node_add(node left, node right);
00184   node_add(std::istream& stream);
00185 private:
00186   virtual void print_node(std::ostream& stream, int indent) const;
00187   virtual number evaluate_node() const;
00188   virtual void save_node(std::ostream& stream) const;
00189 };
00190 
00192 class node_subtract : public node_binary {
00193 public:
00194   node_subtract(node left, node right);
00195   node_subtract(std::istream& stream);
00196 private:
00197   virtual void print_node(std::ostream& stream, int indent) const;
00198   virtual number evaluate_node() const;
00199   virtual void save_node(std::ostream& stream) const;
00200 };
00201 
00203 class node_multiply : public node_binary {
00204 public:
00205   node_multiply(node left, node right);
00206   node_multiply(std::istream& stream);
00207 private:
00208   virtual void print_node(std::ostream& stream, int indent) const;
00209   virtual number evaluate_node() const;
00210   virtual void save_node(std::ostream& stream) const;
00211 };
00212 
00214 class node_divide : public node_binary {
00215 public:
00216   node_divide(node left, node right);
00217   node_divide(std::istream& stream);
00218 private:
00219   virtual void print_node(std::ostream& stream, int indent) const;
00220   virtual number evaluate_node() const;
00221   virtual void save_node(std::ostream& stream) const;
00222 };
00223 
00224 #endif

Generated on Sun Nov 30 10:06:52 2008 for Calculator by  doxygen 1.5.3