aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/deprecated/datafile/datafile.h
diff options
context:
space:
mode:
authorqrort <qrort@yandex-team.com>2022-12-02 11:31:25 +0300
committerqrort <qrort@yandex-team.com>2022-12-02 11:31:25 +0300
commitb1f4ffc9c8abff3ba58dc1ec9a9f92d2f0de6806 (patch)
tree2a23209faf0fea5586a6d4b9cee60d1b318d29fe /library/cpp/deprecated/datafile/datafile.h
parent559174a9144de40d6bb3997ea4073c82289b4974 (diff)
downloadydb-b1f4ffc9c8abff3ba58dc1ec9a9f92d2f0de6806.tar.gz
remove kikimr/driver DEPENDS
Diffstat (limited to 'library/cpp/deprecated/datafile/datafile.h')
-rw-r--r--library/cpp/deprecated/datafile/datafile.h88
1 files changed, 0 insertions, 88 deletions
diff --git a/library/cpp/deprecated/datafile/datafile.h b/library/cpp/deprecated/datafile/datafile.h
deleted file mode 100644
index a438baceca3..00000000000
--- a/library/cpp/deprecated/datafile/datafile.h
+++ /dev/null
@@ -1,88 +0,0 @@
-#pragma once
-
-#include "loadmode.h"
-
-#include <library/cpp/deprecated/mapped_file/mapped_file.h>
-
-#include <util/generic/vector.h>
-#include <util/system/file.h>
-#include <util/system/filemap.h>
-
-/** Simple helper that allows a file to be either mapped or read into malloc'ed memory.
- This behaviour is controlled by EDataLoadMode enum defined in loadmode.h.
- Unlike TBlob it provides Precharge() function and simple file size - based integrity check.
-
- To use this code, inherit your class from TDataFile<TFileHeader>.
- TFileHeader must be a pod-type structure with byte layout of the file header.
- File must start with that header.
- TFileHeader must have FileSize() member function that determines expected file size or
- length of data that need to be read from the beginning of file.
- */
-
-class TDataFileBase {
-protected:
- TVector<char> MemData;
- TMappedFile FileData;
-
- const char* Start;
- size_t Length;
-
- TDataFileBase()
- : Start(nullptr)
- , Length(0)
- {
- }
-
- void DoLoad(TFile& f, int loadMode, void* hdrPtr, size_t hdrSize);
- void DoLoad(const char* fname, int loadMode); // just whole file
- void Destroy();
- void swap(TDataFileBase& with) {
- MemData.swap(with.MemData);
- FileData.swap(with.FileData);
- DoSwap(Start, with.Start);
- DoSwap(Length, with.Length);
- }
-
-public:
- void Precharge() const;
-};
-
-template <class TFileHeader>
-class TDataFile: public TDataFileBase {
-protected:
- void Load(const char* fname, EDataLoadMode loadMode) {
- Destroy();
- TFile f(fname, RdOnly | Seq);
- TFileHeader hdr;
- f.Load(&hdr, sizeof(hdr));
- Length = hdr.FileSize();
- DoLoad(f, (int)loadMode, &hdr, sizeof(hdr));
- }
- const TFileHeader& Hdr() const {
- return *(TFileHeader*)Start;
- }
-};
-
-// Use: class TFoo: public TDataFileEx<Foo> {...};
-// Additional requrement: TFileHeader must have Validate(fname) function that throws exception.
-// Class TUser itself must have Init(fname) function
-// Adds Load() function to your class (TUser)
-template <class TUser, class TFileHeader>
-class TDataFileEx: public TDataFile<TFileHeader> {
-private:
- using TBase = TDataFile<TFileHeader>;
- TUser& User() const {
- return *(TUser*)this;
- }
-
-public:
- TDataFileEx(const char* fname, EDataLoadMode loadMode = DLM_DEFAULT) {
- if (fname)
- Load(fname, loadMode);
- }
- void Load(const char* fname, EDataLoadMode loadMode = DLM_DEFAULT) {
- TBase::Load(fname, loadMode);
- TBase::Hdr().Validate(fname);
- User().Init(fname);
- }
-};