-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSinkClasses.cpp
More file actions
65 lines (52 loc) · 1.51 KB
/
SinkClasses.cpp
File metadata and controls
65 lines (52 loc) · 1.51 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
#define _CRT_SECURE_NO_WARNINGS
#include "SinkClasses.h"
#include <cstring>
#include <fstream>
//двата конструктора за двата различни случая (не можем да имаме stream и filter едновремено)
Sink::Sink(Stream* stream) : streamPointer(stream), filterPoiter(nullptr) {}
Sink::Sink(Filter* filter) : streamPointer(nullptr), filterPoiter(filter) {}
Stream* Sink::getStreamPointer()
{
return streamPointer;
}
Filter* Sink::getFilterPointer()
{
return filterPoiter;
}
void Sink::printEverything()
{
if (streamPointer != nullptr)
{
std::cout << streamPointer->readInput() << std::endl;
}
else
{
std::cout << filterPoiter->searchWordInInput() << std::endl;
}
}
FileSink::FileSink(Stream* stream, const char* filename) : Sink(stream), filename(filename)
{
}
FileSink::FileSink(Filter* filter, const char* filename) : Sink(filter), filename(filename)
{
}
void FileSink::saveTextDataToFile()
{
std::ofstream outputFile(filename);
if (!outputFile)
{
std::cerr << "Could not open the file you've chose: " << filename << std::endl;
return;
}
if (this->getStreamPointer() != nullptr)
{
const char* content = this->getStreamPointer()->readInput();
outputFile << content;
}
else if (this->getFilterPointer() != nullptr)
{
const char* content = this->getFilterPointer()->searchWordInInput();
outputFile << content;
}
outputFile.close();
}