Calculator Step 4

- Main Page
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Private Member Functions | Private Attributes | List of all members
node_function_call Class Reference

`#include <node_impl.hpp>`

Inheritance diagram for node_function_call:

## Public Member Functions
| node_function_call (std::string name, node_list arguments)
std::string | name () const
node_list const & | arguments () const
Public Member Functions inherited from node_impl
| node_impl ()
| node_impl (node_impl &&)=default
node_impl & | operator= (node_impl &&)=default
virtual | ~node_impl ()
void | print (std::ostream &stream, int indent) const
double | evaluate () const
std::string | to_string () const
identifier_list const & | get_parameters () const

## Private Member Functions
virtual void | print_node (std::ostream &stream, int indent) const override
virtual double | evaluate_node () const override

## Private Attributes
std::string | name_
node_list | arguments_

## Detailed Description

Function call.

Definition at line 101 of file node_impl.hpp.

## Constructor & Destructor Documentation

node_function_call::node_function_call | ( | std::string | name,
|  | node_list | arguments
| ) |  |

Definition at line 181 of file node_impl.cpp.

182 : node_impl{}, name_{std::move(name)}, arguments_{std::move(arguments)}
183 {}
node_function_call::name
std::string name() const
Definition: node_impl.cpp:185
node_function_call::arguments
node_list const & arguments() const
Definition: node_impl.cpp:191
node_impl
Definition: node_impl.hpp:17
node_function_call::arguments_
node_list arguments_
Definition: node_impl.hpp:111
node_function_call::name_
std::string name_
Definition: node_impl.hpp:110

## Member Function Documentation

node_list const & node_function_call::arguments | ( |  | ) | const

Definition at line 191 of file node_impl.cpp.

References arguments_.

Referenced by evaluate_node(), and print_node().

193 {
194 return arguments_;
195 }
node_function_call::arguments_
node_list arguments_
Definition: node_impl.hpp:111

double node_function_call::evaluate_node | ( |  | ) | const
| override private virtual

Implements node_impl.

Definition at line 210 of file node_impl.cpp.

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

212 {
213 // Create a local symbol table, assigning all the node values to the parameters.
214 node function{get_function(name())};
215 identifier_list const& parameters{ function.get_parameters() };
216 if (parameters.size() != arguments().size())
217 throw function_error{name(), parameters.size(), arguments().size()};
218 else
219 {
220 // Create a local symbol table by assigning the arguments to the function parameters.
221 symbol_table locals{};
222 identifier_list::const_iterator parm{parameters.begin()};
223 for (auto const& arg : arguments()) {
224 locals.emplace(*parm, arg);
225 ++parm;
226 }
227 set_symbol_table syms{locals};
228 return function.evaluate();
229 }
230 }
get_function
node get_function(std::string const &name)
Definition: variables.cpp:61
node_function_call::name
std::string name() const
Definition: node_impl.cpp:185
node_function_call::arguments
node_list const & arguments() const
Definition: node_impl.cpp:191
node
Definition: node.hpp:26
identifier_list
std::vector< std::string > identifier_list
A sequence of identifiers (e.g., parameter names).
Definition: node.hpp:19
set_symbol_table
Definition: variables.hpp:19
function_error
Definition: calc_error.hpp:34
node::get_parameters
identifier_list const & get_parameters() const
Definition: node.cpp:69
symbol_table
std::map< std::string, node > symbol_table
Definition: variables.hpp:13

std::string node_function_call::name | ( |  | ) | const

Definition at line 185 of file node_impl.cpp.

References name_.

Referenced by evaluate_node(), and print_node().

187 {
188 return name_;
189 }
node_function_call::name_
std::string name_
Definition: node_impl.hpp:110

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

Implements node_impl.

Definition at line 197 of file node_impl.cpp.

References arguments(), and name().

199 {
200 stream << std::setw(indent) << "" << name() << "(\n";
201 std::size_t index{0};
202 for (auto const& arg : arguments()) {
203 stream << std::setw(indent+1) << "" << "arg " << index << ": ";
204 arg.print(stream, indent + 2);
205 ++index;
206 }
207 stream << std::setw(indent) << "" << ")\n";
208 }
node_function_call::name
std::string name() const
Definition: node_impl.cpp:185
node_function_call::arguments
node_list const & arguments() const
Definition: node_impl.cpp:191

## Member Data Documentation

node_list node_function_call::arguments_
| private

Definition at line 111 of file node_impl.hpp.

Referenced by arguments().

std::string node_function_call::name_
| private

Definition at line 110 of file node_impl.hpp.

Referenced by name().

The documentation for this class was generated from the following files:

- node_impl.hpp
- node_impl.cpp