diff --git a/include/mio/mmap.hpp b/include/mio/mmap.hpp index cfd15de..286e117 100644 --- a/include/mio/mmap.hpp +++ b/include/mio/mmap.hpp @@ -108,7 +108,7 @@ public: * establishing the mapping is thrown. */ template - basic_mmap(const String& path, const size_type offset, const size_type length) + basic_mmap(const String& path, const size_type offset = 0, const size_type length = map_entire_file) { std::error_code error; map(path, offset, length, error); @@ -119,7 +119,7 @@ public: * The same as invoking the `map` function, except any error that may occur while * establishing the mapping is thrown. */ - basic_mmap(const handle_type handle, const size_type offset, const size_type length) + basic_mmap(const handle_type handle, const size_type offset = 0, const size_type length = map_entire_file) { std::error_code error; map(handle, offset, length, error); @@ -269,6 +269,24 @@ public: void map(const String& path, const size_type offset, const size_type length, std::error_code& error); + /** + * Establishes a memory mapping with AccessMode. If the mapping is unsuccesful, the + * reason is reported via `error` and the object remains in a state as if this + * function hadn't been called. + * + * `path`, which must be a path to an existing file, is used to retrieve a file + * handle (which is closed when the object destructs or `unmap` is called), which is + * then used to memory map the requested region. Upon failure, `error` is set to + * indicate the reason and the object remains in an unmapped state. + * + * The entire file is mapped. + */ + template + void map(const String& path, std::error_code& error) + { + map(path, 0, map_entire_file, error); + } + /** * Establishes a memory mapping with AccessMode. If the mapping is * unsuccesful, the reason is reported via `error` and the object remains in @@ -291,6 +309,22 @@ public: void map(const handle_type handle, const size_type offset, const size_type length, std::error_code& error); + /** + * Establishes a memory mapping with AccessMode. If the mapping is + * unsuccesful, the reason is reported via `error` and the object remains in + * a state as if this function hadn't been called. + * + * `handle`, which must be a valid file handle, which is used to memory map the + * requested region. Upon failure, `error` is set to indicate the reason and the + * object remains in an unmapped state. + * + * The entire file is mapped. + */ + void map(const handle_type handle, std::error_code& error) + { + map(handle, 0, map_entire_file, error); + } + /** * If a valid memory mapping has been created prior to this call, this call * instructs the kernel to unmap the memory region and disassociate this object diff --git a/include/mio/shared_mmap.hpp b/include/mio/shared_mmap.hpp index ba7e1e0..0ca5c14 100644 --- a/include/mio/shared_mmap.hpp +++ b/include/mio/shared_mmap.hpp @@ -92,7 +92,7 @@ public: * establishing the mapping is thrown. */ template - basic_shared_mmap(const String& path, const size_type offset, const size_type length) + basic_shared_mmap(const String& path, const size_type offset = 0, const size_type length = map_entire_file) { std::error_code error; map(path, offset, length, error); @@ -103,7 +103,7 @@ public: * The same as invoking the `map` function, except any error that may occur while * establishing the mapping is thrown. */ - basic_shared_mmap(const handle_type handle, const size_type offset, const size_type length) + basic_shared_mmap(const handle_type handle, const size_type offset = 0, const size_type length = map_entire_file) { std::error_code error; map(handle, offset, length, error); @@ -251,6 +251,24 @@ public: map_impl(path, offset, length, error); } + /** + * Establishes a memory mapping with AccessMode. If the mapping is unsuccesful, the + * reason is reported via `error` and the object remains in a state as if this + * function hadn't been called. + * + * `path`, which must be a path to an existing file, is used to retrieve a file + * handle (which is closed when the object destructs or `unmap` is called), which is + * then used to memory map the requested region. Upon failure, `error` is set to + * indicate the reason and the object remains in an unmapped state. + * + * The entire file is mapped. + */ + template + void map(const String& path, std::error_code& error) + { + map_impl(path, 0, map_entire_file, error); + } + /** * Establishes a memory mapping with AccessMode. If the mapping is unsuccesful, the * reason is reported via `error` and the object remains in a state as if this @@ -276,6 +294,22 @@ public: map_impl(handle, offset, length, error); } + /** + * Establishes a memory mapping with AccessMode. If the mapping is unsuccesful, the + * reason is reported via `error` and the object remains in a state as if this + * function hadn't been called. + * + * `handle`, which must be a valid file handle, which is used to memory map the + * requested region. Upon failure, `error` is set to indicate the reason and the + * object remains in an unmapped state. + * + * The entire file is mapped. + */ + void map(const handle_type handle, std::error_code& error) + { + map_impl(handle, 0, map_entire_file, error); + } + /** * If a valid memory mapping has been created prior to this call, this call * instructs the kernel to unmap the memory region and disassociate this object