-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbit_editors.h
72 lines (59 loc) · 1.45 KB
/
bit_editors.h
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
65
66
67
68
69
70
71
72
//
// Created by Тимофей Жамойдин on 23.10.22.
//
#pragma once
#include <fstream>
#include <cstdlib>
#include <iostream>
#include <vector>
#include "my_exceptions.h"
#include "constants.h"
class Reader {
public:
void operator=(const Reader& other) = delete;
Reader(const Reader& other) = delete;
explicit Reader(std::istream& stream, std::string_view filename);
std::string_view GetFilename();
bool IsEof();
bool GetBit();
std::vector<bool> GetBits(int size);
u_char GetByte();
void Reset();
private:
char buffer_[BUFFER_SIZE];
size_t current_index_ = 0;
size_t current_buffer_end_ = 0;
size_t bites_ = 0;
std::istream& stream_;
std::string_view filename_;
void UpdateBuffer();
};
class FileReader : public Reader {
public:
explicit FileReader(std::string_view filename);
~FileReader();
private:
std::ifstream file_;
};
class Writer {
public:
void operator=(const Writer& other) = delete;
Writer(const Writer& other) = delete;
explicit Writer(std::ostream& stream);
void WriteChar(char c);
void WriteBits(const std::vector<bool>& bites);
void WriteBit(bool b);
void Flush();
private:
char buffer_[BUFFER_SIZE];
size_t current_index_ = 0;
size_t bites_ = 0;
std::ostream& stream_;
};
class FileWriter : public Writer {
public:
explicit FileWriter(std::string_view filename);
~FileWriter();
private:
std::ofstream file_;
};