AFIO  v2.00 late alpha
afio_v2_xxx::algorithm::mapped_view< T > Class Template Reference

Provides a typed mapped view of a section_handle suitable for feeding to STL algorithms or the Ranges TS by wrapping a map_handle into a span<T>. More...

#include "mapped_view.hpp"

Inheritance diagram for afio_v2_xxx::algorithm::mapped_view< T >:

Public Types

using extent_type = typename section_handle::extent_type
 The extent type.
 
using size_type = typename section_handle::size_type
 The size type.
 

Public Member Functions

constexpr mapped_view ()=default
 Default constructor.
 
 mapped_view (size_type length, section_handle::flag _flag=section_handle::flag::readwrite)
 
 mapped_view (section_handle &sh, size_type length=(size_type) -1, extent_type byteoffset=0, section_handle::flag _flag=section_handle::flag::readwrite)
 
 mapped_view (mapped_file_handle &mfh, size_type length=(size_type) -1, extent_type byteoffset=0)
 

Detailed Description

template<class T>
class afio_v2_xxx::algorithm::mapped_view< T >

Provides a typed mapped view of a section_handle suitable for feeding to STL algorithms or the Ranges TS by wrapping a map_handle into a span<T>.

Optionally can issue a blocking write barrier on destruction of the mapped view by setting the flag section_handle::flag::barrier_on_close, thus forcing any changes to data referred to by the view to storage before the destructor returns.

Constructor & Destructor Documentation

◆ mapped_view() [1/3]

template<class T >
afio_v2_xxx::algorithm::mapped_view< T >::mapped_view ( size_type  length,
section_handle::flag  _flag = section_handle::flag::readwrite 
)
inlineexplicit

Create a view of new memory.

Parameters
lengthThe number of items to map.
_flagThe flags to pass to map_handle::map().
76  : _mapping(map_handle::map(length * sizeof(T), _flag).value())
77  {
78  char *addr = _mapping.address();
79  static_cast<span<T> &>(*this) = span<T>(reinterpret_cast<T *>(addr), length);
80  }
char * address() const noexcept
The address in memory where this mapped view resides.
Definition: map_handle.hpp:342
result< file_handle::extent_type > length(const file_handle &self) noexcept
Definition: file_handle.hpp:360
static result< map_handle > map(size_type bytes, section_handle::flag _flag=section_handle::flag::readwrite) noexcept

◆ mapped_view() [2/3]

template<class T >
afio_v2_xxx::algorithm::mapped_view< T >::mapped_view ( section_handle sh,
size_type  length = (size_type) -1,
extent_type  byteoffset = 0,
section_handle::flag  _flag = section_handle::flag::readwrite 
)
inlineexplicit

Construct a mapped view of the given section handle.

Parameters
shThe section handle to use as the data source for creating the map.
lengthThe number of items to map, use -1 to mean the length of the section handle divided by sizeof(T).
byteoffsetThe byte offset into the section handle, this does not need to be a multiple of the page size.
_flagThe flags to pass to map_handle::map().
90 #ifdef _WIN32
91  byteoffset & ~65535,
92 #else
94 #endif
95  byteoffset, sh, (length == (size_type) -1) ? 0 : length * sizeof(T), _flag)) // NOLINT
96  {
97  }
result< file_handle::extent_type > length(const file_handle &self) noexcept
Definition: file_handle.hpp:360
constexpr mapped_view()=default
Default constructor.
typename section_handle::size_type size_type
The size type.
Definition: mapped_view.hpp:50
T round_down_to_page_size(T i) noexcept
Round a value to its next lowest page size multiple.
Definition: utils.hpp:51

◆ mapped_view() [3/3]

template<class T >
afio_v2_xxx::algorithm::mapped_view< T >::mapped_view ( mapped_file_handle mfh,
size_type  length = (size_type) -1,
extent_type  byteoffset = 0 
)
inlineexplicit

Construct a mapped view of the given mapped file handle.

Parameters
mfhThe mapped file handle to use as the data source for creating the map.
lengthThe number of items to map, use -1 to mean the length of the section handle divided by sizeof(T).
byteoffsetThe byte offset into the mapped file handle, this does not need to be a multiple of the page size.
105  : span<T>(reinterpret_cast<T *>(mfh.address() + byteoffset), (length == (size_type) -1) ? (mfh.length().value() / sizeof(T)) : length) // NOLINT
106  {
107  }
result< file_handle::extent_type > length(const file_handle &self) noexcept
Definition: file_handle.hpp:360
typename section_handle::size_type size_type
The size type.
Definition: mapped_view.hpp:50

The documentation for this class was generated from the following file: