-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirectory tree.h
More file actions
84 lines (66 loc) · 2.54 KB
/
directory tree.h
File metadata and controls
84 lines (66 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once
#include <memory>
#include <string>
#include <string_view>
#include <list>
#include <filesystem>
namespace fs = std::filesystem;
class DirectoryTree
{
private:
struct Node
{
fs::path path{};
std::unique_ptr<Node> firstChild { nullptr };
std::unique_ptr<Node> nextSibling { nullptr };
};
class Iterator
{
private:
struct History
{
std::list<const Node*> record{};
std::list<const Node*>::iterator currentNode{};
History() = default;
History(const Node* node);
const Node* current();
void setCurrentToLast();
void add(const Node* node);
void reset();
void deleteUntilCurrent();
void deleteAfterCurrent();
};
mutable History m_history{};
mutable DirectoryTree* m_this_tree{};
void toNonExistentNode(const fs::path& path) const;
void toNonExistentDerivedNode(std::string_view pathString, const Node* parent) const;
public:
Iterator(const Node* pointer, DirectoryTree* currentTree);
Iterator(const Iterator&) = delete;
void operator=(const Iterator&) = delete;
const Node* get() const;
void toPath(const fs::path& path) const;
void toNode(const Node* node) const;
void toSibling() const;
void toChild() const;
void toParent() const;
void toRoot() const;
void back() const;
void forward() const;
friend class TreeDisplayer;
};
std::unique_ptr<Node> m_root{};
Iterator m_iterator{ m_root.get(), this };
void addChildren(Node* parent, std::unique_ptr<Node>* existingChild = nullptr);
void addRootParent();
const Node* findChild(const Node* node, const fs::path& path) const;
const Node* findParent(const Node* node) const;
public:
DirectoryTree(const DirectoryTree&) = delete;
void operator=(const DirectoryTree&) = delete;
DirectoryTree();
explicit DirectoryTree(const fs::path& path);
const Node* findPath(const fs::path& path) const;
const Iterator& iterator() const;
friend class TreeDisplayer;
};