-
Notifications
You must be signed in to change notification settings - Fork 0
/
FilePrinter.cpp
38 lines (33 loc) · 1.41 KB
/
FilePrinter.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
#include "FilePrinter.h"
namespace {
const std::string KfourSpaces = " ";
const std::string KendLine = "\n";
}
void FilePrinter::print(const TBannerHashMap& aBannerHashMap) const {
std::ofstream outFile;
outFile.open(filename);
outFile<< "<Banners>"<<KendLine;
for(const auto& banner : aBannerHashMap) {
printBanner(outFile, banner.first, banner.second);
}
outFile<< "</Banners>";
outFile.close();
}
void FilePrinter::printBanner(std::ofstream& aStream, const std::string& aBannerId, const BannerInfo& aBanner) const
{
aStream<<KfourSpaces<<"<Banner id=\""<<aBannerId<<"\" revenues=\""<<aBanner.money_earned<<"\">"<<KendLine;
aStream<<KfourSpaces<<KfourSpaces<<"<Events>"<<KendLine;
for(const auto& eventInfo : aBanner.eventInfo_map) {
//Note: looks like it should be /Event instead of /event, but that how it was written in the task
//example : <Banner id="Banner71" revenues="6.449"> <Events> <Event id="6">2</event> ...
aStream<<KfourSpaces<<KfourSpaces<<KfourSpaces<<"<Event id=\""<<eventInfo.first<<"\">"<<eventInfo.second<<"</event>"<<KendLine;
}
aStream<<KfourSpaces<<KfourSpaces<<"</Events>"<<KendLine;
}
void FilePrinter::printError(const std::string& aError) const {
std::ofstream outFile;
outFile.open(filename);
outFile << "Exception occured: ";
outFile << aError;
outFile.close();
}