Update code style in README and test.cpp

This commit is contained in:
mandreyel 2018-09-07 15:59:45 +02:00
parent 11f22060b1
commit a53f63b58b
5 changed files with 16 additions and 21 deletions

View File

@ -75,7 +75,7 @@ int main()
// length of the mapping is otherwise expected, with the factory method.
std::error_code error;
mio::mmap_sink rw_mmap = mio::make_mmap_sink(
"file.txt", 0, mio::map_entire_file, error);
"file.txt", 0, mio::map_entire_file, error);
if (error) { return handle_error(error); }
// You can use any iterator based function.
@ -103,7 +103,7 @@ int main()
// Now create the same mapping, but in read-only mode.
mio::mmap_source ro_mmap = mio::make_mmap_source(
"file.txt", 0, mio::map_entire_file, error);
"file.txt", 0, mio::map_entire_file, error);
if (error) { return handle_error(error); }
const int the_answer_to_everything = ro_mmap[answer_index];

View File

@ -348,7 +348,6 @@ void basic_mmap<ByteT>::unmap()
{
::UnmapViewOfFile(get_mapping_start());
::CloseHandle(file_mapping_handle_);
file_mapping_handle_ = INVALID_HANDLE_VALUE;
}
#else
if(data_) { ::munmap(const_cast<pointer>(get_mapping_start()), mapped_length_); }

View File

@ -301,14 +301,14 @@ public:
/**
* This is the basis for all read-only mmap objects and should be preferred over
* directly using basic_mmap.
* directly using `basic_mmap`.
*/
template<typename ByteT>
using basic_mmap_source = basic_mmap<access_mode::read, ByteT>;
/**
* This is the basis for all read-write mmap objects and should be preferred over
* directly using basic_mmap.
* directly using `basic_mmap`.
*/
template<typename ByteT>
using basic_mmap_sink = basic_mmap<access_mode::write, ByteT>;
@ -323,7 +323,7 @@ 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` type. */
template<
typename MMap,
typename MappingToken
@ -340,7 +340,7 @@ template<
*
* MappingToken may be a String (`std::string`, `std::string_view`, `const char*`,
* `std::filesystem::path`, `std::vector<char>`, or similar), or a
* mmap_source::file_handle.
* `mmap_source::handle_type`.
*/
template<typename MappingToken>
mmap_source make_mmap_source(const MappingToken& token, mmap_source::size_type offset,
@ -354,7 +354,7 @@ mmap_source make_mmap_source(const MappingToken& token, mmap_source::size_type o
*
* MappingToken may be a String (`std::string`, `std::string_view`, `const char*`,
* `std::filesystem::path`, `std::vector<char>`, or similar), or a
* mmap_sink::file_handle.
* `mmap_sink::handle_type`.
*/
template<typename MappingToken>
mmap_sink make_mmap_sink(const MappingToken& token, mmap_sink::size_type offset,

View File

@ -17,7 +17,7 @@ int main()
// length of the mapping is otherwise expected, with the factory method.
std::error_code error;
mio::mmap_sink rw_mmap = mio::make_mmap_sink(
"file.txt", 0, mio::map_entire_file, error);
"file.txt", 0, mio::map_entire_file, error);
if (error) { return handle_error(error); }
// You can use any iterator based function.
@ -45,7 +45,7 @@ int main()
// Now create the same mapping, but in read-only mode.
mio::mmap_source ro_mmap = mio::make_mmap_source(
"file.txt", 0, mio::map_entire_file, error);
"file.txt", 0, mio::map_entire_file, error);
if (error) { return handle_error(error); }
const int the_answer_to_everything = ro_mmap[answer_index];

View File

@ -33,19 +33,17 @@ int main()
{
// Map the region of the file to which buffer was written.
mio::mmap_source file_view = mio::make_mmap_source(
path, 0, mio::map_entire_file, error);
path, 0, mio::map_entire_file, error);
if(error) { return handle_error(error); }
assert(file_view.is_open());
assert(file_view.size() == buffer.size());
// Then verify that mmap's bytes correspond to that of buffer.
for(auto i = 0; i < buffer.size(); ++i)
{
if(file_view[i] != buffer[i])
{
for(auto i = 0; i < buffer.size(); ++i) {
if(file_view[i] != buffer[i]) {
std::printf("%ith byte mismatch: expected(%i) <> actual(%i)",
i, buffer[i], file_view[i]);
i, buffer[i], file_view[i]);
assert(0);
}
}
@ -58,12 +56,10 @@ int main()
assert(shared_file_view.size() == buffer.size());
// Then verify that mmap's bytes correspond to that of buffer.
for(auto i = 0; i < buffer.size(); ++i)
{
if(shared_file_view[i] != buffer[i])
{
for(auto i = 0; i < buffer.size(); ++i) {
if(shared_file_view[i] != buffer[i]) {
std::printf("%ith byte mismatch: expected(%i) <> actual(%i)",
i, buffer[i], shared_file_view[i]);
i, buffer[i], shared_file_view[i]);
assert(0);
}
}