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

35 lines
1004 B
C
Raw Permalink Normal View History

2023-04-22 14:45:43 +02:00
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
2023-04-21 22:46:18 +02:00
#include <memory>
#include <set>
2023-04-21 22:46:18 +02:00
#include <string>
#include <vector>
class node {
public:
node(const std::string &name = "");
2023-04-21 22:46:18 +02:00
virtual ~node();
std::string get_name() const;
void set_name(const std::string &new_name);
std::size_t get_nr_children() const;
2023-04-21 22:46:18 +02:00
node *get_child(std::size_t i) const;
void add_child(node *child);
void print(std::ostream &str, unsigned int depth = 0) const;
std::string print_recursive(unsigned int depth = 0,
std::set<const node *> visited = {}) const;
std::string print_iterative() const;
2023-04-21 22:46:18 +02:00
private:
std::string name;
std::vector<node *> children;
bool destroy =
false; // gets set by the destructor,
// allows deletion of recursive trees with a recursive destructor
static unsigned int node_id;
2023-04-21 22:46:18 +02:00
};
2023-04-21 23:56:14 +02:00
2023-04-22 11:43:39 +02:00
extern std::ostream &operator<<(std::ostream &os, node &n);
2023-04-21 23:56:14 +02:00
node *create_complete_tree(std::size_t nr_child_nodes, unsigned int tree_depth);