Repository navigation
Expand file tree
/
Copy pathCResultWriter.h
More file actions
72 lines (59 loc) · 1.66 KB
/
Copy pathCResultWriter.h
File metadata and controls
72 lines (59 loc) · 1.66 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
// CResultWriter.h
#ifndef CRESULTWRITER_H
#define CRESULTWRITER_H
#include "CResult.h"
#include "CError.h"
#include "CTree.h"
#include <fstream>
#include <string>
#include <vector>
#include <iostream>
class CResultWriter
{
private:
static inline void v_writeErrors(std::ostream& os, const std::vector<CError*>& v_errors);
public:
template <typename T>
bool inline bWriteToFile(const CResult<T, CError>& cResult, const std::string& sFileName);
};
void inline CResultWriter::v_writeErrors(std::ostream& os, const std::vector<CError*>& v_errors)
{
os << "--- BLEDY ---" << std::endl;
for (size_t i = 0; i < v_errors.size(); ++i)
{
os << v_errors[i]->s_getMessage() << std::endl;
}
}
// 1. IMPLEMENTACJA SZABLONU OGÓLNEGO
template <typename T>
bool inline CResultWriter::bWriteToFile(const CResult<T, CError>& cResult, const std::string& sFileName)
{
std::ofstream file(sFileName.c_str());
if (!file.is_open()) return false;
if (!cResult.bIsSuccess())
{
CResultWriter::v_writeErrors(file, cResult.vGetErrors());
}
file.close();
return true;
}
// 2. IMPLEMENTACJA PEŁNEJ SPECJALIZACJI
template <>
bool inline CResultWriter::bWriteToFile<CTree>(const CResult<CTree, CError>& cResult, const std::string& sFileName)
{
std::ofstream file(sFileName.c_str());
if (!file.is_open()) return false;
if (!cResult.bIsSuccess())
{
v_writeErrors(file, cResult.vGetErrors());
}
else
{
file << "--- SUKCES: DRZEWO W POSTACI PREFIKSOWEJ ---" << std::endl;
CTree* pc_tree = cResult.cGetValue();
pc_tree->v_printPrefix(file);
}
file.close();
return true;
}
#endif