CppCommon  1.0.4.1
C++ Common Library
directory.h
Go to the documentation of this file.
1 
9 #ifndef CPPCOMMON_FILESYSTEM_DIRECTORY_H
10 #define CPPCOMMON_FILESYSTEM_DIRECTORY_H
11 
13 #include "filesystem/file.h"
14 #include "filesystem/symlink.h"
15 
16 namespace CppCommon {
17 
19 
24 class Directory : public Path
25 {
26 public:
31 
33  Directory() : Path() {}
35 
38  Directory(const Path& path) : Path(path) {}
39  Directory(const Directory&) = default;
40  Directory(Directory&&) = default;
41  ~Directory() = default;
42 
43  Directory& operator=(const Path& path)
44  { Assign(path); return *this; }
45  Directory& operator=(const Directory&) = default;
46  Directory& operator=(Directory&&) = default;
47 
49  explicit operator bool() const noexcept { return IsDirectoryExists(); }
50 
52  bool IsDirectoryExists() const;
54  bool IsDirectoryEmpty() const;
55 
57  DirectoryIterator begin() const;
59  DirectoryIterator end() const;
60 
62  DirectoryIterator rbegin() const;
64  DirectoryIterator rend() const;
65 
67 
71  std::vector<Path> GetEntries(const std::string& pattern = "");
73 
77  std::vector<Path> GetEntriesRecursive(const std::string& pattern = "");
78 
80 
84  std::vector<Directory> GetDirectories(const std::string& pattern = "");
86 
90  std::vector<Directory> GetDirectoriesRecursive(const std::string& pattern = "");
91 
93 
97  std::vector<File> GetFiles(const std::string& pattern = "");
99 
103  std::vector<File> GetFilesRecursive(const std::string& pattern = "");
104 
106 
110  std::vector<Symlink> GetSymlinks(const std::string& pattern = "");
112 
116  std::vector<Symlink> GetSymlinksRecursive(const std::string& pattern = "");
117 
119 
127 
134 
136  void swap(Directory& directory) noexcept;
137  friend void swap(Directory& directory1, Directory& directory2) noexcept;
138 };
139 
142 } // namespace CppCommon
143 
144 #include "directory.inl"
145 
146 #endif // CPPCOMMON_FILESYSTEM_DIRECTORY_H
Filesystem directory.
Definition: directory.h:25
std::vector< File > GetFilesRecursive(const std::string &pattern="")
Recursively get all files (including symbolic link files) in the current directory.
Definition: directory.cpp:214
static const Flags< FileAttributes > DEFAULT_ATTRIBUTES
Default directory attributes (Normal)
Definition: directory.h:28
std::vector< Path > GetEntriesRecursive(const std::string &pattern="")
Recursively get all entries (directories, files, symbolic links) in the current directory.
Definition: directory.cpp:147
bool IsDirectoryExists() const
Is the directory exists?
Definition: directory.cpp:31
Directory(Directory &&)=default
Directory & operator=(const Directory &)=default
Directory(const Directory &)=default
void swap(Directory &directory) noexcept
Swap two instances.
Definition: directory.inl:11
DirectoryIterator begin() const
Get the directory begin iterator.
Definition: directory.cpp:117
Directory(const Path &path)
Initialize directory with a given path.
Definition: directory.h:38
Directory & operator=(Directory &&)=default
static Directory CreateTree(const Path &path, const Flags< FileAttributes > &attributes=Directory::DEFAULT_ATTRIBUTES, const Flags< FilePermissions > &permissions=Directory::DEFAULT_PERMISSIONS)
Create full directory tree of the given path.
Definition: directory.cpp:303
DirectoryIterator end() const
Get the directory end iterator.
Definition: directory.cpp:122
std::vector< Symlink > GetSymlinksRecursive(const std::string &pattern="")
Recursively get all symbolic links (including symbolic link directories) in the current directory.
Definition: directory.cpp:247
static const Flags< FilePermissions > DEFAULT_PERMISSIONS
Default directory permissions (IRUSR | IWUSR | IXUSR | IRGRP | IXGRP | IROTH | IXOTH)
Definition: directory.h:30
std::vector< Directory > GetDirectoriesRecursive(const std::string &pattern="")
Recursively get all directories (including symbolic link directories) in the current directory.
Definition: directory.cpp:176
std::vector< Symlink > GetSymlinks(const std::string &pattern="")
Get all symbolic links (including symbolic link directories) in the current directory.
Definition: directory.cpp:233
std::vector< Path > GetEntries(const std::string &pattern="")
Get all entries (directories, files, symbolic links) in the current directory.
Definition: directory.cpp:137
DirectoryIterator rbegin() const
Get the directory recursive begin iterator.
Definition: directory.cpp:127
std::vector< Directory > GetDirectories(const std::string &pattern="")
Get all directories (including symbolic link directories) in the current directory.
Definition: directory.cpp:157
static Directory Create(const Path &path, const Flags< FileAttributes > &attributes=Directory::DEFAULT_ATTRIBUTES, const Flags< FilePermissions > &permissions=Directory::DEFAULT_PERMISSIONS)
Create directory from the given path.
Definition: directory.cpp:261
std::vector< File > GetFiles(const std::string &pattern="")
Get all files (including symbolic link files) in the current directory.
Definition: directory.cpp:195
Directory & operator=(const Path &path)
Definition: directory.h:43
bool IsDirectoryEmpty() const
Is the directory empty?
Definition: directory.cpp:60
Directory()
Initialize directory with an empty path.
Definition: directory.h:33
DirectoryIterator rend() const
Get the directory recursive end iterator.
Definition: directory.cpp:132
Filesystem directory iterator.
Filesystem path.
Definition: path.h:90
Path & Assign(const Path &path)
Assign the given path to the current one.
Definition: path.inl:20
Flags< FileAttributes > attributes() const
Get the path file attributes.
Definition: path.cpp:472
Flags< FilePermissions > permissions() const
Get the path file permissions.
Definition: path.cpp:499
Filesystem directory inline implementation.
Filesystem directory iterator definition.
Filesystem file definition.
C++ Common project definitions.
Definition: token_bucket.h:15