Repository navigation
Expand file tree
/
Copy pathPrintStream.cpp
More file actions
79 lines (65 loc) · 1.39 KB
/
Copy pathPrintStream.cpp
File metadata and controls
79 lines (65 loc) · 1.39 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
73
74
75
76
77
78
79
//
// Created by Christopher McMorran on 2016-12-15.
//
#include <iostream>
#include "PrintStream.h"
PrintStream::PrintStream(String file)
{
this->_stream = new std::ofstream(file._string.c_str());
this->fname = file._string;
}
PrintStream::PrintStream(std::string file)
{
this->_stream = new std::ofstream(file.c_str());
this->fname = file;
}
PrintStream::~PrintStream()
{
delete(this->_stream);
}
bool PrintStream::open()
{
this->_stream->open(this->fname);
return this->_stream->is_open();
}
bool PrintStream::close()
{
this->_stream->close();
return !this->_stream->is_open();
}
bool PrintStream::isOpen()
{
return this->_stream->is_open();
}
bool PrintStream::isClosed()
{
return !this->_stream->is_open();
}
PrintStream &PrintStream::append(String string)
{
this->_stream->write(string._string.c_str(), string.length());
return *this;
}
PrintStream &PrintStream::append(std::string string)
{
this->_stream->write(string.c_str(), string.length());
return *this;
}
PrintStream &PrintStream::println(std::string string)
{
if (this->is_static) {
std::cout << string;
return *this;
}
this->_stream->write(string.append("\n").c_str(), string.length() + 1);
return *this;
}
PrintStream &PrintStream::println(String string)
{
if (this->is_static) {
std::cout << string;
return *this;
}
this->_stream->write(string.append("\n")._string.c_str(), string.length() + 1);
return *this;
}