mirror of
https://github.com/vimpunk/mio.git
synced 2026-02-16 23:29:55 +08:00
Add entire file mapping overload to factory methods
This commit is contained in:
parent
99db68866c
commit
2e048e5a25
@ -35,6 +35,10 @@ mio::mmap_source mmap(path);
|
|||||||
std::error_code error;
|
std::error_code error;
|
||||||
mio::mmap_source mmap = mio::make_mmap_source(path, offset, size_to_map, 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:
|
- Using the `map` member function:
|
||||||
```c++
|
```c++
|
||||||
|
|||||||
@ -423,7 +423,10 @@ using ummap_source = basic_mmap_source<unsigned char>;
|
|||||||
using mmap_sink = basic_mmap_sink<char>;
|
using mmap_sink = basic_mmap_sink<char>;
|
||||||
using ummap_sink = basic_mmap_sink<unsigned 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<
|
template<
|
||||||
typename MMap,
|
typename MMap,
|
||||||
typename MappingToken
|
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);
|
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.
|
* 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);
|
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
|
} // namespace mio
|
||||||
|
|
||||||
#include "detail/mmap.ipp"
|
#include "detail/mmap.ipp"
|
||||||
|
|||||||
@ -104,6 +104,8 @@ int main()
|
|||||||
// Make sure shared_mmap mapping compiles as all testing was done on
|
// Make sure shared_mmap mapping compiles as all testing was done on
|
||||||
// normal mmaps.
|
// normal mmaps.
|
||||||
mio::shared_mmap_source _3(path, 0, mio::map_entire_file);
|
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");
|
std::printf("all tests passed!\n");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user