-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfile.cpp
More file actions
66 lines (54 loc) · 1.27 KB
/
Copy pathfile.cpp
File metadata and controls
66 lines (54 loc) · 1.27 KB
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
60
61
62
63
64
65
66
#include "common/file.h"
//#include "common/private/file_p.h"
namespace shelllet {
namespace common {
class FilePrivate : public ObjectPrivate {
Q_DECLARE_PUBLIC(File)
public:
std::unique_ptr<QFile> file;
};
}
}
shelllet::common::String shelllet::common::File::readAllAsText(const Path& path)
{
std::ifstream stream(path.toStdPath());
BOOST_ASSERT_MSG(path.isExist(), "file not exist");
return stream;
}
shelllet::common::File& shelllet::common::File::operator<<(const String& str)
{
return *this;
}
void shelllet::common::File::write(const String& data)
{
Q_D(File);
if (!d->file->isOpen()) {
BOOST_VERIFY_MSG(d->file->open(QIODevice::WriteOnly), "Open file failed.");
}
d->file->write(data.toUtf8());
}
void shelllet::common::File::copy(const Path& src, const Path& target)
{
std::filesystem::copy_file(src, target);
}
shelllet::common::File::File(const Path& path)
: File(*new FilePrivate)
{
Q_D(File);
d->file->setFileName(*path.toString().toQString());
}
shelllet::common::File::File(const String& name)
: File(*new FilePrivate)
{
Q_D(File);
d->file->setFileName(*name.toQString());
}
shelllet::common::File::File()
: File(*new FilePrivate)
{
}
shelllet::common::File::File(FilePrivate& d)
: Object(d, nullptr)
{
d.file = std::make_unique<QFile>();
}