FileManager v1.7.0
Manage access to files with async model
Loading...
Searching...
No Matches
FileHandle.cpp
1#include "FileHandle.h"
2
3#include "FileManager.h"
4
5using namespace std;
6
7namespace file_manager
8{
9 FileHandle::FileHandle(const filesystem::path& filePath, ios_base::openmode mode) :
10 filePath(filePath),
11 file(filePath, mode),
12 mode(mode),
13 isNotifyOnDestruction(true)
14 {
15
16 }
17
18 FileHandle::FileHandle(FileHandle&& other) noexcept
19 {
20 (*this) = move(other);
21 }
22
23 FileHandle& FileHandle::operator = (FileHandle&& other) noexcept
24 {
25 filePath = move(other.filePath);
26 file = move(other.file);
27 mode = other.mode;
28
29 isNotifyOnDestruction = other.isNotifyOnDestruction;
30
31 other.isNotifyOnDestruction = !other.isNotifyOnDestruction;
32
33 return *this;
34 }
35
36 uint64_t FileHandle::getFileSize() const
37 {
38 return filesystem::file_size(filePath);
39 }
40
41 const filesystem::path& FileHandle::getPathToFile() const
42 {
43 return filePath;
44 }
45
46 filesystem::path FileHandle::getFileName() const
47 {
48 return filePath.filename();
49 }
50
51 FileHandle::~FileHandle()
52 {
53 if (isNotifyOnDestruction)
54 {
55 file.close();
56
57 FileManager::getInstance().notify(move(filePath));
58 }
59 }
60}