-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawPolicy.h
More file actions
64 lines (48 loc) · 1.41 KB
/
DrawPolicy.h
File metadata and controls
64 lines (48 loc) · 1.41 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
#ifndef INTERVAL_ANALYSIS_DRAWPOLICY_H
#define INTERVAL_ANALYSIS_DRAWPOLICY_H
#include "fstream"
#include "iostream"
#include "IPoint.h"
#include "sstream"
using std::ofstream, std::ostringstream;
struct EmptyDrawPolicy {
static void drawIPoint(const IPoint &iPoint) {}
};
struct MemoryDrawPolicy {
static ostringstream file;
static void drawIPoint(const IPoint &iPoint) {
file << iPoint;
}
static void saveToFile(std::string &filename) {
ofstream file_out;
file_out.open(filename);
file_out << file.str();
file_out.close();
}
};
ostringstream MemoryDrawPolicy::file = ostringstream();
struct FileDrawPolicy {
static ofstream file;
static void drawIPoint(const IPoint &iPoint) {
if (!file.is_open()) file.open("output.txt", std::ios::out | std::ios::app);
file << iPoint;
file.close();
}
};
ofstream FileDrawPolicy::file = ofstream("output.txt", std::ios::out);
struct PrintDrawPolicy {
static void drawIPoint(const IPoint &iPoint) {
cout << iPoint;
}
};
struct PrintAndFileDrawPolicy {
static ofstream file;
static void drawIPoint(const IPoint &iPoint) {
if (!file.is_open()) file.open("output.txt", std::ios::out | std::ios::app);
file << iPoint;
file.close();
cout << iPoint;
}
};
ofstream PrintAndFileDrawPolicy::file = ofstream("output.txt", std::ios::out);
#endif