aboutsummaryrefslogtreecommitdiff
path: root/src/system/MemoryMappedFile.cpp
blob: 54f15c11bedc6b98213766e50e976f68c1aa2c2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "../../include/mglpp/system/MemoryMappedFile.hpp"

namespace mgl {
    MemoryMappedFile::MemoryMappedFile() {
        memory_mapped_file.data = nullptr;
        memory_mapped_file.size = 0;
        memory_mapped_file.fd = -1;
    }

    MemoryMappedFile::~MemoryMappedFile() {
        mgl_mapped_file_unload(&memory_mapped_file);
    }
    
    bool MemoryMappedFile::load(const char *filepath, LoadOptions load_options) {
        if(memory_mapped_file.fd != -1)
            return false;

        mgl_memory_mapped_file_load_options mapped_file_load_options = {
            load_options.readable,
            load_options.writable
        };
        return mgl_mapped_file_load(filepath, &memory_mapped_file, &mapped_file_load_options) == 0;
    }

    void* MemoryMappedFile::data() {
        return memory_mapped_file.data;
    }

    size_t MemoryMappedFile::size() {
        return memory_mapped_file.size;
    }

    const mgl_memory_mapped_file* MemoryMappedFile::internal_mapped_file() const {
        return &memory_mapped_file;
    }
}