LibrePCB Developers Documentation
Loading...
Searching...
No Matches
transactionaldirectory.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_CORE_TRANSACTIONALDIRECTORY_H
21#define LIBREPCB_CORE_TRANSACTIONALDIRECTORY_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "filesystem.h"
27
28#include <QtCore>
29
30#include <memory>
31
32/*******************************************************************************
33 * Namespace / Forward Declarations
34 ******************************************************************************/
35namespace librepcb {
36
37class TransactionalFileSystem;
38
39/*******************************************************************************
40 * Class TransactionalDirectory
41 ******************************************************************************/
42
51class TransactionalDirectory final : public FileSystem {
52 Q_OBJECT
53
54public:
55 // Constructors / Destructor
56 TransactionalDirectory(QObject* parent = nullptr);
57 explicit TransactionalDirectory(std::shared_ptr<TransactionalFileSystem> fs,
58 const QString& dir = "",
59 QObject* parent = nullptr) noexcept;
60 // Note: The "other" parameter must not be a const reference because of
61 // const correctness reasons! A const TransactionalDirectory must
62 // not be convertible to a non-const TransactionalDirectory because
63 // it would allow writing to a file system which should actually be
64 // const.
66 const QString& subdir = "",
67 QObject* parent = nullptr) noexcept;
68 virtual ~TransactionalDirectory() noexcept;
69
70 // Getters
71 std::shared_ptr<const TransactionalFileSystem> getFileSystem()
72 const noexcept {
73 return mFileSystem;
74 }
75 std::shared_ptr<TransactionalFileSystem> getFileSystem() noexcept {
76 return mFileSystem;
77 }
78 const QString& getPath() const noexcept { return mPath; }
79 bool isWritable() const noexcept;
80 bool isRestoredFromAutosave() const noexcept;
81
82 // Inherited from FileSystem
83 virtual FilePath getAbsPath(const QString& path = "") const noexcept override;
84 virtual QStringList getDirs(const QString& path = "") const noexcept override;
85 virtual QStringList getFiles(
86 const QString& path = "") const noexcept override;
87 virtual bool fileExists(const QString& path) const noexcept override;
88 virtual QByteArray read(const QString& path) const override;
89 virtual QByteArray readIfExists(const QString& path) const override;
90 virtual void write(const QString& path, const QByteArray& content) override;
91 virtual void renameFile(const QString& src, const QString& dst) override;
92 virtual void removeFile(const QString& path) override;
93 virtual void removeDirRecursively(const QString& path = "") override;
94
95 // General Methods
96 void copyTo(TransactionalDirectory& dest) const;
99
100private: // Methods
102 const QString& srcDir,
104 const QString& dstDir);
105
106private: // Data
108 QString mPath;
109};
110
111/*******************************************************************************
112 * End of File
113 ******************************************************************************/
114
115} // namespace librepcb
116
117#endif
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
Base class / interface for all file system implementations.
Definition filesystem.h:45
Helper class to access a subdirectory of TransactionalFileSystem.
Definition transactionaldirectory.h:51
std::shared_ptr< TransactionalFileSystem > getFileSystem() noexcept
Definition transactionaldirectory.h:75
virtual void removeDirRecursively(const QString &path="") override
Definition transactionaldirectory.cpp:120
const QString & getPath() const noexcept
Definition transactionaldirectory.h:78
virtual bool fileExists(const QString &path) const noexcept override
Definition transactionaldirectory.cpp:94
virtual QStringList getFiles(const QString &path="") const noexcept override
Definition transactionaldirectory.cpp:89
virtual void renameFile(const QString &src, const QString &dst) override
Definition transactionaldirectory.cpp:111
virtual void write(const QString &path, const QByteArray &content) override
Definition transactionaldirectory.cpp:106
void saveTo(TransactionalDirectory &dest)
Definition transactionaldirectory.cpp:136
virtual QStringList getDirs(const QString &path="") const noexcept override
Definition transactionaldirectory.cpp:84
QString mPath
Definition transactionaldirectory.h:108
bool isRestoredFromAutosave() const noexcept
Definition transactionaldirectory.cpp:71
virtual void removeFile(const QString &path) override
Definition transactionaldirectory.cpp:116
virtual QByteArray read(const QString &path) const override
Definition transactionaldirectory.cpp:98
void copyTo(TransactionalDirectory &dest) const
Definition transactionaldirectory.cpp:128
std::shared_ptr< TransactionalFileSystem > mFileSystem
Definition transactionaldirectory.h:107
std::shared_ptr< const TransactionalFileSystem > getFileSystem() const noexcept
Definition transactionaldirectory.h:71
virtual ~TransactionalDirectory() noexcept
Definition transactionaldirectory.cpp:60
bool isWritable() const noexcept
Definition transactionaldirectory.cpp:67
void moveTo(TransactionalDirectory &dest)
Definition transactionaldirectory.cpp:145
static void copyDirRecursively(TransactionalFileSystem &srcFs, const QString &srcDir, TransactionalFileSystem &dstFs, const QString &dstDir)
Definition transactionaldirectory.cpp:161
virtual QByteArray readIfExists(const QString &path) const override
Definition transactionaldirectory.cpp:102
virtual FilePath getAbsPath(const QString &path="") const noexcept override
Definition transactionaldirectory.cpp:79
Transactional librepcb::FileSystem implementation.
Definition transactionalfilesystem.h:71
Definition occmodel.cpp:76
Definition uuid.h:186