#include <node_impl.hpp>
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 double | evaluate_node () const |
virtual void | save_node (std::ostream &stream) const |
Private Attributes | |
std::string | name_ |
node_list | arguments_ |
Definition at line 119 of file node_impl.hpp.
node_function_call::node_function_call | ( | std::string const & | name, | |
node_list const & | arguments | |||
) |
Definition at line 288 of file node_impl.cpp.
00289 : node_impl(), name_(name), arguments_(arguments) 00290 {}
node_function_call::node_function_call | ( | std::istream & | stream | ) |
Definition at line 292 of file node_impl.cpp.
References arguments_, name(), and name_.
00293 : node_impl() 00294 { 00295 std::string name; 00296 if (not (stream >> name_)) 00297 throw calc_error("malformed library file, cannot read function call name"); 00298 std::size_t size; 00299 if (not (stream >> size)) 00300 throw calc_error("malformed library file, cannot read function call"); 00301 arguments_.reserve(size); 00302 while (size-- != 0) { 00303 arguments_.push_back(node(stream)); 00304 } 00305 }
std::string node_function_call::name | ( | ) | const |
Definition at line 307 of file node_impl.cpp.
References name_.
Referenced by evaluate_node(), node_function_call(), print_node(), and save_node().
00309 { 00310 return name_; 00311 }
node_list const & node_function_call::arguments | ( | ) | const |
Definition at line 313 of file node_impl.cpp.
References arguments_.
Referenced by evaluate_node(), print_node(), and save_node().
00315 { 00316 return arguments_; 00317 }
void node_function_call::print_node | ( | std::ostream & | stream, | |
int | indent | |||
) | const [private, virtual] |
Implements node_impl.
Definition at line 319 of file node_impl.cpp.
References arguments(), and name().
00321 { 00322 stream << std::setw(indent) << "" << name() << "(\n"; 00323 for (node_list::const_iterator first(arguments().begin()), arg(first); arg != arguments().end(); ++arg) { 00324 stream << std::setw(indent+1) << "" << "arg " << std::distance(first, arg) << ": "; 00325 arg->print(stream, indent + 2); 00326 } 00327 stream << std::setw(indent) << "" << ")\n"; 00328 }
double node_function_call::evaluate_node | ( | ) | const [private, virtual] |
Implements node_impl.
Definition at line 330 of file node_impl.cpp.
References arguments(), node::evaluate(), get_function(), node::get_parameters(), and name().
00332 { 00333 // Create a local symbol table, assigning all the node values to the parameters. 00334 node function = get_function(name()); 00335 identifier_list const& parameters( function.get_parameters() ); 00336 if (parameters.size() != arguments().size()) 00337 throw function_error(name(), parameters.size(), arguments().size()); 00338 else 00339 { 00340 // Create a local symbol table by assigning the arguments to the function parameters. 00341 symbol_table locals; 00342 identifier_list::const_iterator parm(parameters.begin()); 00343 for (node_list::const_iterator arg(arguments().begin()); arg != arguments().end(); ++arg, ++parm) { 00344 locals.insert(std::make_pair(*parm, *arg)); 00345 } 00346 set_symbol_table syms(locals); 00347 return function.evaluate(); 00348 } 00349 }
void node_function_call::save_node | ( | std::ostream & | stream | ) | const [private, virtual] |
Implements node_impl.
Definition at line 351 of file node_impl.cpp.
References arguments(), and name().
00353 { 00354 stream << "call " << name() << ' ' << arguments().size() << ' '; 00355 for (node_list::const_iterator arg(arguments().begin()); arg != arguments().end(); ++arg) 00356 arg->save(stream); 00357 }
std::string node_function_call::name_ [private] |
node_list node_function_call::arguments_ [private] |