Doxygen
Loading...
Searching...
No Matches
dir.h
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Copyright (C) 1997-2021 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15
16#ifndef DIR_H
17#define DIR_H
18
19#include <string>
20#include <memory>
21
22#include "fileinfo.h"
23
25{
26 public:
28 DirEntry(const DirEntry &);
29 DirEntry &operator=(const DirEntry &);
32 bool is_directory() const;
33 bool is_regular_file() const;
34 bool is_symlink() const;
35 std::string path() const;
36 private:
37 friend class DirIterator;
38 DirEntry();
39 struct Private;
40 std::unique_ptr<Private> p;
41};
42
44{
45 public:
47 using difference_type = std::ptrdiff_t;
50 using iterator_category = std::input_iterator_tag;
51 DirIterator(const DirIterator &it);
56 const value_type &operator*() const;
57 const value_type *operator->() const;
58
59 friend bool operator==(const DirIterator &it1,const DirIterator &it2);
60 friend bool operator!=(const DirIterator &it1,const DirIterator &it2);
61 friend DirIterator begin(DirIterator it) noexcept;
62 friend DirIterator end(const DirIterator &) noexcept;
64
65 private:
66 friend class Dir;
68 DirIterator(const std::string &path);
69 struct Private;
70 std::unique_ptr<Private> p;
71};
72
73/** Class representing a directory in the file system */
74class Dir final
75{
76 public:
77 Dir();
78 Dir(const std::string &path);
79 Dir(const Dir &d);
80 Dir &operator=(const Dir &d);
81 Dir(Dir &&d);
82 Dir &operator=(Dir &&d);
83 ~Dir();
84 void setPath(const std::string &path);
85 std::string path() const;
86
87 DirIterator iterator() const;
88
89 bool isEmpty(const std::string subdir) const;
90 bool exists() const;
91 std::string filePath(const std::string &path,bool acceptsAbsPath=true) const;
92 bool exists(const std::string &path,bool acceptsAbsPath=true) const;
93 bool mkdir(const std::string &path,bool acceptsAbsPath=true) const;
94 bool rmdir(const std::string &path,bool acceptsAbsPath=true) const;
95 bool remove(const std::string &path,bool acceptsAbsPath=true) const;
96 bool rename(const std::string &orgName,const std::string &newName,
97 bool acceptsAbsPath=true) const;
98 bool copy(const std::string &src,const std::string &dest,bool acceptsAbsPath=true) const;
99 std::string absPath() const;
100
101 bool isRelative() const;
102
103 static bool isRelativePath(const std::string &path);
104 static std::string currentDirPath();
105 static bool setCurrent(const std::string &path);
106 static std::string cleanDirPath(const std::string &path);
107
108 private:
109 struct Private;
110 std::unique_ptr<Private> p;
111};
112
113#endif
Definition dir.h:25
~DirEntry()
DirEntry(const DirEntry &)
Definition dir.cpp:37
friend class DirIterator
Definition dir.h:37
bool is_directory() const
Definition dir.cpp:65
bool is_regular_file() const
Definition dir.cpp:70
std::string path() const
Definition dir.cpp:80
std::unique_ptr< Private > p
Definition dir.h:40
DirEntry & operator=(const DirEntry &)
Definition dir.cpp:42
bool is_symlink() const
Definition dir.cpp:75
DirEntry()
Definition dir.cpp:33
static std::string currentDirPath()
Definition dir.cpp:340
Dir()
Definition dir.cpp:189
bool isEmpty(const std::string subdir) const
Definition dir.cpp:263
Dir & operator=(const Dir &d)
Definition dir.cpp:200
std::string absPath() const
Definition dir.cpp:363
bool mkdir(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:295
void setPath(const std::string &path)
Definition dir.cpp:229
static bool isRelativePath(const std::string &path)
Definition dir.cpp:275
~Dir()
Definition dir.cpp:225
bool isRelative() const
Definition dir.cpp:270
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:314
bool copy(const std::string &src, const std::string &dest, bool acceptsAbsPath=true) const
Definition dir.cpp:330
std::string filePath(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:280
DirIterator iterator() const
Definition dir.cpp:239
bool rmdir(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:309
bool rename(const std::string &orgName, const std::string &newName, bool acceptsAbsPath=true) const
Definition dir.cpp:321
static std::string cleanDirPath(const std::string &path)
Definition dir.cpp:355
static bool setCurrent(const std::string &path)
Definition dir.cpp:348
std::string path() const
Definition dir.cpp:234
bool exists() const
Definition dir.cpp:257
std::unique_ptr< Private > p
Definition dir.h:110
DirIterator()
Definition dir.cpp:96
std::ptrdiff_t difference_type
Definition dir.h:47
DirEntry value_type
Definition dir.h:46
DirIterator(const DirIterator &it)
Definition dir.cpp:104
std::input_iterator_tag iterator_category
Definition dir.h:50
DirIterator operator++()
Definition dir.cpp:141
value_type & reference
Definition dir.h:49
~DirIterator()
Definition dir.cpp:137
const value_type & operator*() const
Definition dir.cpp:148
const value_type * operator->() const
Definition dir.cpp:154
friend bool operator==(const DirIterator &it1, const DirIterator &it2)
Definition dir.cpp:160
friend class Dir
Definition dir.h:66
std::unique_ptr< Private > p
Definition dir.h:70
DirIterator & operator=(const DirIterator &it)
Definition dir.cpp:111
friend DirIterator begin(DirIterator it) noexcept
Definition dir.cpp:170
friend bool operator!=(const DirIterator &it1, const DirIterator &it2)
Definition dir.cpp:165
friend DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:175
value_type * pointer
Definition dir.h:48
Definition dir.cpp:29