Debian Codegraph @

mednafen/Stream.h

raw symbols SCIP
1 #cxx . . $ `<file>/mednafen/Stream.h`/ifndef __MDFN_STREAM_H
2 #define __MDFN_STREAM_Hcxx . . $ `mednafen/Stream.h:2:9`!
3
4 // TODO/WIP
5
6 // TODO?: BufferedStream, no virtual functions, yes inline functions, constructor takes a Stream* argument.
7
8 #include "mednafen.h"cxx . . $ `<file>/mednafen/mednafen.h`/
9 #include <errno.h>
10
11 #include <stdio.h> // For SEEK_* defines, which we will use in Stream out of FORCE OF HABIT.
12
13 #define MODE_READcxx . . $ `mednafen/Stream.h:13:9`! 0
14 #define MODE_WRITEcxx . . $ `mednafen/Stream.h:14:9`! 1
15 #define MODE_WRITE_SAFEcxx . . $ `mednafen/Stream.h:15:9`! 2
16
17 class Streamcxx . . $ Stream#
18 {
19 public:
20
21 Streamcxx . . $ Stream#Stream(49f6e7a06ebc5aa8).();
22 virtual ~cxx . . $ Stream#`~Stream`(49f6e7a06ebc5aa8).Streamcxx . . $ Stream#();
23
24 enumcxx . . $ Stream#$anonymous_type_0#
25 {
26 ATTRIBUTE_READABLEcxx . . $ Stream#ATTRIBUTE_READABLE. = 0,
27 ATTRIBUTE_WRITEABLEcxx . . $ Stream#ATTRIBUTE_WRITEABLE.,
28 ATTRIBUTE_SEEKABLEcxx . . $ Stream#ATTRIBUTE_SEEKABLE.
29 };
30 virtual uint64cxx . . $ uint64# attributescxx . . $ Stream#attributes(f708dce9a8856c70).(void) = 0;
31
32 virtual uint64cxx . . $ uint64# readcxx . . $ Stream#read(a1f03d5c460544d4).(void *data, uint64cxx . . $ uint64# count, bool error_on_eos = true) = 0;
33 virtual void writecxx . . $ Stream#write(8c7266571c1d65cc).(const void *data, uint64cxx . . $ uint64# count) = 0;
34
35 virtual void seekcxx . . $ Stream#seek(3b75d2d14f60ac6a).(int64cxx . . $ int64# offset, int whence) = 0;
36 virtual int64cxx . . $ int64# tellcxx . . $ Stream#tell(da6335ded91d79c2).(void) = 0;
37 virtual int64cxx . . $ int64# sizecxx . . $ Stream#size(da6335ded91d79c2).(void) = 0;
38 virtual void closecxx . . $ Stream#close(49f6e7a06ebc5aa8).(void) = 0; // Flushes(in the case of writeable streams) and closes the stream.
39 // Necessary since this operation can fail(running out of disk space, for instance),
40 // and throw an exception in the destructor would be a Bad Idea(TM).
41 //
42 // Manually calling this function isn't strictly necessary, but recommended when the
43 // stream is writeable; it will be called automatically from the destructor, with any
44 // exceptions thrown caught and logged.
45
46 //
47 // Utility functions(TODO):
48 //
49 INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint8cxx . . $ uint8# get_u8cxx . . $ Stream#get_u8(7c4be072098b358f).(void)
50 {
51 uint8cxx . . $ uint8# ret;
52
53 readcxx . . $ Stream#read(a1f03d5c460544d4).(&ret, sizeof(ret));
54
55 return ret;
56 }
57
58 INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void put_u8cxx . . $ Stream#put_u8(ac50b47256ae7414).(uint8cxx . . $ uint8# c)
59 {
60 writecxx . . $ Stream#write(8c7266571c1d65cc).(&c, sizeof(c));
61 }
62
63
64 template<typename T>
65 INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! T get_NEcxx . . $ Stream#get_NE(5f357b03ed472e5e).(void)
66 {
67 T ret;
68
69 readcxx . . $ Stream#read(a1f03d5c460544d4).(&ret, sizeof(ret));
70
71 return ret;
72 }
73
74 template<typename T>
75 INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void put_NEcxx . . $ Stream#put_NE(9b289cee16747614).(T c)
76 {
77 writecxx . . $ Stream#write(8c7266571c1d65cc).(&c, sizeof(c));
78 }
79
80
81 template<typename T>
82 INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! T get_REcxx . . $ Stream#get_RE(5f357b03ed472e5e).(void)
83 {
84 uint8cxx . . $ uint8# tmp[sizeof(T)];
85 T ret = 0;
86
87 readcxx . . $ Stream#read(a1f03d5c460544d4).(tmp, sizeof(tmp));
88
89 for(unsigned i = 0; i < sizeof(T); i++)
90 ret |= (T)tmp[i] << (i * 8);
91
92 return ret;
93 }
94
95 template<typename T>
96 INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void put_REcxx . . $ Stream#put_RE(9b289cee16747614).(T c)
97 {
98 uint8cxx . . $ uint8# tmp[sizeof(T)];
99
100 for(unsigned i = 0; i < sizeof(T); i++)
101 tmp[i] = ((uint8cxx . . $ uint8# *)&c)[sizeof(T) - 1 - i];
102
103 writecxx . . $ Stream#write(8c7266571c1d65cc).(tmp, sizeof(tmp));
104 }
105
106 template<typename T>
107 INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! T get_LEcxx . . $ Stream#get_LE(5f357b03ed472e5e).(void)
108 {
109 #ifdef MSB_FIRST
110 return get_RE<T>();
111 #else
112 return get_NEcxx . . $ Stream#get_NE(5f357b03ed472e5e).<T>();
113 #endif
114 }
115
116 template<typename T>
117 INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void put_LEcxx . . $ Stream#put_LE(9b289cee16747614).(T c)
118 {
119 #ifdef MSB_FIRST
120 return put_RE<T>(c);
121 #else
122 return put_NEcxx . . $ Stream#put_NE(9b289cee16747614).<T>(c);
123 #endif
124 }
125
126 template<typename T>
127 INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! T get_BEcxx . . $ Stream#get_BE(5f357b03ed472e5e).(void)
128 {
129 #ifdef MSB_FIRST
130 return get_NE<T>();
131 #else
132 return get_REcxx . . $ Stream#get_RE(5f357b03ed472e5e).<T>();
133 #endif
134 }
135
136 template<typename T>
137 INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void put_BEcxx . . $ Stream#put_BE(9b289cee16747614).(T c)
138 {
139 #ifdef MSB_FIRST
140 return put_NE<T>(c);
141 #else
142 return put_REcxx . . $ Stream#put_RE(9b289cee16747614).<T>(c);
143 #endif
144 }
145
146 // Reads a line into "str", overwriting its contents; returns the line-end char('\n' or '\r' or '\0'), or -1 on EOF.
147 // The line-end char won't be added to "str".
148 // It's up to the caller to handle extraneous empty lines caused by DOS-format text lines(\r\n).
149 // ("str" is passed by reference for the possibility of improved performance by reusing alloced memory for the std::string, though part
150 // of it would be up to the STL implementation).
151 // Implemented as virtual so that a higher-performance version can be implemented if possible(IE with MemoryStream)
152 virtual int get_linecxx . . $ Stream#get_line(9b8588921b9c6c2f).(stdcxx . . $ std/::stringcxx . . $ std/string# &str);
153 };
154 #endif