/
printer.cpp
48 lines (34 loc) · 881 Bytes
/
printer.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
#include "printer.hpp"
#include "template.hpp"
#include <vector>
#include <iostream>
#include <fstream>
using namespace std;
using namespace bake;
Printer::Printer(string filename) {
this->filename = filename;
}
void Printer::print(Tree *temp, vector<Post *>posts) {
fstream file(filename, ios::out);
if (!file.is_open())
return;
file << temp->get_begin();
auto post_temp = temp->get_post_template();
for (auto post : posts) {
string post_str = post_temp->get_post(post);
file << post_str;
}
file << temp->get_end();
file.close();
}
void Printer::print(Tree *temp, Post *post) {
fstream file(filename, ios::out);
if (!file.is_open())
return;
file << temp->get_begin();
auto post_temp = temp->get_post_template();
string post_str = post_temp->get_post(post);
file << post_str;
file << temp->get_end();
file.close();
}