aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/deprecated/mapped_file/mapped_file.h
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/deprecated/mapped_file/mapped_file.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/deprecated/mapped_file/mapped_file.h')
-rw-r--r--library/cpp/deprecated/mapped_file/mapped_file.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/library/cpp/deprecated/mapped_file/mapped_file.h b/library/cpp/deprecated/mapped_file/mapped_file.h
new file mode 100644
index 0000000000..45859ed65a
--- /dev/null
+++ b/library/cpp/deprecated/mapped_file/mapped_file.h
@@ -0,0 +1,72 @@
+#pragma once
+
+#include <util/generic/flags.h>
+#include <util/generic/ptr.h>
+#include <util/generic/string.h>
+#include <util/generic/utility.h>
+#include <util/generic/yexception.h>
+#include <util/system/align.h>
+#include <util/system/file.h>
+#include <util/system/filemap.h>
+#include <util/system/yassert.h>
+
+#include <cstdio>
+#include <new>
+
+/// Deprecated (by pg@), use TFileMap or TMemoryMap instead
+class TMappedFile {
+private:
+ TFileMap* Map_;
+
+private:
+ TMappedFile(TFileMap* map, const char* dbgName);
+
+public:
+ TMappedFile() {
+ Map_ = nullptr;
+ }
+
+ ~TMappedFile() {
+ term();
+ }
+
+ explicit TMappedFile(const TString& name) {
+ Map_ = nullptr;
+ init(name, TFileMap::oRdOnly);
+ }
+
+ TMappedFile(const TFile& file, TFileMap::EOpenMode om = TFileMap::oRdOnly, const char* dbgName = "unknown");
+
+ void init(const TString& name);
+
+ void init(const TString& name, TFileMap::EOpenMode om);
+
+ void init(const TString& name, size_t length, TFileMap::EOpenMode om);
+
+ void init(const TFile&, TFileMap::EOpenMode om = TFileMap::oRdOnly, const char* dbgName = "unknown");
+
+ void flush();
+
+ void term() {
+ if (Map_) {
+ Map_->Unmap();
+ delete Map_;
+ Map_ = nullptr;
+ }
+ }
+
+ size_t getSize() const {
+ return (Map_ ? Map_->MappedSize() : 0);
+ }
+
+ void* getData(size_t pos = 0) const {
+ Y_ASSERT(!Map_ || (pos <= getSize()));
+ return (Map_ ? (void*)((unsigned char*)Map_->Ptr() + pos) : nullptr);
+ }
+
+ void precharge(size_t pos = 0, size_t size = (size_t)-1) const;
+
+ void swap(TMappedFile& file) noexcept {
+ DoSwap(Map_, file.Map_);
+ }
+};