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:
43  using difference_type = std::ptrdiff_t;
44  using pointer = value_type*;
46  using iterator_category = std::input_iterator_tag;
47  DirIterator(const DirIterator &it);
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 
67 /** Class representing a directory in the file system */
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
Dir::currentDirPath
static std::string currentDirPath()
Definition: dir.cpp:282
DirIterator::p
std::unique_ptr< Private > p
Definition: dir.h:63
Dir::copy
bool copy(const std::string &src, const std::string &dest, bool acceptsAbsPath=true) const
Definition: dir.cpp:272
fileinfo.h
Dir::Private
Definition: dir.cpp:137
DirIterator::Private
Definition: dir.cpp:60
Dir::filePath
std::string filePath(const std::string &path, bool acceptsAbsPath=true) const
Definition: dir.cpp:222
Dir::remove
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Definition: dir.cpp:256
Dir
Class representing a directory in the file system
Definition: dir.h:68
DirEntry::is_regular_file
bool is_regular_file() const
Definition: dir.cpp:43
DirEntry::p
std::unique_ptr< Private > p
Definition: dir.h:48
DirIterator::~DirIterator
~DirIterator()
Definition: dir.cpp:81
DirEntry
Definition: dir.h:24
DirEntry::Private
Definition: dir.cpp:25
DirEntry::path
std::string path() const
Definition: dir.cpp:53
DirEntry::DirEntry
DirEntry()
Definition: dir.cpp:30
DirIterator::operator->
const value_type * operator->() const
Definition: dir.cpp:107
DirIterator::begin
friend DirIterator begin(DirIterator it) noexcept
Definition: dir.cpp:123
DirIterator::iterator_category
std::input_iterator_tag iterator_category
Definition: dir.h:46
DirIterator::operator++
DirIterator operator++()
Definition: dir.cpp:94
DirIterator::operator!=
friend bool operator!=(const DirIterator &it1, const DirIterator &it2)
Definition: dir.cpp:118
Dir::isRelativePath
static bool isRelativePath(const std::string &path)
Definition: dir.cpp:217
DirIterator::operator==
friend bool operator==(const DirIterator &it1, const DirIterator &it2)
Definition: dir.cpp:113
Dir::rename
bool rename(const std::string &orgName, const std::string &newName, bool acceptsAbsPath=true) const
Definition: dir.cpp:263
Dir::path
std::string path() const
Definition: dir.cpp:176
Dir::~Dir
~Dir()
Definition: dir.cpp:167
Dir::absPath
std::string absPath() const
Definition: dir.cpp:305
DirIterator::operator*
const value_type & operator*() const
Definition: dir.cpp:101
DirEntry::~DirEntry
~DirEntry()
Definition: dir.cpp:34
Dir::Dir
Dir()
Definition: dir.cpp:142
Dir::setCurrent
static bool setCurrent(const std::string &path)
Definition: dir.cpp:290
DirIterator::operator=
DirIterator & operator=(const DirIterator &it)
Definition: dir.cpp:85
DirEntry::is_directory
bool is_directory() const
Definition: dir.cpp:38
DirIterator
Definition: dir.h:39
Dir::isEmpty
bool isEmpty(const std::string subdir) const
Definition: dir.cpp:205
Dir::operator=
Dir & operator=(const Dir &d)
Definition: dir.cpp:153
DirIterator::difference_type
std::ptrdiff_t difference_type
Definition: dir.h:43
DirEntry::is_symlink
bool is_symlink() const
Definition: dir.cpp:48
Dir::isRelative
bool isRelative() const
Definition: dir.cpp:212
Dir::setPath
void setPath(const std::string &path)
Definition: dir.cpp:171
Dir::exists
bool exists() const
Definition: dir.cpp:199
Dir::iterator
DirIterator iterator() const
Definition: dir.cpp:181
Dir::rmdir
bool rmdir(const std::string &path, bool acceptsAbsPath=true) const
Definition: dir.cpp:251
DirIterator::end
friend DirIterator end(const DirIterator &) noexcept
Definition: dir.cpp:128
DirIterator::DirIterator
DirIterator()
Definition: dir.cpp:68
DirIterator::value_type
DirEntry value_type
Definition: dir.h:42
Dir::mkdir
bool mkdir(const std::string &path, bool acceptsAbsPath=true) const
Definition: dir.cpp:237
Dir::cleanDirPath
static std::string cleanDirPath(const std::string &path)
Definition: dir.cpp:297
Dir::p
std::unique_ptr< Private > p
Definition: dir.h:101