Advertisement
Guest User

Untitled

a guest
Sep 6th, 2021
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include <string>
  4.  
  5. #include "FileSystemObject.h"
  6. #include "FileSystemObjectsContainer.h"
  7.  
  8. const std::string ARROW = "--->";
  9.  
  10. void processDir(const std::shared_ptr<FileSystemObjectsContainer> directory) {
  11. for (auto obj = directory->begin(); obj < directory->end(); obj++) {
  12. std::cout << ARROW;
  13. std::shared_ptr<FileSystemObject> currObj = *obj;
  14. //if directory
  15. auto directory = std::dynamic_pointer_cast<Directory>(currObj);
  16. if (directory) {
  17. std::cout << directory->getName() << std::endl;
  18. std::cout << ARROW;
  19. processDir(directory);
  20. }
  21. //if file
  22. auto file = std::dynamic_pointer_cast<File>(currObj);
  23. if (file) {
  24. std::cout << file->getName() << std::endl;
  25. }
  26. }
  27. }
  28.  
  29.  
  30. std::string getTreeView(const std::vector<std::shared_ptr<FileSystemObject>>& rootObjects) {
  31.  
  32. for (size_t i = 0; i < rootObjects.size(); i++) {
  33. std::shared_ptr<FileSystemObject> currObj = rootObjects[i];
  34.  
  35. //if directory
  36. auto directory = std::dynamic_pointer_cast<Directory>(currObj);
  37. if (directory) {
  38. std::cout << directory->getName() << std::endl;
  39. processDir(directory);
  40. continue;
  41. }
  42.  
  43. //if file
  44. auto file = std::dynamic_pointer_cast<File>(currObj);
  45. if (file) {
  46. std::cout << file->getName() << std::endl;
  47. continue;
  48. }
  49.  
  50. //if shortcut to file
  51. auto shortcut = std::dynamic_pointer_cast<FileSystemObject>(currObj);
  52. if (shortcut) {
  53. std::cout << shortcut->getName() << std::endl;
  54. std::cout << ARROW;
  55.  
  56. }
  57.  
  58. //if shortcut to dir
  59. auto shortcutDir = std::dynamic_pointer_cast<FileSystemObjectsContainer>(currObj);
  60. if (shortcutDir) {
  61. //std::cout << container->getName() << std::endl;
  62. std::cout << ARROW;
  63. processDir(shortcutDir);
  64.  
  65. }
  66. }
  67. return "";
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement