mio 1.1.0
Loading...
Searching...
No Matches
mio::basic_mmap< AccessMode, ByteT > Struct Template Reference

#include <mmap.hpp>

Public Types

using value_type = ByteT
 
using size_type = size_t
 
using reference = value_type &
 
using const_reference = const value_type &
 
using pointer = value_type *
 
using const_pointer = const value_type *
 
using difference_type = std::ptrdiff_t
 
using iterator = pointer
 
using const_iterator = const_pointer
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 
using iterator_category = std::random_access_iterator_tag
 
using handle_type = file_handle_type
 

Public Member Functions

 basic_mmap ()
 
 basic_mmap (const basic_mmap &)=delete
 
 basic_mmap (basic_mmap &&)
 
basic_mmapoperator= (const basic_mmap &)=delete
 
basic_mmapoperator= (basic_mmap &&)
 
 ~basic_mmap ()
 
handle_type file_handle () const noexcept
 
handle_type mapping_handle () const noexcept
 
bool is_open () const noexcept
 
bool empty () const noexcept
 
bool is_mapped () const noexcept
 
size_type size () const noexcept
 
size_type length () const noexcept
 
size_type mapped_length () const noexcept
 
size_type mapping_offset () const noexcept
 
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
pointer data () noexcept
 
const_pointer data () const noexcept
 
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
const_iterator cbegin () const noexcept
 
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
iterator end () noexcept
 
const_iterator end () const noexcept
 
const_iterator cend () const noexcept
 
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
reverse_iterator rbegin () noexcept
 
const_reverse_iterator rbegin () const noexcept
 
const_reverse_iterator crbegin () const noexcept
 
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
reverse_iterator rend () noexcept
 
const_reverse_iterator rend () const noexcept
 
const_reverse_iterator crend () const noexcept
 
reference operator[] (const size_type &i) noexcept
 
const_reference operator[] (const size_type &i) const noexcept
 
template<typename String >
void map (const String &path, const size_type &offset, const size_type &length, std::error_code &error)
 
template<typename String >
void map (const String &path, std::error_code &error)
 
void map (const handle_type &handle, const size_type &offset, const size_type &length, std::error_code &error)
 
void map (const handle_type &handle, std::error_code &error)
 
void unmap ()
 
void swap (basic_mmap &other)
 
template<access_mode A = AccessMode>
std::enable_if< A==access_mode::write, void >::type sync (std::error_code &error)
 

Member Typedef Documentation

◆ const_iterator

template<access_mode AccessMode, typename ByteT >
using mio::basic_mmap< AccessMode, ByteT >::const_iterator = const_pointer

◆ const_pointer

template<access_mode AccessMode, typename ByteT >
using mio::basic_mmap< AccessMode, ByteT >::const_pointer = const value_type*

◆ const_reference

template<access_mode AccessMode, typename ByteT >
using mio::basic_mmap< AccessMode, ByteT >::const_reference = const value_type&

◆ const_reverse_iterator

template<access_mode AccessMode, typename ByteT >
using mio::basic_mmap< AccessMode, ByteT >::const_reverse_iterator = std::reverse_iterator<const_iterator>

◆ difference_type

template<access_mode AccessMode, typename ByteT >
using mio::basic_mmap< AccessMode, ByteT >::difference_type = std::ptrdiff_t

◆ handle_type

template<access_mode AccessMode, typename ByteT >
using mio::basic_mmap< AccessMode, ByteT >::handle_type = file_handle_type

◆ iterator

template<access_mode AccessMode, typename ByteT >
using mio::basic_mmap< AccessMode, ByteT >::iterator = pointer

◆ iterator_category

template<access_mode AccessMode, typename ByteT >
using mio::basic_mmap< AccessMode, ByteT >::iterator_category = std::random_access_iterator_tag

◆ pointer

template<access_mode AccessMode, typename ByteT >
using mio::basic_mmap< AccessMode, ByteT >::pointer = value_type*

◆ reference

template<access_mode AccessMode, typename ByteT >
using mio::basic_mmap< AccessMode, ByteT >::reference = value_type&

◆ reverse_iterator

template<access_mode AccessMode, typename ByteT >
using mio::basic_mmap< AccessMode, ByteT >::reverse_iterator = std::reverse_iterator<iterator>

◆ size_type

template<access_mode AccessMode, typename ByteT >
using mio::basic_mmap< AccessMode, ByteT >::size_type = size_t

◆ value_type

template<access_mode AccessMode, typename ByteT >
using mio::basic_mmap< AccessMode, ByteT >::value_type = ByteT

Constructor & Destructor Documentation

◆ basic_mmap() [1/3]

template<access_mode AccessMode, typename ByteT >
mio::basic_mmap< AccessMode, ByteT >::basic_mmap ( )
inline

The default constructed mmap object is in a non-mapped state, that is, any operation that attempts to access nonexistent underlying data will result in undefined behaviour/segmentation faults.

◆ basic_mmap() [2/3]

template<access_mode AccessMode, typename ByteT >
mio::basic_mmap< AccessMode, ByteT >::basic_mmap ( const basic_mmap< AccessMode, ByteT > &  )
delete

basic_mmap has single-ownership semantics, so transferring ownership may only be accomplished by moving the object.

◆ basic_mmap() [3/3]

template<access_mode AccessMode, typename ByteT >
mio::basic_mmap< AccessMode, ByteT >::basic_mmap ( basic_mmap< AccessMode, ByteT > &&  )

◆ ~basic_mmap()

If this is a read-write mapping, the destructor invokes sync. Regardless of the access mode, unmap is invoked as a final step.

Member Function Documentation

◆ begin() [1/2]

template<access_mode AccessMode, typename ByteT >
const_iterator mio::basic_mmap< AccessMode, ByteT >::begin ( ) const
inlinenoexcept

◆ begin() [2/2]

template<access_mode AccessMode, typename ByteT >
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
iterator mio::basic_mmap< AccessMode, ByteT >::begin ( )
inlinenoexcept

Returns an iterator to the first requested byte, if a valid memory mapping exists, otherwise this function call is undefined behaviour.

◆ cbegin()

template<access_mode AccessMode, typename ByteT >
const_iterator mio::basic_mmap< AccessMode, ByteT >::cbegin ( ) const
inlinenoexcept

◆ cend()

template<access_mode AccessMode, typename ByteT >
const_iterator mio::basic_mmap< AccessMode, ByteT >::cend ( ) const
inlinenoexcept

◆ crbegin()

template<access_mode AccessMode, typename ByteT >
const_reverse_iterator mio::basic_mmap< AccessMode, ByteT >::crbegin ( ) const
inlinenoexcept

◆ crend()

template<access_mode AccessMode, typename ByteT >
const_reverse_iterator mio::basic_mmap< AccessMode, ByteT >::crend ( ) const
inlinenoexcept

◆ data() [1/2]

template<access_mode AccessMode, typename ByteT >
const_pointer mio::basic_mmap< AccessMode, ByteT >::data ( ) const
inlinenoexcept

◆ data() [2/2]

template<access_mode AccessMode, typename ByteT >
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
pointer mio::basic_mmap< AccessMode, ByteT >::data ( )
inlinenoexcept

Returns a pointer to the first requested byte, or nullptr if no memory mapping exists.

◆ empty()

template<access_mode AccessMode, typename ByteT >
bool mio::basic_mmap< AccessMode, ByteT >::empty ( ) const
inlinenoexcept

Returns true if no mapping was established, that is, conceptually the same as though the length that was mapped was 0. This function is provided so that this class has Container semantics.

◆ end() [1/2]

template<access_mode AccessMode, typename ByteT >
const_iterator mio::basic_mmap< AccessMode, ByteT >::end ( ) const
inlinenoexcept

◆ end() [2/2]

template<access_mode AccessMode, typename ByteT >
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
iterator mio::basic_mmap< AccessMode, ByteT >::end ( )
inlinenoexcept

Returns an iterator one past the last requested byte, if a valid memory mapping exists, otherwise this function call is undefined behaviour.

◆ file_handle()

template<access_mode AccessMode, typename ByteT >
handle_type mio::basic_mmap< AccessMode, ByteT >::file_handle ( ) const
inlinenoexcept

On UNIX systems 'file_handle' and 'mapping_handle' are the same. On Windows, however, a mapped region of a file gets its own handle, which is returned by 'mapping_handle'.

◆ is_mapped()

template<access_mode AccessMode, typename ByteT >
bool mio::basic_mmap< AccessMode, ByteT >::is_mapped ( ) const
noexcept

Returns true if a mapping was established.

◆ is_open()

template<access_mode AccessMode, typename ByteT >
bool mio::basic_mmap< AccessMode, ByteT >::is_open ( ) const
inlinenoexcept

Returns whether a valid memory mapping has been created.

◆ length()

template<access_mode AccessMode, typename ByteT >
size_type mio::basic_mmap< AccessMode, ByteT >::length ( ) const
inlinenoexcept

◆ map() [1/4]

template<access_mode AccessMode, typename ByteT >
void mio::basic_mmap< AccessMode, ByteT >::map ( const handle_type handle,
const size_type offset,
const size_type length,
std::error_code &  error 
)

Establishes a memory mapping with AccessMode. If the mapping is unsuccesful, the reason is reported via error and the object remains in a state as if this function hadn't been called.

handle, which must be a valid file handle, which is used to memory map the requested region. Upon failure, error is set to indicate the reason and the object remains in an unmapped state.

offset is the number of bytes, relative to the start of the file, where the mapping should begin. When specifying it, there is no need to worry about providing a value that is aligned with the operating system's page allocation granularity. This is adjusted by the implementation such that the first requested byte (as returned by data or begin), so long as offset is valid, will be at offset from the start of the file.

length is the number of bytes to map. It may be map_entire_file, in which case a mapping of the entire file is created.

◆ map() [2/4]

template<access_mode AccessMode, typename ByteT >
void mio::basic_mmap< AccessMode, ByteT >::map ( const handle_type handle,
std::error_code &  error 
)
inline

Establishes a memory mapping with AccessMode. If the mapping is unsuccesful, the reason is reported via error and the object remains in a state as if this function hadn't been called.

handle, which must be a valid file handle, which is used to memory map the requested region. Upon failure, error is set to indicate the reason and the object remains in an unmapped state.

The entire file is mapped.

◆ map() [3/4]

template<access_mode AccessMode, typename ByteT >
template<typename String >
void mio::basic_mmap< AccessMode, ByteT >::map ( const String path,
const size_type offset,
const size_type length,
std::error_code &  error 
)

Establishes a memory mapping with AccessMode. If the mapping is unsuccesful, the reason is reported via error and the object remains in a state as if this function hadn't been called.

path, which must be a path to an existing file, is used to retrieve a file handle (which is closed when the object destructs or unmap is called), which is then used to memory map the requested region. Upon failure, error is set to indicate the reason and the object remains in an unmapped state.

offset is the number of bytes, relative to the start of the file, where the mapping should begin. When specifying it, there is no need to worry about providing a value that is aligned with the operating system's page allocation granularity. This is adjusted by the implementation such that the first requested byte (as returned by data or begin), so long as offset is valid, will be at offset from the start of the file.

length is the number of bytes to map. It may be map_entire_file, in which case a mapping of the entire file is created.

◆ map() [4/4]

template<access_mode AccessMode, typename ByteT >
template<typename String >
void mio::basic_mmap< AccessMode, ByteT >::map ( const String path,
std::error_code &  error 
)
inline

Establishes a memory mapping with AccessMode. If the mapping is unsuccesful, the reason is reported via error and the object remains in a state as if this function hadn't been called.

path, which must be a path to an existing file, is used to retrieve a file handle (which is closed when the object destructs or unmap is called), which is then used to memory map the requested region. Upon failure, error is set to indicate the reason and the object remains in an unmapped state.

The entire file is mapped.

◆ mapped_length()

template<access_mode AccessMode, typename ByteT >
size_type mio::basic_mmap< AccessMode, ByteT >::mapped_length ( ) const
inlinenoexcept

◆ mapping_handle()

template<access_mode AccessMode, typename ByteT >
handle_type mio::basic_mmap< AccessMode, ByteT >::mapping_handle ( ) const
noexcept

◆ mapping_offset()

template<access_mode AccessMode, typename ByteT >
size_type mio::basic_mmap< AccessMode, ByteT >::mapping_offset ( ) const
inlinenoexcept

Returns the offset relative to the start of the mapping.

◆ operator=() [1/2]

◆ operator=() [2/2]

◆ operator[]() [1/2]

template<access_mode AccessMode, typename ByteT >
const_reference mio::basic_mmap< AccessMode, ByteT >::operator[] ( const size_type i) const
inlinenoexcept

◆ operator[]() [2/2]

template<access_mode AccessMode, typename ByteT >
reference mio::basic_mmap< AccessMode, ByteT >::operator[] ( const size_type i)
inlinenoexcept

Returns a reference to the ith byte from the first requested byte (as returned by data). If this is invoked when no valid memory mapping has been created prior to this call, undefined behaviour ensues.

◆ rbegin() [1/2]

template<access_mode AccessMode, typename ByteT >
const_reverse_iterator mio::basic_mmap< AccessMode, ByteT >::rbegin ( ) const
inlinenoexcept

◆ rbegin() [2/2]

template<access_mode AccessMode, typename ByteT >
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
reverse_iterator mio::basic_mmap< AccessMode, ByteT >::rbegin ( )
inlinenoexcept

Returns a reverse iterator to the last memory mapped byte, if a valid memory mapping exists, otherwise this function call is undefined behaviour.

◆ rend() [1/2]

template<access_mode AccessMode, typename ByteT >
const_reverse_iterator mio::basic_mmap< AccessMode, ByteT >::rend ( ) const
inlinenoexcept

◆ rend() [2/2]

template<access_mode AccessMode, typename ByteT >
template<access_mode A = AccessMode, typename = typename std::enable_if<A == access_mode::write>::type>
reverse_iterator mio::basic_mmap< AccessMode, ByteT >::rend ( )
inlinenoexcept

Returns a reverse iterator past the first mapped byte, if a valid memory mapping exists, otherwise this function call is undefined behaviour.

◆ size()

template<access_mode AccessMode, typename ByteT >
size_type mio::basic_mmap< AccessMode, ByteT >::size ( ) const
inlinenoexcept

size and length both return the logical length, i.e. the number of bytes user requested to be mapped, while mapped_length returns the actual number of bytes that were mapped which is a multiple of the underlying operating system's page allocation granularity.

◆ swap()

template<access_mode AccessMode, typename ByteT >
void mio::basic_mmap< AccessMode, ByteT >::swap ( basic_mmap< AccessMode, ByteT > &  other)

◆ sync()

template<access_mode AccessMode, typename ByteT >
template<access_mode A = AccessMode>
std::enable_if< A==access_mode::write, void >::type mio::basic_mmap< AccessMode, ByteT >::sync ( std::error_code &  error)

Flushes the memory mapped page to disk. Errors are reported via error.

◆ unmap()

template<access_mode AccessMode, typename ByteT >
void mio::basic_mmap< AccessMode, ByteT >::unmap ( )

If a valid memory mapping has been created prior to this call, this call instructs the kernel to unmap the memory region and disassociate this object from the file.

The file handle associated with the file that is mapped is only closed if the mapping was created using a file path. If, on the other hand, an existing file handle was used to create the mapping, the file handle is not closed.


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