MVault 1.0.0
Simple c++ database
Loading...
Searching...
No Matches
StreamFileReader.h
1#pragma once
2
3#include <cstdint>
4#include <fstream>
5#include <iostream>
6
7// BIG_FILE_SIZE must be greater then FILE_BLOCK_SIZE
8#define FILE_BLOCK_SIZE 4096
9#define BIG_FILE_SIZE 10485760
10
11namespace mvlt
12{
28 {
29 private:
30 // Input file variable
31 std::ifstream File;
32
33 // Input file size
34 std::streamsize FileSize = 0;
35
36 // Position in file
37 std::streamsize FilePos = 0;
38
39 // Position if file chunk
40 std::uint16_t ChunkPos = 1;
41
42 // Current char
43 char Char = 0;
44
45 // Next char
46 char NextChar = 0;
47
48 // File chunk
49 char DataChunk[FILE_BLOCK_SIZE] = {0};
50
51 // Pointer to store little files
52 char* Data = nullptr;
53
54 public:
57 StreamFileReader() noexcept;
58
64 StreamFileReader(const StreamFileReader& other) noexcept = delete;
65
71 StreamFileReader(StreamFileReader&& other) noexcept = delete;
72
78 explicit StreamFileReader(const std::string& fileName) noexcept;
79
87 StreamFileReader& operator=(const StreamFileReader& other) noexcept = delete;
88
96 StreamFileReader& operator=(StreamFileReader&& other) noexcept = delete;
97
105 bool Open(const std::string& fileName) noexcept;
106
112 bool IsOpen() const noexcept;
113
119 bool IsEnd() const noexcept;
120
126 std::size_t GetFileSize() const noexcept;
127
133 std::size_t GetCurrentPos() const noexcept;
134
140 char GetChar() const noexcept;
141
147 char GetNextChar() const noexcept;
148
154 bool Move() noexcept;
155
157 void Close() noexcept;
158
160 ~StreamFileReader() noexcept;
161 };
162
164}
A class for reading files as a stream.
Definition StreamFileReader.h:28
char GetChar() const noexcept
Method for getting the current character.
Definition StreamFileReader.cpp:78
StreamFileReader() noexcept
Default constructor.
Definition StreamFileReader.cpp:5
bool Open(const std::string &fileName) noexcept
Method for opening the file.
Definition StreamFileReader.cpp:12
StreamFileReader & operator=(const StreamFileReader &other) noexcept=delete
Assignment operator.
void Close() noexcept
Method for closing a file.
Definition StreamFileReader.cpp:128
std::size_t GetCurrentPos() const noexcept
A method for get current reading position.
Definition StreamFileReader.cpp:71
bool IsOpen() const noexcept
Method for checking whether the file has been opened.
Definition StreamFileReader.cpp:43
StreamFileReader & operator=(StreamFileReader &&other) noexcept=delete
Move assignment operator.
bool IsEnd() const noexcept
A method for checking if a file has been read.
Definition StreamFileReader.cpp:48
StreamFileReader(const StreamFileReader &other) noexcept=delete
Copy constructor.
char GetNextChar() const noexcept
Method for getting the next character.
Definition StreamFileReader.cpp:83
StreamFileReader(StreamFileReader &&other) noexcept=delete
Move constructor.
bool Move() noexcept
A method for moving through a file.
Definition StreamFileReader.cpp:88
std::size_t GetFileSize() const noexcept
A method for get file size.
Definition StreamFileReader.cpp:66