doxygen
dir.h
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 
24 class DirEntry
25 {
26  public:
27  ~DirEntry();
28  DirEntry(const DirEntry &);
29  DirEntry &operator=(const DirEntry &);
30  DirEntry(DirEntry &&);
31  DirEntry &operator=(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:
46  using value_type = DirEntry;
47  using difference_type = std::ptrdiff_t;
48  using pointer = value_type*;
49  using reference = value_type&;
50  using iterator_category = std::input_iterator_tag;
51  DirIterator(const DirIterator &it);
52  DirIterator &operator=(const DirIterator &it);
54  DirIterator &operator=(DirIterator &&it);
55  DirIterator operator++();
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;
63  ~DirIterator();
64 
65  private:
66  friend class Dir;
67  DirIterator();
68  DirIterator(const std::string &path);
69  struct Private;
70  std::unique_ptr<Private> p;
71 };
72 
74 class 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.cpp:87
Definition: dir.h:24
Definition: dir.cpp:184
Class representing a directory in the file system.
Definition: dir.h:74
Definition: dir.cpp:28
Definition: dir.h:43