Simon Bruder
db4d489ae8
size_t should only be used for indexing. For all other purposes, unsigned int should be used.
35 lines
1,003 B
C++
35 lines
1,003 B
C++
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
#include <set>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class node {
|
|
public:
|
|
node(const std::string &name = "");
|
|
virtual ~node();
|
|
std::string get_name() const;
|
|
void set_name(const std::string new_name);
|
|
std::size_t get_nr_children() const;
|
|
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;
|
|
|
|
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;
|
|
};
|
|
|
|
extern std::ostream &operator<<(std::ostream &os, node &n);
|
|
|
|
node *create_complete_tree(std::size_t nr_child_nodes, unsigned int tree_depth);
|