-
Notifications
You must be signed in to change notification settings - Fork 0
Add filetree definitions #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: cpp
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,14 +8,41 @@ | |
| #include <tempeh/common/typedefs.hpp> | ||
| #include <cassert> | ||
| #include <system_error> | ||
| #include <list> | ||
|
|
||
| namespace TempehEditor::FileSystem { | ||
|
|
||
| FileTree::FileTree(std::string& path_str) | ||
| namespace fs = std::filesystem; | ||
|
|
||
| FileTree::FileTree(const fs::path &path_str) | ||
| { | ||
| std::filesystem::path path(path_str); | ||
| std::error_code err; | ||
| assert(std::filesystem::exists(path, err) && "Path did not exists"); | ||
| std::list<FileTreeMap::iterator> list; | ||
|
|
||
| auto [iter, _] = hashmap.insert_or_assign(path_str.string(), | ||
| nullptr); | ||
|
|
||
| list.push_back(iter); | ||
|
|
||
| while (!list.empty()) { | ||
| auto current_entry = list.front(); | ||
| list.pop_front(); | ||
| for (const auto & entry : fs::directory_iterator(current_entry->first)) { | ||
|
|
||
| fs::path p = entry.path(); | ||
|
|
||
| std::shared_ptr<FileTree> tree; | ||
|
|
||
| if (fs::path(p).filename() == ".git") { | ||
|
||
| continue; | ||
| } | ||
| if (fs::is_directory(p)) { | ||
| tree = std::make_shared<FileTree>(p); | ||
| } | ||
|
|
||
| auto [i, _] = hashmap.insert_or_assign(p.string(), tree); | ||
| list.push_back(i); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // TODO | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use list.
https://dzone.com/articles/c-benchmark-%E2%80%93-stdvector-vs