-
Notifications
You must be signed in to change notification settings - Fork 1
/
ofstream.cpp
98 lines (85 loc) · 2.55 KB
/
ofstream.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
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
#include <ofstream>
#include <stdio.h>
#include <stdarg.h>
namespace ppcStreams
{
/**************************************************************/
ofstream::ofstream()
/**************************************************************/
{
_fileHandle = NULL;
}
/**************************************************************/
ofstream::ofstream(string filename)
/**************************************************************/
{
open(filename);
}
/**************************************************************/
ofstream::~ofstream()
/**************************************************************/
{
}
/**************************************************************/
int ofstream::OutFunction(const char* format, ...)
/**************************************************************/
{
va_list argList;
va_start(argList, format);
return(fprintf(_fileHandle, format, va_arg(argList, double))); //Sloppy, stack manip problems
}
/**************************************************************/
bool ofstream::operator==(bool val)
/**************************************************************/
{
return(is_open()==val);
}
/**************************************************************/
ofstream::operator void*()
/**************************************************************/
{
if (is_open())
return ((void*)this);
else
return NULL;
}
/**************************************************************/
int ofstream::eof()
/**************************************************************/
{
return(feof(_fileHandle));
}
/**************************************************************/
bool ofstream::open(string filename, ios::openmode mode)
/**************************************************************/
{
if (mode==ios::out)
_fileHandle = fopen(filename.c_str(), "w");
else if (mode == ios::app)
_fileHandle = fopen(filename.c_str(), "a");
else if (mode == (ios::app | ios::out))
_fileHandle = fopen(filename.c_str(), "a");
else //Invalid open mode for an output stream
{
_fileHandle = NULL;
throw;
}
return (is_open());
}
/**************************************************************/
bool ofstream::is_open()
/**************************************************************/
{
if (_fileHandle!=NULL)
return true;
else
return false;
}
/**************************************************************/
void ofstream::close()
/**************************************************************/
{
if(_fileHandle!=NULL)
fclose(_fileHandle);
}
}; /*end namespace ppcStreams*/