summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qtemporarydir.h
blob: 1fdaa83fb0a849c8c02266af1a5d3aee698baa3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QTEMPORARYDIR_H
#define QTEMPORARYDIR_H

#include <QtCore/qglobal.h>
#include <QtCore/qdir.h>
#include <QtCore/qscopedpointer.h>

QT_BEGIN_NAMESPACE


#ifndef QT_NO_TEMPORARYFILE

class QTemporaryDirPrivate;

class Q_CORE_EXPORT QTemporaryDir
{
public:
    QTemporaryDir();
    explicit QTemporaryDir(const QString &templateName);
    QTemporaryDir(QTemporaryDir &&other) noexcept
        : d_ptr{std::exchange(other.d_ptr, nullptr)}
    { }

    QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QTemporaryDir)

    ~QTemporaryDir();

    void swap(QTemporaryDir &other) noexcept
    { qt_ptr_swap(d_ptr, other.d_ptr); }

    bool isValid() const;
    QString errorString() const;

    bool autoRemove() const;
    void setAutoRemove(bool b);
    bool remove();

    QString path() const;
    QString filePath(const QString &fileName) const;

private:
    QTemporaryDirPrivate *d_ptr;

    Q_DISABLE_COPY(QTemporaryDir)
};

inline void swap(QTemporaryDir &lhs, QTemporaryDir &rhs) noexcept
{
    lhs.swap(rhs);
}

#endif // QT_NO_TEMPORARYFILE

QT_END_NAMESPACE

#endif // QTEMPORARYDIR_H