This repository has been archived on 2024-01-28. You can view files and clone it, but cannot push or open issues or pull requests.
ecg-prog-filtered/u01/node.cpp

34 lines
837 B
C++
Raw Normal View History

2023-04-21 22:46:18 +02:00
#include <iostream>
#include <sstream>
2023-04-21 22:46:18 +02:00
#include "node.h"
unsigned int node::node_id = 0;
node::node(const std::string &name) : name(name) {
node_id++;
if (name.empty()) {
std::stringstream node_sm;
node_sm << "node_" << node_id;
this->name = node_sm.str();
}
}
2023-04-21 22:46:18 +02:00
node::~node() {
2023-04-21 22:46:37 +02:00
std::cout << "enter ~node() of \"" << get_name() << "\"" << std::endl;
2023-04-21 22:46:18 +02:00
for (node *child : children) {
delete child;
}
2023-04-21 22:46:37 +02:00
std::cout << "leave ~node() of \"" << get_name() << "\"" << std::endl;
2023-04-21 22:46:18 +02:00
}
std::string node::get_name() const { return name; }
void node::set_name(const std::string new_name) { this->name = new_name; }
unsigned int node::get_nr_children() const { return children.size(); }
node *node::get_child(std::size_t i) const { return children[i]; }
void node::add_child(node *child) { children.push_back(child); }