-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrFile.h
More file actions
56 lines (48 loc) · 1.46 KB
/
StrFile.h
File metadata and controls
56 lines (48 loc) · 1.46 KB
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
/** ======================================================================+
+ Copyright @2020-2021 Arjun Ray
+ Released under MIT License
+ see https://mit-license.org
+========================================================================*/
#pragma once
#ifndef UTILITY_STRFILE_H
#define UTILITY_STRFILE_H
#include <utility>
namespace Utility
{
/**
* @class StrFile
* @brief File into memory buffer
*/
class StrFile
{
public:
~StrFile() noexcept;
StrFile(char const* file);
StrFile(StrFile&&); // move-only
explicit operator bool() const { return base_ != nullptr; }
int error() const { return err_; }
using Spec = std::pair<char const*, std::size_t>;
Spec spec() const { return {get(), size()}; }
char* get() { return static_cast<char*>(base_); }
char const* get() const { return static_cast<char const*>(base_); }
std::size_t size() const { return fsize_; }
private:
std::size_t fsize_{0};
std::size_t msize_{0};
void* base_{nullptr};
int err_{0};
//
void map_normal_( int fd, std::size_t size );
void map_special_( int fd, std::size_t size );
};
inline
StrFile::StrFile(StrFile&& model)
: fsize_(model.fsize_)
, msize_(model.msize_)
, base_(model.base_)
, err_(model.err_)
{
model.base_ = nullptr;
}
} // namespace Utility
#endif // UTILITY_STRFILE_H