Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <string>
- #include "FileSystemObject.h"
- #include "FileSystemObjectsContainer.h"
- const std::string ARROW = "--->";
- void processDir(const std::shared_ptr<FileSystemObjectsContainer> directory) {
- for (auto obj = directory->begin(); obj < directory->end(); obj++) {
- std::cout << ARROW;
- std::shared_ptr<FileSystemObject> currObj = *obj;
- //if directory
- auto directory = std::dynamic_pointer_cast<Directory>(currObj);
- if (directory) {
- std::cout << directory->getName() << std::endl;
- std::cout << ARROW;
- processDir(directory);
- }
- //if file
- auto file = std::dynamic_pointer_cast<File>(currObj);
- if (file) {
- std::cout << file->getName() << std::endl;
- }
- }
- }
- std::string getTreeView(const std::vector<std::shared_ptr<FileSystemObject>>& rootObjects) {
- for (size_t i = 0; i < rootObjects.size(); i++) {
- std::shared_ptr<FileSystemObject> currObj = rootObjects[i];
- //if directory
- auto directory = std::dynamic_pointer_cast<Directory>(currObj);
- if (directory) {
- std::cout << directory->getName() << std::endl;
- processDir(directory);
- continue;
- }
- //if file
- auto file = std::dynamic_pointer_cast<File>(currObj);
- if (file) {
- std::cout << file->getName() << std::endl;
- continue;
- }
- //if shortcut to file
- auto shortcut = std::dynamic_pointer_cast<FileSystemObject>(currObj);
- if (shortcut) {
- std::cout << shortcut->getName() << std::endl;
- std::cout << ARROW;
- }
- //if shortcut to dir
- auto shortcutDir = std::dynamic_pointer_cast<FileSystemObjectsContainer>(currObj);
- if (shortcutDir) {
- //std::cout << container->getName() << std::endl;
- std::cout << ARROW;
- processDir(shortcutDir);
- }
- }
- return "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement