Calculator Step 6

- 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 ()
| node_impl (node_impl &&)=default
node_impl & | operator= (node_impl &&)=default
void | print (std::ostream &stream, int indent) const
number | 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 number | 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 101 of file node_impl.hpp.

## Constructor & Destructor Documentation

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

Definition at line 202 of file node_impl.cpp.

203 : node_impl{}, parameters_{std::move(parameters)}, definition_{definition}
204 {}
node_function::definition_
node definition_
Definition: node_impl.hpp:114
node_impl
Definition: node_impl.hpp:20
node_function::parameters_
identifier_list parameters_
Definition: node_impl.hpp:113
node_function::parameters
identifier_list const & parameters() const
Definition: node_impl.cpp:222

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

Definition at line 206 of file node_impl.cpp.

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

## Member Function Documentation

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

Definition at line 228 of file node_impl.cpp.

References definition_.

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

230 {
231 return definition_;
232 }
node_function::definition_
node definition_
Definition: node_impl.hpp:114

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

Implements node_impl.

Definition at line 254 of file node_impl.cpp.

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

256 {
257 return definition().evaluate();
258 }
node_function::definition
node definition() const
Definition: node_impl.cpp:228
node::evaluate
number evaluate() const
Definition: node.cpp:73

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

Reimplemented from node_impl.

Definition at line 260 of file node_impl.cpp.

References parameters().

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

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

Definition at line 222 of file node_impl.cpp.

References parameters_.

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

224 {
225 return parameters_;
226 }
node_function::parameters_
identifier_list parameters_
Definition: node_impl.hpp:113

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

Implements node_impl.

Definition at line 245 of file node_impl.cpp.

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

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

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

Implements node_impl.

Definition at line 266 of file node_impl.cpp.

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

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

## Member Data Documentation

node node_function::definition_
| private

Definition at line 114 of file node_impl.hpp.

Referenced by definition().

identifier_list node_function::parameters_
| private

Definition at line 113 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