Calculator  Step 5
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:
node_impl

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_implread_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 {}
identifier_list parameters_
Definition: node_impl.hpp:110
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 }
Definition: node.hpp:26
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 }
double node_function::evaluate_node ( ) const
overrideprivatevirtual

Implements node_impl.

Definition at line 255 of file node_impl.cpp.

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

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

Reimplemented from node_impl.

Definition at line 261 of file node_impl.cpp.

References parameters().

263 {
264  return parameters();
265 }
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 }
identifier_list parameters_
Definition: node_impl.hpp:110
void node_function::print_node ( std::ostream &  stream,
int  indent 
) const
overrideprivatevirtual

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";
251  stream << '=';
252  definition().print(stream, indent + 2);
253 }
node definition() const
Definition: node_impl.cpp:229
void print(std::ostream &stream, int indent=0) const
Definition: node.cpp:54
void print_identifier_list(std::ostream &stream, identifier_list const &identifiers)
Definition: node_impl.cpp:235
identifier_list const & parameters() const
Definition: node_impl.cpp:223
void node_function::save_node ( std::ostream &  stream) const
overrideprivatevirtual

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 definition() const
Definition: node_impl.cpp:229
void save(std::ostream &stream) const
Definition: node.cpp:78
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: