1 #pragma once 2 3 #ifndef MMAP_H_ 4 #define MMAP_H_ 5 6 #include <cstddef> 7 #include <memory> 8 9 class MemoryMappedFile { 10 class impl; 11 12 struct read_tag {}; 13 struct write_tag {}; 14 struct create_tag {}; 15 public: 16 static const read_tag READ_TAG; 17 static const write_tag WRITE_TAG; 18 static const create_tag CREATE_TAG; 19 private: 20 std::unique_ptr<impl> m_impl; 21 get_impl()22 impl *get_impl() { return m_impl.get(); } get_impl()23 const impl *get_impl() const { return m_impl.get(); } 24 public: 25 MemoryMappedFile() noexcept; 26 27 MemoryMappedFile(MemoryMappedFile &&other) noexcept; 28 29 MemoryMappedFile(const char *path, read_tag); 30 31 MemoryMappedFile(const char *path, write_tag); 32 33 MemoryMappedFile(const char *path, size_t size, create_tag); 34 35 ~MemoryMappedFile(); 36 37 MemoryMappedFile &operator=(MemoryMappedFile &&other) noexcept; 38 39 size_t size() const noexcept; 40 41 const void *read_ptr() const noexcept; 42 43 void *write_ptr() noexcept; 44 45 void flush(); 46 47 void close(); 48 }; 49 50 #endif // MMAP_H_ 51