Correlation 4.10.0
An Analysis Tool for Liquids and for Amorphous Solids
Loading...
Searching...
No Matches
correlation::core::MappedFile Class Reference

RAII memory-mapped read-only file view. More...

#include <MappedFile.hpp>

Public Member Functions

 MappedFile (const std::string &path, bool enforce_size_limit=true)
 Opens and memory-maps a file for reading.
 ~MappedFile ()
 MappedFile (MappedFile &&other) noexcept
MappedFile & operator= (MappedFile &&other) noexcept
 MappedFile (const MappedFile &)=delete
MappedFile & operator= (const MappedFile &)=delete
const char * data () const noexcept
 Pointer to the start of the mapped file contents.
std::size_t size () const noexcept
 Size of the mapped region in bytes.
const char * end () const noexcept
 Convenience: pointer past the end.

Private Member Functions

void release () noexcept

Private Attributes

void * data_ {nullptr}
std::size_t size_ {0}
int fd_ {-1}

Detailed Description

RAII memory-mapped read-only file view.

The constructor opens the file and maps its entire contents into virtual memory. The destructor unmaps and closes all handles. Move-only.

Usage:

MappedFile mf("trajectory.xyz");
const char* data = mf.data();
size_t len = mf.size();
MappedFile(const std::string &path, bool enforce_size_limit=true)
Opens and memory-maps a file for reading.
Definition MappedFile.hpp:63
const char * data() const noexcept
Pointer to the start of the mapped file contents.
Definition MappedFile.hpp:181

Constructor & Destructor Documentation

◆ MappedFile() [1/3]

correlation::core::MappedFile::MappedFile ( const std::string & path,
bool enforce_size_limit = true )
inlineexplicit

Opens and memory-maps a file for reading.

Parameters
pathFile system path.
enforce_size_limitIf true, throws when file exceeds 4 GiB.
Exceptions
std::runtime_erroron I/O or mapping errors, or if the file exceeds the 4 GiB limit while enforce_size_limit is true.
Here is the caller graph for this function:

◆ ~MappedFile()

correlation::core::MappedFile::~MappedFile ( )
inline
Here is the call graph for this function:

◆ MappedFile() [2/3]

correlation::core::MappedFile::MappedFile ( MappedFile && other)
inlinenoexcept
Here is the call graph for this function:

◆ MappedFile() [3/3]

correlation::core::MappedFile::MappedFile ( const MappedFile & )
delete
Here is the call graph for this function:

Member Function Documentation

◆ data()

const char * correlation::core::MappedFile::data ( ) const
inlinenodiscardnoexcept

Pointer to the start of the mapped file contents.

◆ end()

const char * correlation::core::MappedFile::end ( ) const
inlinenodiscardnoexcept

Convenience: pointer past the end.

◆ operator=() [1/2]

MappedFile & correlation::core::MappedFile::operator= ( const MappedFile & )
delete
Here is the call graph for this function:

◆ operator=() [2/2]

MappedFile & correlation::core::MappedFile::operator= ( MappedFile && other)
inlinenoexcept
Here is the call graph for this function:

◆ release()

void correlation::core::MappedFile::release ( )
inlineprivatenoexcept
Here is the caller graph for this function:

◆ size()

std::size_t correlation::core::MappedFile::size ( ) const
inlinenodiscardnoexcept

Size of the mapped region in bytes.

Member Data Documentation

◆ data_

void* correlation::core::MappedFile::data_ {nullptr}
private

◆ fd_

int correlation::core::MappedFile::fd_ {-1}
private

◆ size_

std::size_t correlation::core::MappedFile::size_ {0}
private

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