|
- #pragma once
-
- #include <string>
- #include <memory>
- #include <iterator>
-
- #if cppfs_os == cppfs_os_linux
- #include <dirent.h>
- #endif
-
- #include "../path.h"
- #include "../misc.h"
-
- namespace cppfs
- {
-
- struct directory
- {
- public:
- struct entry
- {
- public:
- file_type type;
- std::string name;
- };
-
- struct iterator
- : public std::iterator<std::forward_iterator_tag, const entry>
- {
- private:
- const directory * _owner;
- entry _entry;
-
- public:
- inline iterator(
- const directory& p_owner,
- bool p_end);
-
- inline iterator(
- iterator&& p_other);
-
- inline iterator(
- const iterator& p_other);
-
- inline iterator& operator=(iterator&& p_other);
- inline iterator& operator=(const iterator& p_other);
-
- inline iterator& operator++();
- inline iterator operator++(int);
-
- inline bool operator==(const iterator& p_other) const;
- inline bool operator!=(const iterator& p_other) const;
-
- inline reference operator* () const;
- inline pointer operator->() const;
-
- #if cppfs_os == cppfs_os_linux
- private:
- using dir_ptr_u = std::unique_ptr<DIR, decltype(&closedir)>;
-
- dir_ptr_u _dir;
- struct dirent * _dirent;
-
- inline void next();
- inline long offset() const;
- #endif
- };
-
- private:
- cppfs::path _path;
-
- public:
- /**
- * @brief Constructor.
- */
- template<typename... T_args>
- inline directory(T_args&&... p_args);
-
- /**
- * @brief Get the path of the directory.
- */
- inline const cppfs::path& path() const;
-
- /**
- * @brief Check if the directory exsists.
- */
- inline bool exists() const;
-
- /**
- * @brief Create the directory.
- */
- inline const directory& create(
- bool p_parent,
- const file_permissions& p_perm = file_permissions::defaults()) const;
-
- /**
- * @brief Remove the directory (and all it's content if the parameter is set to true)
- */
- inline const directory& remove(
- bool p_recursive) const;
-
- /**
- * @brief Create a begin iterator.
- */
- inline iterator begin() const;
-
- /**
- * @brief Create a end iterator.
- */
- inline iterator end() const;
-
- private:
- /**
- * @brief Remove the directory if it's empty.
- */
- inline void remove_dir() const;
- };
-
- }
|