Calculator Step 5

- 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 Class Reference

`#include <node_impl.hpp>`

Inheritance diagram for node_function:

## Public Member Functions
| node_function (identifier_list parameters, node definition)
| node_function (std::istream &stream)
identifier_list const & | parameters () const
node | definition () const
Public Member Functions inherited from node_impl
| node_impl ()
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
void | save (std::ostream &stream) const

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

## Private Attributes
identifier_list | parameters_
node | definition_

## Additional Inherited Members
Static Public Member Functions inherited from node_impl
static std::shared_ptr< node_impl > | read_node (std::istream &stream)

## Detailed Description

Function definition. A function has parameters and a definition.

Definition at line 98 of file node_impl.hpp.

## Constructor & Destructor Documentation

node_function::node_function | ( | identifier_list | parameters,
|  | node | definition
| ) |  |

Definition at line 203 of file node_impl.cpp.

204 : node_impl{}, parameters_{std::move(parameters)}, definition_(definition)
205 {}
node_function::definition_
node definition_
Definition: node_impl.hpp:111
node_impl
Definition: node_impl.hpp:20
node_function::parameters_
identifier_list parameters_
Definition: node_impl.hpp:110
node_function::parameters
identifier_list const & parameters() const
Definition: node_impl.cpp:223

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

Definition at line 207 of file node_impl.cpp.

208 : node_impl{}
209 {
210 std::size_t size{};
211 if (not (stream >> size))
212 throw calc_error{"malformed library file, cannot read function"};
213 parameters_.reserve(size);
214 while (size-- != 0) {
215 std::string parameter{};
216 if (not (stream >> parameter))
217 throw calc_error{"malformed library file, cannot read function parameter"};
218 parameters_.emplace_back(std::move(parameter));
219 }
220 definition_ = node(stream);
221 }
node_function::definition_
node definition_
Definition: node_impl.hpp:111
calc_error
Definition: calc_error.hpp:11
node_impl
Definition: node_impl.hpp:20
node
Definition: node.hpp:26
node_function::parameters_
identifier_list parameters_
Definition: node_impl.hpp:110

## Member Function Documentation

node node_function::definition | ( |  | ) | const

Definition at line 229 of file node_impl.cpp.

References definition_.

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

231 {
232 return definition_;
233 }
node_function::definition_
node definition_
Definition: node_impl.hpp:111

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

Implements node_impl.

Definition at line 255 of file node_impl.cpp.

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

257 {
258 return definition().evaluate();
259 }
node_function::definition
node definition() const
Definition: node_impl.cpp:229
node::evaluate
double evaluate() const
Definition: node.cpp:60

identifier_list const & node_function::evaluate_parameters | ( |  | ) | const
| override private virtual

Reimplemented from node_impl.

Definition at line 261 of file node_impl.cpp.

References parameters().

263 {
264 return parameters();
265 }
node_function::parameters
identifier_list const & parameters() const
Definition: node_impl.cpp:223

identifier_list const & node_function::parameters | ( |  | ) | const

Definition at line 223 of file node_impl.cpp.

References parameters_.

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

225 {
226 return parameters_;
227 }
node_function::parameters_
identifier_list parameters_
Definition: node_impl.hpp:110

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

Implements node_impl.

Definition at line 246 of file node_impl.cpp.

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

248 {
249 stream << std::setw(indent) << "" << "fun\n";
250 print_identifier_list(stream, parameters());
251 stream << '=';
252 definition().print(stream, indent + 2);
253 }
node_function::definition
node definition() const
Definition: node_impl.cpp:229
node::print
void print(std::ostream &stream, int indent=0) const
Definition: node.cpp:54
print_identifier_list
void print_identifier_list(std::ostream &stream, identifier_list const &identifiers)
Definition: node_impl.cpp:235
node_function::parameters
identifier_list const & parameters() const
Definition: node_impl.cpp:223

void node_function::save_node | ( | std::ostream & | stream | ) | const
| override private virtual

Implements node_impl.

Definition at line 267 of file node_impl.cpp.

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

269 {
270 stream << "function " << parameters().size() << ' ';
271 for (auto const& parameter : parameters())
272 stream << parameter << ' ';
273 definition().save(stream);
274 }
node_function::definition
node definition() const
Definition: node_impl.cpp:229
node::save
void save(std::ostream &stream) const
Definition: node.cpp:78
node_function::parameters
identifier_list const & parameters() const
Definition: node_impl.cpp:223

## Member Data Documentation

node node_function::definition_
| private

Definition at line 111 of file node_impl.hpp.

Referenced by definition().

identifier_list node_function::parameters_
| private

Definition at line 110 of file node_impl.hpp.

Referenced by parameters().

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

- node_impl.hpp
- node_impl.cpp