-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.cpp
137 lines (121 loc) · 2.58 KB
/
data.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/**
* Data.cpp -
* @author: Jonathan Beard
* @version: Mon Feb 18 17:39:01 2013
*/
#include <cstdlib>
#include <cstring>
#include "data.hpp"
#include "cpp_output_handler.hpp"
#include "options_vars.hpp"
/* default namespace for Raft */
using namespace Raft;
Data::Data()
: rf_parsestream( nullptr ),
rf_errorstream( nullptr ),
userstream( std::cout ),
errorstream( std::cerr ),
cpp_handler( nullptr )
{
rf_parsestream = new RFParseStream();
rf_errorstream = new RFErrorStream();
cpp_handler = new CPP_OutputHandler( (*this) );
}
Data::~Data()
{
if( rf_errorstream != nullptr )
{
delete( rf_errorstream );
rf_errorstream = nullptr;
}
if( rf_parsestream != nullptr )
{
delete( rf_parsestream );
rf_parsestream = nullptr;
}
if( cpp_handler != nullptr )
{
delete( cpp_handler );
cpp_handler = nullptr;
}
}
void Data::Final()
{
if( rf_errorstream != nullptr )
{
errorstream << "The following system error(s) were detected:\n";
errorstream << (*rf_errorstream).str() << "\n";
errorstream << "Done with errorstream." << std::endl; /* just in case std::out */
exit( EXIT_FAILURE );
}
else
{
exit( EXIT_SUCCESS );
}
}
std::ostream& Data::PrintErrors( std::ostream &stream )
{
stream << get_rf_errorstream().str() << "\n";
return( stream );
}
std::ostream& Data::PrintParseErrors( std::ostream &stream )
{
stream << get_rf_parsestream().str() << "\n";
return( stream );
}
void Data::reset_rf_parsestream()
{
if( rf_parsestream != nullptr )
{
delete( rf_parsestream );
rf_parsestream = nullptr;
}
assert( rf_parsestream == nullptr );
}
RFParseStream& Data::get_rf_parsestream()
{
if( rf_parsestream == nullptr )
{
rf_parsestream = new RFParseStream();
}
return( (*rf_parsestream) );
}
void Data::reset_rf_errorstream()
{
if( rf_errorstream != nullptr )
{
delete( rf_errorstream );
rf_errorstream = nullptr;
}
}
RFErrorStream& Data::get_rf_errorstream()
{
if( rf_errorstream == nullptr )
{
rf_errorstream = new RFErrorStream();
}
return( (*rf_errorstream) );
}
UserStream& Data::get_userstream()
{
return( userstream );
}
ErrorStream& Data::get_errorstream()
{
return( errorstream );
}
CPP_OutputHandler&
Data::get_cpp_handler()
{
return( *cpp_handler );
}
void Data::set_options_vars( Options_Vars *vars )
{
assert( vars != nullptr );
(this)->options = vars;
}
Options_Vars& Data::get_options_vars()
{
assert( (this)->options != nullptr );
return( (*(this)->options) );
}