Website Summary Files Commits Branches @commit @diff @stats
path: root / Utils / Kindle / Page.cpp
blob: b663f4c909d24815d5300a00a7e09b3e7865488c (plain) (blame)
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
#include "Page.h"

void Page::write(unsigned linesCount) {
	if (linesCount > MAX_LINES_IN_PAGE)
		linesCount = MAX_LINES_IN_PAGE;


	for (size_t i = 0; i < linesCount; i++) {
		std::cout << i + 1 << " ";
		lines.pushBack(string());

		lines[i].getLine(std::cin);
	}
}

void Page::displayPage() const {
	for (size_t i = 0; i < lines.getSize(); i++)
		std::cout << lines[i] << std::endl;
}

void Page::writeToFile(std::ofstream& outFile) const {
	int len = lines.getSize();
	outFile.write((const char*)&len, sizeof(len));

	for (size_t i = 0; i < len; i++)
		writeString(outFile, lines[i]);
}

void Page::readFromFile(std::ifstream& inFile) {
	int len = 0;
	inFile.read((char*)&len, sizeof(len));

	for (size_t i = 0; i < len; i++) {
		string s = readString(inFile);
		lines.pushBack(std::move(s));
	}
}