diff --git a/.gitignore b/.gitignore index d45fc41..22e9802 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /compile/main -.vscode \ No newline at end of file +.vscode +obj \ No newline at end of file diff --git a/obj/controller/DirectoryGraph.o b/obj/controller/DirectoryGraph.o deleted file mode 100644 index f5b515e..0000000 Binary files a/obj/controller/DirectoryGraph.o and /dev/null differ diff --git a/obj/main.o b/obj/main.o deleted file mode 100644 index 2de60ae..0000000 Binary files a/obj/main.o and /dev/null differ diff --git a/obj/model/DirectoryNode.o b/obj/model/DirectoryNode.o deleted file mode 100644 index c9efab3..0000000 Binary files a/obj/model/DirectoryNode.o and /dev/null differ diff --git a/obj/view/Dree.o b/obj/view/Dree.o deleted file mode 100644 index e528149..0000000 Binary files a/obj/view/Dree.o and /dev/null differ diff --git a/src/controller/DirectoryGraph.cpp b/src/controller/DirectoryGraph.cpp index d63027c..4b7451a 100644 --- a/src/controller/DirectoryGraph.cpp +++ b/src/controller/DirectoryGraph.cpp @@ -9,14 +9,14 @@ bool DirectoryGraph::isDirectory(const string &pathStr) return filesystem::is_directory(path); } -DirectoryNode *DirectoryGraph::BuildGraph(const string &directoryName, int depth) +DirectoryNode *DirectoryGraph::BuildGraph(const string &directoryName, long long depth) { DirectoryNode *graph = new DirectoryNode(directoryName); TraverseDirectoriesDFS(graph, depth, 0); return graph; } -void DirectoryGraph::TraverseDirectoriesDFS(DirectoryNode *node, int depth, int currentDepth) +void DirectoryGraph::TraverseDirectoriesDFS(DirectoryNode *node, long long depth, long long currentDepth) { if (currentDepth > depth) return; @@ -40,19 +40,33 @@ void DirectoryGraph::TraverseDirectoriesDFS(DirectoryNode *node, int depth, int } } -void DirectoryGraph::PrintGraph(DirectoryNode *node, int depth, int currentDepth) +void DirectoryGraph::PrintGraph(DirectoryNode *node, long long depth, long long currentDepth, bool isLastChild, long long mask) { if (currentDepth == depth) return; - for (int i = 0; i < currentDepth * depth; ++i) - cout << " "; - cout << "└── "; + for (long long i = 0; i < currentDepth; i++) + { + if (((mask >> i) & 1ll) == 0ll) + cout << "│ "; + else + cout << " "; + } + isLastChild ? cout << "└── " : cout << "├── "; cout << node->name << "\n"; - for (size_t i = 0; i < node->children.size(); ++i) + for (size_t i = 0; i < node->children.size(); i++) { DirectoryNode *child = node->children[i]; - PrintGraph(child, depth, currentDepth + 1); + if (i == node->children.size() - 1) + { + mask = mask | (1ll << (currentDepth + 1)); + } + PrintGraph(child, depth, currentDepth + 1, i == node->children.size() - 1, mask); } } + +void DirectoryGraph::PrintGraph(DirectoryNode *node, long long depth) +{ + this->PrintGraph(node, depth, 0, true, 1); +} \ No newline at end of file diff --git a/src/controller/DirectoryGraph.h b/src/controller/DirectoryGraph.h index 58373b1..408157c 100644 --- a/src/controller/DirectoryGraph.h +++ b/src/controller/DirectoryGraph.h @@ -11,14 +11,13 @@ using namespace std; class DirectoryGraph { public: - DirectoryNode *BuildGraph(const string &directoryName, int depth); - - void PrintGraph(DirectoryNode *node, int depth, int currentDepth = 0); + DirectoryNode *BuildGraph(const string &directoryName, long long depth); + void PrintGraph(DirectoryNode *node, long long depth); private: bool isDirectory(const std::string &pathStr); - - void TraverseDirectoriesDFS(DirectoryNode *node, int depth, int currentDepth = 0); + void TraverseDirectoriesDFS(DirectoryNode *node, long long depth, long long currentDepth = 0); + void PrintGraph(DirectoryNode *node, long long depth, long long currentDepth, bool isLastChild, long long mask); }; #endif diff --git a/src/main.cpp b/src/main.cpp index cb1c624..13ac231 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,9 +8,10 @@ using namespace std; int main() { + long long depth = 3; // should not be more than 60 auto currentPath = filesystem::current_path(); DirectoryGraph builder; - auto root = builder.BuildGraph(currentPath, 4); - builder.PrintGraph(root, 4); + auto root = builder.BuildGraph(currentPath, depth); + builder.PrintGraph(root, depth); return 0; }