AFIO  v2.00 late alpha
afio_v2_xxx::algorithm::mapped_span< 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_span.hpp"

Inheritance diagram for afio_v2_xxx::algorithm::mapped_span< 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_span ()
 Default constructor.
 
 mapped_span (size_type length, section_handle::flag _flag=section_handle::flag::readwrite)
 
 mapped_span (section_handle &sh, size_type length=(size_type) -1, extent_type byteoffset=0, section_handle::flag _flag=section_handle::flag::readwrite)
 
 mapped_span (map_handle &mh, size_type length=(size_type) -1, extent_type byteoffset=0)
 
 mapped_span (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_span< 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_span() [1/4]

template<class T >
afio_v2_xxx::algorithm::mapped_span< T >::mapped_span ( 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().
77  : _mapping(map_handle::map(length * sizeof(T), _flag).value())
78  {
79  byte *addr = _mapping.address();
80  static_cast<span<T> &>(*this) = span<T>(reinterpret_cast<T *>(addr), length); // NOLINT
81  }
static result< map_handle > map(size_type bytes, section_handle::flag _flag=section_handle::flag::readwrite) noexcept
result< section_handle::extent_type > length(const section_handle &self) noexcept
Return the current maximum permitted extent of the memory section.
Definition: map_handle.hpp:585
byte * address() const noexcept
The address in memory where this mapped view resides.
Definition: map_handle.hpp:411

◆ mapped_span() [2/4]

template<class T >
afio_v2_xxx::algorithm::mapped_span< T >::mapped_span ( 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().
91 #ifdef _WIN32
92  byteoffset & ~65535,
93 #else
95 #endif
96  byteoffset, sh, (length == (size_type) -1) ? 0 : length * sizeof(T), _flag)) // NOLINT
97  {
98  }
constexpr mapped_span()
Default constructor.
Definition: mapped_span.hpp:69
result< section_handle::extent_type > length(const section_handle &self) noexcept
Return the current maximum permitted extent of the memory section.
Definition: map_handle.hpp:585
typename section_handle::size_type size_type
The size type.
Definition: mapped_span.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_span() [3/4]

template<class T >
afio_v2_xxx::algorithm::mapped_span< T >::mapped_span ( map_handle mh,
size_type  length = (size_type) -1,
extent_type  byteoffset = 0 
)
inlineexplicit

Construct a mapped view of the given map handle.

Parameters
mhThe map handle to use.
lengthThe number of items to map, use -1 to mean the length of the map handle divided by sizeof(T).
byteoffsetThe byte offset into the map handle, this does not need to be a multiple of the page size.
106  : span<T>(reinterpret_cast<T *>(mh.address() + byteoffset), (length == (size_type) -1) ? ((mh.length() - byteoffset) / sizeof(T)) : length) // NOLINT
107  {
108  }
result< section_handle::extent_type > length(const section_handle &self) noexcept
Return the current maximum permitted extent of the memory section.
Definition: map_handle.hpp:585
typename section_handle::size_type size_type
The size type.
Definition: mapped_span.hpp:50

◆ mapped_span() [4/4]

template<class T >
afio_v2_xxx::algorithm::mapped_span< T >::mapped_span ( 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.
116  : span<T>(reinterpret_cast<T *>(mfh.address() + byteoffset), (length == (size_type) -1) ? ((mfh.maximum_extent().value() - byteoffset) / sizeof(T)) : length) // NOLINT
117  {
118  }
result< section_handle::extent_type > length(const section_handle &self) noexcept
Return the current maximum permitted extent of the memory section.
Definition: map_handle.hpp:585
typename section_handle::size_type size_type
The size type.
Definition: mapped_span.hpp:50

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