Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
lnx/FileMapper.h
Go to the documentation of this file.
1#pragma once
2#include <cstddef>
4#include <misc/global.h>
5#include <misc/lnx/File.h>
6
7namespace sf::lnx
8{
9
14{
15 public:
20
24 explicit FileMapper(const std::string& filepath, size_t ofs = 0, size_t sz = 0);
25
29 void initialize() override;
30
34 ~FileMapper() override;
35
39 void initialize(const std::string& filepath, size_t ofs = 0, size_t sz = 0);
40
44 void createView(size_t size) override;
45
49 void setView(size_t ofs, size_t sz);
50
54 void reset();
55
59 void* getPtr() override;
60
67 template<typename T>
68 T* lock(bool readonly = false)
69 {
70 return static_cast<T*>(doLock(readonly));
71 }
72
76 void unlock(bool sync = false);
77
78 bool mapView() override;
79
80 bool unmapView() override;
81
86 const File& getFile()
87 {
88 return _file;
89 }
90
94 [[nodiscard]] bool isLocked() const;
95
101 void sync(bool async);
102
106 [[nodiscard]] size_t getSize() const;
107
108 private:
113 void* doLock(bool readonly);
114
118 bool _temp{false};
122 File _file{};
126 char* _ptr{nullptr};
130 int _counter{0};
134 size_t _size{0};
138 size_t _offset{0};
142 size_t _realOffset{0};
143};
144
145}// namespace sf::lnx
class for file mapping
Definition IFileMapper.h:12
Wrapper for the linux mmap.
Definition lnx/FileMapper.h:14
~FileMapper() override
Destructor.
void initialize() override
Use temporary files to map.
void setView(size_t ofs, size_t sz)
Sets the part of the file to be mapped.
size_t getSize() const
void initialize(const std::string &filepath, size_t ofs=0, size_t sz=0)
Initializes the mapper passing a file instance.
void * getPtr() override
Gets the pointer of the mapped area.
FileMapper(const std::string &filepath, size_t ofs=0, size_t sz=0)
Initializing constructor.
FileMapper()
Default constructor.
bool unmapView() override
Unlocks the pointer locked with mapView().
void createView(size_t size) override
Sets the size of the file to be mapped.
void unlock(bool sync=false)
void reset()
Unlocks the locked file and removes the file reference.
void sync(bool async)
bool isLocked() const
bool mapView() override
Locks a pointer in memory which can be unlocked using unmapView().
T * lock(bool readonly=false)
Locks the set area.
Definition lnx/FileMapper.h:68
const File & getFile()
Definition lnx/FileMapper.h:86
Definition File.h:15
#define _MISC_CLASS
Definition misc/global.h:40
Definition File.h:9