-
Notifications
You must be signed in to change notification settings - Fork 0
/
write.hpp
118 lines (106 loc) · 3.05 KB
/
write.hpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* write.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tschmitt <tschmitt@student.42heilbronn.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/26 19:38:25 by tschmitt #+# #+# */
/* Updated: 2022/10/26 19:38:26 by tschmitt ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include <ostream>
#include <fstream>
namespace write
{
namespace color
{
namespace
{
enum code
{
FG_RED = 31,
FG_GREEN = 32,
FG_YELLOW = 33,
FG_BLUE = 34,
FG_BLACK = 30,
FG_DEFAULT = 39,
BG_RED = 41,
BG_GREEN = 42,
BG_YELLOW = 43,
BG_BLUE = 44,
BG_DEFAULT = 49
};
class modifier
{
private:
code _color_code;
public:
explicit modifier(code color_code) : _color_code(color_code) { };
friend std::ostream &operator<<(std::ostream &os, const modifier &modifier)
{
os << "\033[" << modifier._color_code << "m";
return os;
}
};
}
namespace fg
{
static modifier red(FG_RED);
static modifier green(FG_GREEN);
static modifier blue(FG_BLUE);
static modifier yellow(FG_YELLOW);
static modifier black(FG_BLACK);
static modifier reset(FG_DEFAULT);
}
namespace bg
{
static modifier red(BG_RED);
static modifier green(BG_GREEN);
static modifier blue(BG_BLUE);
static modifier yellow(BG_YELLOW);
static modifier reset(BG_DEFAULT);
}
}
namespace container
{
template < class Container >
static void to_file(Container container, std::ofstream &out_file_stream)
{
out_file_stream << std::endl;
for (typename Container::const_iterator it = container.begin(); it != container.end(); ++it)
{
out_file_stream << *it << ',';
}
out_file_stream << std::endl;
}
template < class Container >
static void to_out(Container container, std::ostream &out_stream)
{
out_stream << "Printing Content of Container" << std::endl;
for (typename Container::const_iterator it = container.begin(); it != container.end(); ++it)
{
out_stream << *it << ", ";
}
out_stream << std::endl;
}
}
namespace iterator
{
template < class Iterator >
static void to_file(Iterator iterator, Iterator end, std::ofstream &out_file_stream)
{
if (iterator == end)
return;
out_file_stream << '<' << *iterator << '>' << std::endl;
}
template < class Iterator >
static void to_out(Iterator iterator, Iterator end, std::ostream &out_stream)
{
if (iterator == end)
return;
out_stream << '<' << *iterator << '>' << std::endl;
}
}
}