node_function Class Reference

#include <node_impl.hpp>

Inheritance diagram for node_function:

node_impl

List of all members.

Public Member Functions

 node_function (identifier_list const &parameters, node definition)
 node_function (std::istream &stream)
identifier_list const & parameters () const
node definition () const

Private Member Functions

virtual void print_node (std::ostream &stream, int indent) const
virtual number evaluate_node () const
virtual
identifier_list
const & 
evaluate_parameters () const
virtual void save_node (std::ostream &stream) const

Private Attributes

identifier_list parameters_
node definition_


Detailed Description

Function definition. A function has parameters and a definition.

Definition at line 102 of file node_impl.hpp.


Constructor & Destructor Documentation

node_function::node_function ( identifier_list const &  parameters,
node  definition 
)

Definition at line 214 of file node_impl.cpp.

00215 : node_impl(), parameters_(parameters), definition_(definition)
00216 {}

node_function::node_function ( std::istream &  stream  ) 

Definition at line 218 of file node_impl.cpp.

References definition_, and parameters_.

00219 : node_impl()
00220 {
00221   std::size_t size;
00222   if (not (stream >> size))
00223     throw calc_error("malformed library file, cannot read function");
00224   parameters_.reserve(size);
00225   while (size-- != 0) {
00226     std::string parameter;
00227     if (not (stream >> parameter))
00228       throw calc_error("malformed library file, cannot read function parameter");
00229     parameters_.push_back(parameter);
00230   }
00231   definition_ = node(stream);
00232 }


Member Function Documentation

identifier_list const & node_function::parameters (  )  const

Definition at line 234 of file node_impl.cpp.

References parameters_.

Referenced by evaluate_parameters(), print_node(), and save_node().

00236 {
00237   return parameters_;
00238 }

node node_function::definition (  )  const

Definition at line 240 of file node_impl.cpp.

References definition_.

Referenced by evaluate_node(), print_node(), and save_node().

00242 {
00243   return definition_;
00244 }

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

Implements node_impl.

Definition at line 257 of file node_impl.cpp.

References definition(), parameters(), node::print(), and print_identifier_list().

00259 {
00260   stream << std::setw(indent) << "" << "fun\n";
00261   print_identifier_list(stream, parameters());
00262   stream << '=';
00263   definition().print(stream, indent + 2);
00264 }

number node_function::evaluate_node (  )  const [private, virtual]

Implements node_impl.

Definition at line 266 of file node_impl.cpp.

References definition(), and node::evaluate().

00268 {
00269   return definition().evaluate();
00270 }

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

Reimplemented from node_impl.

Definition at line 272 of file node_impl.cpp.

References parameters().

00274 {
00275   return parameters();
00276 }

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

Implements node_impl.

Definition at line 278 of file node_impl.cpp.

References definition(), parameters(), and node::save().

00280 {
00281   stream << "function " << parameters().size() << ' ';
00282   std::copy(parameters().begin(), parameters().end(), std::ostream_iterator<std::string>(stream, " "));
00283   definition().save(stream);
00284 }


Member Data Documentation

identifier_list node_function::parameters_ [private]

Definition at line 114 of file node_impl.hpp.

Referenced by node_function(), and parameters().

node node_function::definition_ [private]

Definition at line 115 of file node_impl.hpp.

Referenced by definition(), and node_function().


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