-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHexViewer.cpp
63 lines (54 loc) · 1.22 KB
/
HexViewer.cpp
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
#include "HexViewer.h"
#include "Style/Hexyl/Hexyl.h"
#include "Style/HexDump/HexDump.h"
#include "Printer/DefaultPrinter/DefaultPrinter.h"
#include "FileStream/LocalFile/LocalFile.h"
#include "DataProcessing/DataProcessing.h"
HexViewer::HexViewer()
: m_style(nullptr)
, m_printer(nullptr)
, m_file(nullptr)
{
}
HexViewer::~HexViewer()
{
delete m_style;
delete m_printer;
delete m_file;
}
void HexViewer::setStyle(const std::string& _style, bool _colors)
{
if (_style == "hexyl")
{
m_style = new Hexyl(_colors);
}
else if (_style == "hexdump")
{
m_style = new HexDump;
}
else
{
throw std::runtime_error("Can't load theme");
}
}
void HexViewer::setPrinter(const std::string& _printer)
{
m_printer = new DefaultPrinter;
}
void HexViewer::setFile(const std::string& _file)
{
m_file = new LocalFile(_file);
}
void HexViewer::print(int _offset, size_t _length)
{
DataProcessing dataProcessing(*m_printer, *m_style, *m_file);
if (_offset)
{
dataProcessing.setOffset(_offset);
}
if (_length)
{
dataProcessing.setLength(_length);
}
dataProcessing.process();
}