Storm 1.10.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
MappedFile.cpp
Go to the documentation of this file.
1/*
2 * MappedFile.cpp
3 *
4 * Created on: Jan 21, 2014
5 * Author: Manuel Sascha Weiand
6 */
7
9
10#include <fcntl.h>
11#include <sys/mman.h>
12#include <cstring>
13#include <fstream>
14
15#include <boost/integer/integer_mask.hpp>
16
18#include "storm/io/file.h"
20
21namespace storm {
22namespace parser {
23
24MappedFile::MappedFile(const char* filename) {
25 STORM_LOG_THROW(storm::io::fileExistsAndIsReadable(filename), storm::exceptions::FileIoException,
26 "Error while reading " << filename << ": The file does not exist or is not readable.");
27
28 // Do file mapping for reasonable systems.
29 // stat64(), open(), mmap()
30
31#ifdef MACOSX
32 if (stat(filename, &(this->st)) != 0) {
33#else
34 if (stat64(filename, &(this->st)) != 0) {
35#endif
36 STORM_LOG_THROW(false, storm::exceptions::FileIoException, "Error in stat(" << filename << "): Probably, this file does not exist.");
37 }
38 this->file = open(filename, O_RDONLY);
39
40 STORM_LOG_THROW(this->file >= 0, storm::exceptions::FileIoException, "Error in open(" << filename << "): Probably, we may not read this file.");
41
42 this->data = static_cast<char*>(mmap(NULL, this->st.st_size, PROT_READ, MAP_PRIVATE, this->file, 0));
43 if (this->data == MAP_FAILED) {
44 close(this->file);
45 STORM_LOG_ERROR("Error in mmap(" << filename << "): " << std::strerror(errno));
46 throw exceptions::FileIoException() << "MappedFile Error in mmap(): " << std::strerror(errno);
47 }
48 this->dataEnd = this->data + this->st.st_size;
49}
50
52 munmap(this->data, this->st.st_size);
53 close(this->file);
54}
55
56char const* MappedFile::getData() const {
57 return data;
58}
59
60char const* MappedFile::getDataEnd() const {
61 return dataEnd;
62}
63
64std::size_t MappedFile::getDataSize() const {
65 return this->getDataEnd() - this->getData();
66}
67
68} // namespace parser
69} // namespace storm
char const * getData() const
Returns a pointer to the beginning of the mapped file data.
~MappedFile()
Destructs a MappedFile.
char const * getDataEnd() const
Returns a pointer to the end of the mapped file data.
std::size_t getDataSize() const
Returns the size of the mapped file data.
MappedFile(const char *filename)
Constructs a MappedFile.
#define STORM_LOG_ERROR(message)
Definition logging.h:26
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
bool fileExistsAndIsReadable(std::string const &filename)
Tests whether the given file exists and is readable.
Definition file.h:66
LabParser.cpp.