lean cpp library
A lean C++ library providing efficient utility classes for high-performance C++ applications.
|
File class that allows for memory-mapped read/write access to a given file. More...
#include <mapped_file.h>
Public Member Functions | |
LEAN_MAYBE_EXPORT | mapped_file (const utf8_ntri &name, uint8 size=0, bool mapWhole=true, open_mode mode=file::open, uint4 hints=file::none, uint4 share=file::share_default) |
Opens the given file according to the given flags. Throws a runtime_exception on error. A size of 0 equals the current file size. | |
LEAN_MAYBE_EXPORT | ~mapped_file () |
Closes this file. | |
LEAN_MAYBE_EXPORT void * | map (uint8 offset=0, size_t size=0) |
(Re-)maps the file using the given parameters. Throws a runtime_exception on error. A size of 0 maps the entire file starting at the given offset. | |
LEAN_MAYBE_EXPORT void | unmap () |
Unmaps the file. | |
LEAN_MAYBE_EXPORT bool | flush () |
Flushes the file contents in the mapped range to disk, returing true on success. Ignored, if currently unmapped. | |
LEAN_MAYBE_EXPORT void | resize (uint8 newSize) |
Resizes the file, either extending or truncating it. Throws a runtime_exception on error. Unmaps the file, re-mapping is only possible again after this method has returned successfully. | |
LEAN_INLINE void * | data () |
Gets a pointer to the file in memory, nullptr if currently unmapped. | |
LEAN_INLINE const void * | data () const |
Gets a pointer to the file in memory, nullptr if currently unmapped. | |
LEAN_INLINE bool | mapped () const |
Gets whether the file is currently mapped. | |
Protected Member Functions | |
LEAN_MAYBE_EXPORT void * | map (bool readonly, uint8 offset, size_t size) |
Maps the given view of this file. A size of 0 maps the entire file starting at the given offset. Throws a runtime_exception on error. | |
LEAN_MAYBE_EXPORT void | unmap (void *memory) |
Unmaps the given view of this file. |
File class that allows for memory-mapped read/write access to a given file.