aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/deprecated/mapped_file/mapped_file.cpp
blob: 90752ea26388183f1871485944e518064728f146 (plain) (blame)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "mapped_file.h"

#include <util/generic/yexception.h>
#include <util/system/defaults.h>
#include <util/system/hi_lo.h>
#include <util/system/filemap.h>

TMappedFile::TMappedFile(TFileMap* map, const char* dbgName) {
    Map_ = map;
    i64 len = Map_->Length();
    if (Hi32(len) != 0 && sizeof(size_t) <= sizeof(ui32))
        ythrow yexception() << "File '" << dbgName << "' mapping error: " << len << " too large";

    Map_->Map(0, static_cast<size_t>(len));
}

TMappedFile::TMappedFile(const TFile& file, TFileMap::EOpenMode om, const char* dbgName)
    : Map_(nullptr) 
{
    init(file, om, dbgName);
}

void TMappedFile::precharge(size_t off, size_t size) const {
    if (!Map_)
        return;

    Map_->Precharge(off, size);
}

void TMappedFile::init(const TString& name) {
    THolder<TFileMap> map(new TFileMap(name));
    TMappedFile newFile(map.Get(), name.data());
    Y_UNUSED(map.Release());
    newFile.swap(*this);
    newFile.term();
}

void TMappedFile::init(const TString& name, size_t length, TFileMap::EOpenMode om) {
    THolder<TFileMap> map(new TFileMap(name, length, om));
    TMappedFile newFile(map.Get(), name.data());
    Y_UNUSED(map.Release());
    newFile.swap(*this);
    newFile.term();
}

void TMappedFile::init(const TFile& file, TFileMap::EOpenMode om, const char* dbgName) {
    THolder<TFileMap> map(new TFileMap(file, om));
    TMappedFile newFile(map.Get(), dbgName);
    Y_UNUSED(map.Release());
    newFile.swap(*this);
    newFile.term();
}

void TMappedFile::init(const TString& name, TFileMap::EOpenMode om) {
    THolder<TFileMap> map(new TFileMap(name, om));
    TMappedFile newFile(map.Get(), name.data());
    Y_UNUSED(map.Release());
    newFile.swap(*this);
    newFile.term();
}

void TMappedFile::flush() {
    Map_->Flush();
}