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  bool is_directory() const;
29  bool is_regular_file() const;
30  bool is_symlink() const;
31  std::string path() const;
32  private:
33  friend class DirIterator;
34  DirEntry();
35  struct Private;
36  std::unique_ptr<Private> p;
37 };
38 
40 {
41  public:
42  using value_type = DirEntry;
43  using difference_type = std::ptrdiff_t;
44  using pointer = value_type*;
45  using reference = value_type&;
46  using iterator_category = std::input_iterator_tag;
47  DirIterator(const DirIterator &it);
48  DirIterator &operator=(const DirIterator &it);
49  DirIterator operator++();
50  const value_type &operator*() const;
51  const value_type *operator->() const;
52 
53  friend bool operator==(const DirIterator &it1,const DirIterator &it2);
54  friend bool operator!=(const DirIterator &it1,const DirIterator &it2);
55  friend DirIterator begin(DirIterator it) noexcept;
56  friend DirIterator end(const DirIterator &) noexcept;
57  ~DirIterator();
58 
59  private:
60  friend class Dir;
61  DirIterator();
62  DirIterator(const std::string &path);
63  struct Private;
64  std::unique_ptr<Private> p;
65 };
66 
68 class Dir final
69 {
70  public:
71  Dir();
72  Dir(const std::string &path);
73  Dir(const Dir &d);
74  Dir &operator=(const Dir &d);
75  ~Dir();
76  void setPath(const std::string &path);
77  std::string path() const;
78 
79  DirIterator iterator() const;
80 
81  bool isEmpty(const std::string subdir) const;
82  bool exists() const;
83  std::string filePath(const std::string &path,bool acceptsAbsPath=true) const;
84  bool exists(const std::string &path,bool acceptsAbsPath=true) const;
85  bool mkdir(const std::string &path,bool acceptsAbsPath=true) const;
86  bool rmdir(const std::string &path,bool acceptsAbsPath=true) const;
87  bool remove(const std::string &path,bool acceptsAbsPath=true) const;
88  bool rename(const std::string &orgName,const std::string &newName,
89  bool acceptsAbsPath=true) const;
90  bool copy(const std::string &src,const std::string &dest,bool acceptsAbsPath=true) const;
91  std::string absPath() const;
92 
93  bool isRelative() const;
94 
95  static bool isRelativePath(const std::string &path);
96  static std::string currentDirPath();
97  static bool setCurrent(const std::string &path);
98  static std::string cleanDirPath(const std::string &path);
99 
100  private:
101  struct Private;
102  std::unique_ptr<Private> p;
103 };
104 
105 #endif
Definition: dir.cpp:60
Definition: dir.h:24
Definition: dir.cpp:137
Class representing a directory in the file system.
Definition: dir.h:68
Definition: dir.cpp:25
Definition: dir.h:39