Developer documentation
Version 3.0.3-105-gd3941f44
mmap.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __file_mmap_h__
18#define __file_mmap_h__
19
20#include <iostream>
21#include <cassert>
22#include <cstdint>
23
24#include "types.h"
25#include "file/entry.h"
26
27namespace MR
28{
29 namespace File
30 {
31
32 class MMap : protected Entry { NOMEMALIGN
33 public:
35
55 MMap (const Entry& entry, bool readwrite = false, bool preload = true, int64_t mapped_size = -1);
57
58 std::string name () const {
59 return Entry::name;
60 }
61 int64_t size () const {
62 return msize;
63 }
64 uint8_t* address() {
65 return first;
66 }
67 const uint8_t* address() const {
68 return first;
69 }
70
71 bool is_read_write () const {
72 return readwrite;
73 }
74 bool changed () const;
75
76 friend std::ostream& operator<< (std::ostream& stream, const MMap& m) {
77 stream << "File::MMap { " << m.name() << " [" << m.fd << "], size: "
78 << m.size() << ", mapped " << (m.readwrite ? "RW" : "RO")
79 << " at " << (void*) m.address() << ", offset " << m.start << " }";
80 return stream;
81 }
82
83 protected:
84 int fd;
85 uint8_t* addr;
86 uint8_t* first;
87 int64_t msize;
88 time_t mtime;
90
91 void map ();
92
93 private:
94 MMap (const MMap& mmap) : Entry (mmap), fd (0), addr (NULL), first (NULL), msize (0), mtime (0), readwrite (false) {
95 assert (0);
96 }
97 };
98
99
100 }
101}
102
103#endif
104
Definition: entry.h:29
std::string name
Definition: entry.h:42
int64_t start
Definition: entry.h:43
int64_t msize
Definition: mmap.h:87
friend std::ostream & operator<<(std::ostream &stream, const MMap &m)
Definition: mmap.h:76
bool readwrite
Definition: mmap.h:89
std::string name() const
Definition: mmap.h:58
MMap(const Entry &entry, bool readwrite=false, bool preload=true, int64_t mapped_size=-1)
create a new memory-mapping to file in entry
int fd
Definition: mmap.h:84
int64_t size() const
Definition: mmap.h:61
time_t mtime
Definition: mmap.h:88
bool is_read_write() const
Definition: mmap.h:71
const uint8_t * address() const
Definition: mmap.h:67
uint8_t * address()
Definition: mmap.h:64
uint8_t * first
Definition: mmap.h:86
bool changed() const
uint8_t * addr
Definition: mmap.h:85
#define NOMEMALIGN
Definition: memory.h:22
Definition: base.h:24