Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 09:07:24

0001 // Copyright (C) 2020 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QDIR_H
0005 #define QDIR_H
0006 
0007 #include <QtCore/qcompare.h>
0008 #include <QtCore/qstring.h>
0009 #include <QtCore/qdirlisting.h>
0010 #include <QtCore/qfile.h>
0011 #include <QtCore/qfileinfo.h>
0012 #include <QtCore/qstringlist.h>
0013 #include <QtCore/qshareddata.h>
0014 
0015 QT_BEGIN_NAMESPACE
0016 
0017 class QDirIterator;
0018 class QDirPrivate;
0019 
0020 class Q_CORE_EXPORT QDir
0021 {
0022 public:
0023     enum Filter { Dirs        = 0x001,
0024                   Files       = 0x002,
0025                   Drives      = 0x004,
0026                   NoSymLinks  = 0x008,
0027                   AllEntries  = Dirs | Files | Drives,
0028                   TypeMask    = 0x00f,
0029 
0030                   Readable    = 0x010,
0031                   Writable    = 0x020,
0032                   Executable  = 0x040,
0033                   PermissionMask    = 0x070,
0034 
0035                   Modified    = 0x080,
0036                   Hidden      = 0x100,
0037                   System      = 0x200,
0038 
0039                   AccessMask  = 0x3F0,
0040 
0041                   AllDirs       = 0x400,
0042                   CaseSensitive = 0x800,
0043                   NoDot         = 0x2000,
0044                   NoDotDot      = 0x4000,
0045                   NoDotAndDotDot = NoDot | NoDotDot,
0046 
0047                   NoFilter = -1
0048     };
0049     Q_DECLARE_FLAGS(Filters, Filter)
0050 
0051     enum SortFlag { Name        = 0x00,
0052                     Time        = 0x01,
0053                     Size        = 0x02,
0054                     Unsorted    = 0x03,
0055                     SortByMask  = 0x03,
0056 
0057                     DirsFirst   = 0x04,
0058                     Reversed    = 0x08,
0059                     IgnoreCase  = 0x10,
0060                     DirsLast    = 0x20,
0061                     LocaleAware = 0x40,
0062                     Type        = 0x80,
0063                     NoSort = -1
0064     };
0065     Q_DECLARE_FLAGS(SortFlags, SortFlag)
0066 
0067     QDir(const QDir &);
0068     QDir(const QString &path = QString());
0069     QDir(const QString &path, const QString &nameFilter,
0070          SortFlags sort = SortFlags(Name | IgnoreCase), Filters filter = AllEntries);
0071 #ifdef Q_QDOC
0072     QDir(const std::filesystem::path &path);
0073     QDir(const std::filesystem::path &path, const QString &nameFilter,
0074          SortFlags sort = SortFlags(Name | IgnoreCase), Filters filter = AllEntries);
0075 #elif QT_CONFIG(cxx17_filesystem)
0076     template<typename T, QtPrivate::ForceFilesystemPath<T> = 0>
0077     QDir(const T &path) : QDir(QtPrivate::fromFilesystemPath(path))
0078     {
0079     }
0080     template<typename T, QtPrivate::ForceFilesystemPath<T> = 0>
0081     QDir(const T &path, const QString &nameFilter,
0082          SortFlags sort = SortFlags(Name | IgnoreCase), Filters filter = AllEntries)
0083          : QDir(QtPrivate::fromFilesystemPath(path), nameFilter, sort, filter)
0084     {
0085     }
0086 #endif // QT_CONFIG(cxx17_filesystem)
0087     ~QDir();
0088 
0089     QDir &operator=(const QDir &);
0090     QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QDir)
0091 
0092     void swap(QDir &other) noexcept
0093     { d_ptr.swap(other.d_ptr); }
0094 
0095     void setPath(const QString &path);
0096 #ifdef Q_QDOC
0097     void setPath(const std::filesystem::path &path);
0098 #elif QT_CONFIG(cxx17_filesystem)
0099     template<typename T, QtPrivate::ForceFilesystemPath<T> = 0>
0100     void setPath(const T &path)
0101     {
0102         setPath(QtPrivate::fromFilesystemPath(path));
0103     }
0104 #endif // QT_CONFIG(cxx17_filesystem)
0105     QString path() const;
0106     QString absolutePath() const;
0107     QString canonicalPath() const;
0108 #if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
0109     std::filesystem::path filesystemPath() const
0110     { return QtPrivate::toFilesystemPath(path()); }
0111     std::filesystem::path filesystemAbsolutePath() const
0112     { return QtPrivate::toFilesystemPath(absolutePath()); }
0113     std::filesystem::path filesystemCanonicalPath() const
0114     { return QtPrivate::toFilesystemPath(canonicalPath()); }
0115 #endif // QT_CONFIG(cxx17_filesystem)
0116 
0117 #ifndef QT_BOOTSTRAPPED
0118     static void setSearchPaths(const QString &prefix, const QStringList &searchPaths);
0119     static void addSearchPath(const QString &prefix, const QString &path);
0120 #ifdef Q_QDOC
0121     static void addSearchPath(const QString &prefix, const std::filesystem::path &path);
0122 #elif QT_CONFIG(cxx17_filesystem)
0123     template<typename T, QtPrivate::ForceFilesystemPath<T> = 0>
0124     static void addSearchPath(const QString &prefix, const T &path)
0125     {
0126         addSearchPath(prefix, QtPrivate::fromFilesystemPath(path));
0127     }
0128 #endif // QT_CONFIG(cxx17_filesystem)
0129     static QStringList searchPaths(const QString &prefix);
0130 #endif // QT_BOOTSTRAPPED
0131 
0132     QString dirName() const;
0133     QString filePath(const QString &fileName) const;
0134     QString absoluteFilePath(const QString &fileName) const;
0135     QString relativeFilePath(const QString &fileName) const;
0136 
0137     static QString toNativeSeparators(const QString &pathName);
0138     static QString fromNativeSeparators(const QString &pathName);
0139 
0140     bool cd(const QString &dirName);
0141     bool cdUp();
0142 
0143     QStringList nameFilters() const;
0144     void setNameFilters(const QStringList &nameFilters);
0145 
0146     Filters filter() const;
0147     void setFilter(Filters filter);
0148     SortFlags sorting() const;
0149     void setSorting(SortFlags sort);
0150 
0151 #if QT_CORE_REMOVED_SINCE(6, 5)
0152     uint count() const;
0153 #endif
0154     qsizetype count(QT6_DECL_NEW_OVERLOAD) const;
0155     bool isEmpty(Filters filters = Filters(AllEntries | NoDotAndDotDot)) const;
0156 
0157 #if QT_CORE_REMOVED_SINCE(6, 5) && QT_POINTER_SIZE != 4
0158     QString operator[](int) const;
0159 #endif
0160     QString operator[](qsizetype) const;
0161 
0162     static QStringList nameFiltersFromString(const QString &nameFilter);
0163 
0164     QStringList entryList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
0165     QStringList entryList(const QStringList &nameFilters, Filters filters = NoFilter,
0166                           SortFlags sort = NoSort) const;
0167 
0168     QFileInfoList entryInfoList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
0169     QFileInfoList entryInfoList(const QStringList &nameFilters, Filters filters = NoFilter,
0170                                 SortFlags sort = NoSort) const;
0171 
0172     bool mkdir(const QString &dirName) const;
0173     bool mkdir(const QString &dirName, QFile::Permissions permissions) const;
0174     bool rmdir(const QString &dirName) const;
0175     bool mkpath(const QString &dirPath) const;
0176     bool rmpath(const QString &dirPath) const;
0177 
0178     bool removeRecursively();
0179 
0180     bool isReadable() const;
0181     bool exists() const;
0182     bool isRoot() const;
0183 
0184     static bool isRelativePath(const QString &path);
0185     inline static bool isAbsolutePath(const QString &path) { return !isRelativePath(path); }
0186     bool isRelative() const;
0187     inline bool isAbsolute() const { return !isRelative(); }
0188     bool makeAbsolute();
0189 
0190 #if QT_CORE_REMOVED_SINCE(6, 8)
0191     bool operator==(const QDir &dir) const;
0192     inline bool operator!=(const QDir &dir) const { return !operator==(dir); }
0193 #endif
0194 
0195     bool remove(const QString &fileName);
0196     bool rename(const QString &oldName, const QString &newName);
0197     bool exists(const QString &name) const;
0198 
0199     static QFileInfoList drives();
0200 
0201     constexpr static inline QChar listSeparator() noexcept
0202     {
0203 #if defined(Q_OS_WIN)
0204         return u';';
0205 #else
0206         return u':';
0207 #endif
0208     }
0209 
0210     static QChar separator()
0211     {
0212 #if defined(Q_OS_WIN)
0213         return u'\\';
0214 #else
0215         return u'/';
0216 #endif
0217     }
0218 
0219     static bool setCurrent(const QString &path);
0220     static inline QDir current() { return QDir(currentPath()); }
0221     static QString currentPath();
0222 
0223     static inline QDir home() { return QDir(homePath()); }
0224     static QString homePath();
0225     static inline QDir root() { return QDir(rootPath()); }
0226     static QString rootPath();
0227     static inline QDir temp() { return QDir(tempPath()); }
0228     static QString tempPath();
0229 
0230 #if QT_CONFIG(regularexpression)
0231     static bool match(const QStringList &filters, const QString &fileName);
0232     static bool match(const QString &filter, const QString &fileName);
0233 #endif
0234 
0235     static QString cleanPath(const QString &path);
0236     void refresh() const;
0237 
0238 protected:
0239     explicit QDir(QDirPrivate &d);
0240 
0241     QSharedDataPointer<QDirPrivate> d_ptr;
0242 
0243 private:
0244     friend Q_CORE_EXPORT bool comparesEqual(const QDir &lhs, const QDir &rhs);
0245     Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QDir)
0246     friend class QDirIterator;
0247     friend class QDirListing;
0248     friend class QDirListingPrivate;
0249     // Q_DECLARE_PRIVATE equivalent for shared data pointers
0250     QDirPrivate *d_func();
0251     const QDirPrivate *d_func() const { return d_ptr.constData(); }
0252 };
0253 
0254 Q_DECLARE_SHARED(QDir)
0255 Q_DECLARE_OPERATORS_FOR_FLAGS(QDir::Filters)
0256 Q_DECLARE_OPERATORS_FOR_FLAGS(QDir::SortFlags)
0257 
0258 #ifndef QT_NO_DEBUG_STREAM
0259 class QDebug;
0260 Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters);
0261 Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QDir &dir);
0262 #endif
0263 
0264 QT_END_NAMESPACE
0265 
0266 #endif // QDIR_H