25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

120 satır
2.7 KiB

  1. #pragma once
  2. #include <string>
  3. #include <memory>
  4. #include <iterator>
  5. #if cppfs_os == cppfs_os_linux
  6. #include <dirent.h>
  7. #endif
  8. #include "../path.h"
  9. #include "../misc.h"
  10. namespace cppfs
  11. {
  12. struct directory
  13. {
  14. public:
  15. struct entry
  16. {
  17. public:
  18. file_type type;
  19. std::string name;
  20. };
  21. struct iterator
  22. : public std::iterator<std::forward_iterator_tag, const entry>
  23. {
  24. private:
  25. const directory * _owner;
  26. entry _entry;
  27. public:
  28. inline iterator(
  29. const directory& p_owner,
  30. bool p_end);
  31. inline iterator(
  32. iterator&& p_other);
  33. inline iterator(
  34. const iterator& p_other);
  35. inline iterator& operator=(iterator&& p_other);
  36. inline iterator& operator=(const iterator& p_other);
  37. inline iterator& operator++();
  38. inline iterator operator++(int);
  39. inline bool operator==(const iterator& p_other) const;
  40. inline bool operator!=(const iterator& p_other) const;
  41. inline reference operator* () const;
  42. inline pointer operator->() const;
  43. #if cppfs_os == cppfs_os_linux
  44. private:
  45. using dir_ptr_u = std::unique_ptr<DIR, decltype(&closedir)>;
  46. dir_ptr_u _dir;
  47. struct dirent * _dirent;
  48. inline void next();
  49. inline long offset() const;
  50. #endif
  51. };
  52. private:
  53. cppfs::path _path;
  54. public:
  55. /**
  56. * @brief Constructor.
  57. */
  58. template<typename... T_args>
  59. inline directory(T_args&&... p_args);
  60. /**
  61. * @brief Get the path of the directory.
  62. */
  63. inline const cppfs::path& path() const;
  64. /**
  65. * @brief Check if the directory exsists.
  66. */
  67. inline bool exists() const;
  68. /**
  69. * @brief Create the directory.
  70. */
  71. inline const directory& create(
  72. bool p_parent,
  73. const file_permissions& p_perm = file_permissions::defaults()) const;
  74. /**
  75. * @brief Remove the directory (and all it's content if the parameter is set to true)
  76. */
  77. inline const directory& remove(
  78. bool p_recursive) const;
  79. /**
  80. * @brief Create a begin iterator.
  81. */
  82. inline iterator begin() const;
  83. /**
  84. * @brief Create a end iterator.
  85. */
  86. inline iterator end() const;
  87. private:
  88. /**
  89. * @brief Remove the directory if it's empty.
  90. */
  91. inline void remove_dir() const;
  92. };
  93. }