-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPiece.cpp
More file actions
112 lines (89 loc) · 1.79 KB
/
Piece.cpp
File metadata and controls
112 lines (89 loc) · 1.79 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "Piece.h"
#include "Helpers.h"
#include <fstream>
#include <sstream>
#include <cassert>
Piece::Piece()
{
}
Piece::Piece(std::string file, int length, int pos, Piece * next, bool dummy)
{
mFileName = file;
mLength = length;
mFilePos = pos;
mNext = next;
mIsDummy = dummy;
// default font Calibri 20px
mFont.setFamily("Calibri");
mFont.setPixelSize(30);
mFont.setBold(false);
mFont.setItalic(false);
mFont.setUnderline(false);
}
Piece::Piece(std::string file, int length, int pos, Piece * next, QFont font, bool dummy)
: Piece(file, length, pos, next, dummy)
{
mFont = font;
}
void Piece::setNext(Piece * next)
{
mNext = next;
}
Piece * Piece::getNext() const
{
return mNext;
}
std::string Piece::getText()
{
std::string text;
if (mIsDummy)
return "";
mFileStream.open(mFileName);
// open file
if(!mFileStream.is_open())
{
assert(false);
return "";
}
// check file size
if (Helpers::GetFileSize(mFileName) < mFilePos + mLength)
{
assert(false);
return "";
}
std::ifstream t(mFileName);
std::string str((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
t.close();
size_t strSize = str.size();
if (strSize < mFilePos + mLength)
assert(false);
return str.substr(mFilePos, mLength);
}
int Piece::getLength() const
{
return mLength;
}
void Piece::setLength(int length)
{
mLength = length;
}
std::string Piece::getFile() const
{
return mFileName;
}
int Piece::getFilePos() const
{
return mFilePos;
}
QFont Piece::getFont() const
{
return mFont;
}
void Piece::setFont(QFont const& font)
{
mFont = font;
}
Piece * Piece::getDeepCopy()
{
return new Piece(mFileName, mLength, mFilePos, mNext, mFont, mIsDummy);
}