Add entire file mapping overload to factory methods

This commit is contained in:
mandreyel 2018-10-25 09:22:46 +02:00
parent 99db68866c
commit 2e048e5a25
3 changed files with 22 additions and 1 deletions

View File

@ -35,6 +35,10 @@ mio::mmap_source mmap(path);
std::error_code error;
mio::mmap_source mmap = mio::make_mmap_source(path, offset, size_to_map, error);
```
or:
```c++
mio::mmap_source mmap = mio::make_mmap_source(path, error);
```
- Using the `map` member function:
```c++

View File

@ -423,7 +423,10 @@ using ummap_source = basic_mmap_source<unsigned char>;
using mmap_sink = basic_mmap_sink<char>;
using ummap_sink = basic_mmap_sink<unsigned char>;
/** Convenience factory method that constructs a mapping for any `basic_mmap` type. */
/**
* Convenience factory method that constructs a mapping for any `basic_mmap` or
* `basic_mmap` type.
*/
template<
typename MMap,
typename MappingToken
@ -449,6 +452,12 @@ mmap_source make_mmap_source(const MappingToken& token, mmap_source::size_type o
return make_mmap<mmap_source>(token, offset, length, error);
}
template<typename MappingToken>
mmap_source make_mmap_source(const MappingToken& token, std::error_code& error)
{
return make_mmap_source(token, 0, map_entire_file, error);
}
/**
* Convenience factory method.
*
@ -463,6 +472,12 @@ mmap_sink make_mmap_sink(const MappingToken& token, mmap_sink::size_type offset,
return make_mmap<mmap_sink>(token, offset, length, error);
}
template<typename MappingToken>
mmap_sink make_mmap_sink(const MappingToken& token, std::error_code& error)
{
return make_mmap_sink(token, 0, map_entire_file, error);
}
} // namespace mio
#include "detail/mmap.ipp"

View File

@ -104,6 +104,8 @@ int main()
// Make sure shared_mmap mapping compiles as all testing was done on
// normal mmaps.
mio::shared_mmap_source _3(path, 0, mio::map_entire_file);
auto _4 = mio::make_mmap_source(path, error);
auto _5 = mio::make_mmap<mio::shared_mmap_source>(path, 0, mio::map_entire_file, error);
}
std::printf("all tests passed!\n");