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
27
namespace
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);
56
~MMap
();
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
;
89
bool
readwrite
;
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
MR::File::Entry
Definition:
entry.h:29
MR::File::Entry::name
std::string name
Definition:
entry.h:42
MR::File::Entry::start
int64_t start
Definition:
entry.h:43
MR::File::MMap
Definition:
mmap.h:32
MR::File::MMap::msize
int64_t msize
Definition:
mmap.h:87
MR::File::MMap::operator<<
friend std::ostream & operator<<(std::ostream &stream, const MMap &m)
Definition:
mmap.h:76
MR::File::MMap::readwrite
bool readwrite
Definition:
mmap.h:89
MR::File::MMap::map
void map()
MR::File::MMap::name
std::string name() const
Definition:
mmap.h:58
MR::File::MMap::~MMap
~MMap()
MR::File::MMap::MMap
MMap(const Entry &entry, bool readwrite=false, bool preload=true, int64_t mapped_size=-1)
create a new memory-mapping to file in entry
MR::File::MMap::fd
int fd
Definition:
mmap.h:84
MR::File::MMap::size
int64_t size() const
Definition:
mmap.h:61
MR::File::MMap::mtime
time_t mtime
Definition:
mmap.h:88
MR::File::MMap::is_read_write
bool is_read_write() const
Definition:
mmap.h:71
MR::File::MMap::address
const uint8_t * address() const
Definition:
mmap.h:67
MR::File::MMap::address
uint8_t * address()
Definition:
mmap.h:64
MR::File::MMap::first
uint8_t * first
Definition:
mmap.h:86
MR::File::MMap::changed
bool changed() const
MR::File::MMap::addr
uint8_t * addr
Definition:
mmap.h:85
entry.h
NOMEMALIGN
#define NOMEMALIGN
Definition:
memory.h:22
MR
Definition:
base.h:24
core
file
mmap.h
Generated on Mon Jul 4 2022 08:00:06 for MRtrix by
1.9.3