void DirectoryTree::TraverseBreadthFirst(Directory& dir, const DirectoryEntryVisitor& visitor) { if (!dir) { return; } Aws::Queue<DirectoryEntry> queue; while (DirectoryEntry&& entry = dir.Next()) { queue.push(std::move(entry)); } while (queue.size() > 0) { auto entry = queue.front(); queue.pop(); if(visitor(this, entry)) { if(entry.fileType == FileType::Directory) { auto currentDir = dir.Descend(entry); while (DirectoryEntry&& dirEntry = currentDir->Next()) { queue.push(std::move(dirEntry)); } } } else { return; } } }
bool DirectoryTree::TraverseDepthFirst(Directory& dir, const DirectoryEntryVisitor& visitor, bool postOrder) { if (!dir) { return true; } bool exitTraversal(false); DirectoryEntry entry; while ((entry = dir.Next()) && !exitTraversal) { if(!postOrder) { if(!visitor(this, entry)) { return false; } } if (entry.fileType == FileType::Directory) { auto subDir = dir.Descend(entry); exitTraversal = !TraverseDepthFirst(*subDir, visitor, postOrder); } if (postOrder) { if (!visitor(this, entry)) { return false; } } } return !exitTraversal; }