Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/psx/octoshock/Stream.cpp
2 views
1
// TODO/WIP
2
3
/* Mednafen - Multi-system Emulator
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*/
19
20
#include "octoshock.h"
21
#include "Stream.h"
22
23
//#include <trio/trio.h>
24
25
Stream::Stream()
26
{
27
28
}
29
30
Stream::~Stream()
31
{
32
33
}
34
35
void Stream::put_line(const std::string& str)
36
{
37
char l = '\n';
38
39
write(&str[0], str.size());
40
write(&l, sizeof(l));
41
}
42
43
44
void Stream::print_format(const char *format, ...)
45
{
46
//char *str = NULL;
47
//int rc;
48
49
//va_list ap;
50
51
//va_start(ap, format);
52
53
//rc = trio_vasprintf(&str, format, ap);
54
55
//va_end(ap);
56
57
//if(rc < 0)
58
// throw MDFN_Error(0, "Error in trio_vasprintf()");
59
//else
60
//{
61
// try // Bleck
62
// {
63
// write(str, rc);
64
// }
65
// catch(...)
66
// {
67
// free(str);
68
// throw;
69
// }
70
// free(str);
71
//}
72
}
73
74
int Stream::get_line(std::string &str)
75
{
76
uint8 c;
77
78
str.clear(); // or str.resize(0)??
79
80
while(read(&c, sizeof(c), false) > 0)
81
{
82
if(c == '\r' || c == '\n' || c == 0)
83
return(c);
84
85
str.push_back(c);
86
}
87
88
return(str.length() ? 256 : -1);
89
}
90
91
StreamFilter::StreamFilter()
92
{
93
target_stream = NULL;
94
}
95
96
StreamFilter::StreamFilter(Stream *target_arg)
97
{
98
target_stream = target_arg;
99
}
100
101
StreamFilter::~StreamFilter()
102
{
103
if(target_stream)
104
delete target_stream;
105
}
106
107
Stream* StreamFilter::steal(void)
108
{
109
Stream *ret = target_stream;
110
target_stream = NULL;
111
return ret;
112
}
113
114