Go to the documentation of this file.
10 #if __cplusplus < 201103L
11 #error "mmap_v2 is only supported with c++11 or newer"
19 #ifndef WIBBLE_SYS_MMAP_V2
20 #define WIBBLE_SYS_MMAP_V2
32 #define DEFAULT_MODE (ProtectMode::Read | ProtectMode::Shared)
47 size_t size() {
return _size; }
48 explicit operator bool() {
return bool( _ptr ); }
49 bool valid() {
return bool( _ptr ); }
53 template<
typename T >
54 T &
get(
size_t offset ) {
55 return *
reinterpret_cast< T *
>(
56 reinterpret_cast< char *
>( _ptr.get() ) + offset );
59 template<
typename T >
60 const T &
cget(
size_t offset )
const {
61 return *
reinterpret_cast< T *
>(
62 reinterpret_cast< char *
>( _ptr.get() ) + offset );
65 template<
typename T >
66 const T &
get(
size_t offset )
const {
return cget< T >( offset ); }
68 template<
typename T >
70 return reinterpret_cast< T *
>( _ptr.get() );
73 template<
typename T >
75 return reinterpret_cast< const T *
>( _ptr.get() );
78 template<
typename T >
80 return asConstArrayOf< T >();
84 return asArrayOf< char >()[ offset ];
88 return asArrayOf< char >()[ offset ];
92 std::shared_ptr< void > _ptr;
96 void _map(
const std::string & );
103 #endif // WIBBLE_SYS_MMAP_V2
T & get(size_t offset)
Definition: mmap_v2.h:54
ProtectModeFlags mode()
Definition: mmap_v2.h:50
ProtectMode
Definition: mmap_v2.h:28
size_t size()
Definition: mmap_v2.h:47
const T * asArrayOf() const
Definition: mmap_v2.h:79
Definition: buffer.cpp:28
#define DEFAULT_MODE
Definition: mmap_v2.h:32
StrongEnumFlags< ProtectMode > ProtectModeFlags
Definition: mmap_v2.h:33
void map(const std::string &, ProtectModeFlags=DEFAULT_MODE)
constexpr const static ProtectModeFlags defaultMode
Definition: mmap_v2.h:35
Map< List, F > map(const List &l, const F &f)
Definition: list.h:381
char & operator[](size_t offset)
Definition: mmap_v2.h:83
bool valid()
Definition: mmap_v2.h:49
T * asArrayOf()
Definition: mmap_v2.h:69
const char & operator[](size_t offset) const
Definition: mmap_v2.h:87
Base class for system exceptions.
Definition: exception.h:396
size_t size(const std::string &file)
File size.
Definition: fs.cpp:287
file(GLOB TEST_SOURCES test_ *.cpp) ADD_CUSTOM_TARGET(check COMMAND make libwibble-test &&$
Definition: tests/CMakeLists.txt:3
MMap()
Definition: mmap_v2.h:37
std::auto_ptr< struct stat > stat(const std::string &pathname)
stat() the given file and return the struct stat with the results.
const T * asConstArrayOf() const
Definition: mmap_v2.h:74
const T & cget(size_t offset) const
Definition: mmap_v2.h:60
const T & get(size_t offset) const
Definition: mmap_v2.h:66