node_impl Class Reference

#include <node_impl.hpp>

Inheritance diagram for node_impl:

node_binary node_function node_function_call node_identifier node_number node_unary node_void node_add node_divide node_multiply node_subtract node_negate

List of all members.

Public Member Functions

 node_impl ()
virtual ~node_impl ()
void print (std::ostream &stream, int indent) const
number evaluate () const
std::string to_string () const
identifier_list const & get_parameters () const
void add_ref ()
void del_ref ()
void save (std::ostream &stream) const

Static Public Member Functions

static node_implread_node (std::istream &stream)

Private Member Functions

 node_impl (node_impl const &n)
 not implemented
node_imploperator= (node_impl const &n)
 not implemented
virtual void print_node (std::ostream &stream, int indent) const =0
virtual number evaluate_node () const =0
virtual std::string evaluate_string () const
virtual
identifier_list
const & 
evaluate_parameters () const
virtual void save_node (std::ostream &stream) const =0

Private Attributes

std::size_t refcount_


Detailed Description

Base class for all parse tree nodes. The node classes all derive from node_impl. Each derived class overrides print_node(), for debugging and evalute_node() to evaluate the node. A few classes also override evaluate_string(), but most classes can inherit the node_impl::evaluate_string implementation, which prints the result of calling evaluate().

This class primarily manages the reference count.

Definition at line 19 of file node_impl.hpp.


Constructor & Destructor Documentation

node_impl::node_impl (  ) 

Definition at line 11 of file node_impl.cpp.

00012 : refcount_(1)
00013 {}

node_impl::~node_impl (  )  [virtual]

Definition at line 15 of file node_impl.cpp.

00016 {}

node_impl::node_impl ( node_impl const &  n  )  [private]

not implemented


Member Function Documentation

void node_impl::print ( std::ostream &  stream,
int  indent 
) const

Definition at line 18 of file node_impl.cpp.

References print_node().

Referenced by node::print().

00020 {
00021   print_node(stream, indent);
00022 }

number node_impl::evaluate (  )  const

Definition at line 24 of file node_impl.cpp.

References evaluate_node().

Referenced by node::evaluate(), and evaluate_string().

00026 {
00027   return evaluate_node();
00028 }

std::string node_impl::to_string (  )  const

Definition at line 30 of file node_impl.cpp.

References evaluate_string().

Referenced by node::to_string().

00032 {
00033   return evaluate_string();
00034 }

identifier_list const & node_impl::get_parameters (  )  const

Definition at line 41 of file node_impl.cpp.

References evaluate_parameters().

Referenced by node::get_parameters().

00043 {
00044   return evaluate_parameters();
00045 }

void node_impl::add_ref (  ) 

Definition at line 36 of file node_impl.cpp.

References refcount_.

Referenced by node::node(), and node::operator=().

00037 {
00038   ++refcount_;
00039 }

void node_impl::del_ref (  ) 

Definition at line 47 of file node_impl.cpp.

References refcount_.

Referenced by node::operator=(), and node::~node().

00048 {
00049   --refcount_;
00050   if (refcount_ == 0)
00051     delete this;
00052 }

void node_impl::save ( std::ostream &  stream  )  const

Definition at line 69 of file node_impl.cpp.

References save_node().

Referenced by node::save().

00071 {
00072   save_node(stream);
00073 }

node_impl * node_impl::read_node ( std::istream &  stream  )  [static]

Read the node type from a library file, then create the proper kind of node.

Definition at line 76 of file node_impl.cpp.

00077 {
00078   std::string type;
00079   if (not (stream >> type))
00080     return 0;
00081   if (type == "void")
00082     return new node_void(stream);
00083   if (type == "number")
00084     return new node_number(stream);
00085   if (type == "identifier")
00086     return new node_identifier(stream);
00087   if (type == "function")
00088     return new node_function(stream);
00089   if (type == "call")
00090     return new node_function_call(stream);
00091   if (type == "negate")
00092     return new node_negate(stream);
00093   if (type == "add")
00094     return new node_add(stream);
00095   if (type == "subtract")
00096     return new node_subtract(stream);
00097   if (type == "multiply")
00098     return new node_multiply(stream);
00099   if (type == "divide")
00100     return new node_divide(stream);
00101 
00102   throw calc_error("unknown node type: " + type);
00103 }

node_impl& node_impl::operator= ( node_impl const &  n  )  [private]

not implemented

virtual void node_impl::print_node ( std::ostream &  stream,
int  indent 
) const [private, pure virtual]

Implemented in node_void, node_number, node_identifier, node_function, node_function_call, node_unary, node_binary, node_negate, node_add, node_subtract, node_multiply, and node_divide.

Referenced by print().

virtual number node_impl::evaluate_node (  )  const [private, pure virtual]

Implemented in node_void, node_number, node_identifier, node_function, node_function_call, node_unary, node_binary, node_negate, node_add, node_subtract, node_multiply, and node_divide.

Referenced by evaluate().

std::string node_impl::evaluate_string (  )  const [private, virtual]

Reimplemented in node_void, and node_identifier.

Definition at line 54 of file node_impl.cpp.

References evaluate().

Referenced by to_string().

00056 {
00057   std::ostringstream stream;
00058   stream << evaluate();
00059   return stream.str();
00060 }

identifier_list const & node_impl::evaluate_parameters (  )  const [private, virtual]

Reimplemented in node_function.

Definition at line 62 of file node_impl.cpp.

Referenced by get_parameters().

00064 {
00065   static identifier_list const empty;
00066   return empty;
00067 }

virtual void node_impl::save_node ( std::ostream &  stream  )  const [private, pure virtual]

Implemented in node_void, node_number, node_identifier, node_function, node_function_call, node_unary, node_binary, node_negate, node_add, node_subtract, node_multiply, and node_divide.

Referenced by save().


Member Data Documentation

std::size_t node_impl::refcount_ [private]

Definition at line 49 of file node_impl.hpp.

Referenced by add_ref(), and del_ref().


The documentation for this class was generated from the following files:
Generated on Sun Nov 30 10:06:53 2008 for Calculator by  doxygen 1.5.3