node_function_call Class Reference

#include <node_impl.hpp>

Inheritance diagram for node_function_call:

node_impl

List of all members.

Public Member Functions

 node_function_call (std::string const &name, node_list const &arguments)
 node_function_call (std::istream &stream)
std::string name () const
node_list const & arguments () const

Private Member Functions

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

Private Attributes

std::string name_
node_list arguments_


Detailed Description

Function call.

Definition at line 119 of file node_impl.hpp.


Constructor & Destructor Documentation

node_function_call::node_function_call ( std::string const &  name,
node_list const &  arguments 
)

Definition at line 287 of file node_impl.cpp.

00288 : node_impl(), name_(name), arguments_(arguments)
00289 {}

node_function_call::node_function_call ( std::istream &  stream  ) 

Definition at line 291 of file node_impl.cpp.

References arguments_, name(), and name_.

00292 : node_impl()
00293 {
00294   std::string name;
00295   if (not (stream >> name_))
00296     throw calc_error("malformed library file, cannot read function call name");
00297   std::size_t size;
00298   if (not (stream >> size))
00299     throw calc_error("malformed library file, cannot read function call");
00300   arguments_.reserve(size);
00301   while (size-- != 0) {
00302     arguments_.push_back(node(stream));
00303   }
00304 }


Member Function Documentation

std::string node_function_call::name (  )  const

Definition at line 306 of file node_impl.cpp.

References name_.

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

00308 {
00309   return name_;
00310 }

node_list const & node_function_call::arguments (  )  const

Definition at line 312 of file node_impl.cpp.

References arguments_.

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

00314 {
00315   return arguments_;
00316 }

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

Implements node_impl.

Definition at line 318 of file node_impl.cpp.

References arguments(), and name().

00320 {
00321   stream << std::setw(indent) << "" << name() << "(\n";
00322   for (node_list::const_iterator first(arguments().begin()), arg(first); arg != arguments().end(); ++arg) {
00323     stream << std::setw(indent+1) << "" << "arg " << std::distance(first, arg) << ": ";
00324     arg->print(stream, indent + 2);
00325   }
00326   stream << std::setw(indent) << "" << ")\n";
00327 }

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

Implements node_impl.

Definition at line 329 of file node_impl.cpp.

References arguments(), node::evaluate(), get_function(), node::get_parameters(), and name().

00331 {
00332   // Create a local symbol table, assigning all the node values to the parameters.
00333   node function = get_function(name());
00334   identifier_list const& parameters( function.get_parameters() );
00335   if (parameters.size() != arguments().size())
00336     throw function_error(name(), parameters.size(), arguments().size());
00337   else
00338   {
00339     // Create a local symbol table by assigning the arguments to the function parameters.
00340     symbol_table locals;
00341     identifier_list::const_iterator parm(parameters.begin());
00342     for (node_list::const_iterator arg(arguments().begin()); arg != arguments().end(); ++arg, ++parm) {
00343       locals.insert(std::make_pair(*parm, *arg));
00344     }
00345     set_symbol_table syms(locals);
00346     return function.evaluate();
00347   }
00348 }

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

Implements node_impl.

Definition at line 350 of file node_impl.cpp.

References arguments(), and name().

00352 {
00353   stream << "call " << name() << ' ' << arguments().size() << ' ';
00354   for (node_list::const_iterator arg(arguments().begin()); arg != arguments().end(); ++arg)
00355     arg->save(stream);
00356 }


Member Data Documentation

std::string node_function_call::name_ [private]

Definition at line 130 of file node_impl.hpp.

Referenced by name(), and node_function_call().

node_list node_function_call::arguments_ [private]

Definition at line 131 of file node_impl.hpp.

Referenced by arguments(), and node_function_call().


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