Beatmup
input_stream.cpp
Go to the documentation of this file.
1
/*
2
Beatmup image and signal processing library
3
Copyright (C) 2020, lnstadrum
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 3 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, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#include "
input_stream.h
"
20
#include <cstring>
21
22
using namespace
Beatmup
;
23
24
FileInputStream::FileInputStream
() {}
25
26
27
bool
FileInputStream::isOpen
()
const
{
28
return
stream
.is_open();
29
}
30
31
void
FileInputStream::open
(
const
char
*
filename
) {
32
stream
.open(
filename
, std::ios::in | std::ios::binary);
33
}
34
35
void
FileInputStream::close
() {
36
stream
.close();
37
}
38
39
void
FileInputStream::clear
() {
40
stream
.clear();
41
}
42
43
44
bool
FileInputStream::operator()
(
void
*buffer,
msize
bytes) {
45
stream
.read((
char
*)buffer, bytes);
46
return
stream
.good();
47
}
48
49
bool
FileInputStream::seek
(
msize
pos) {
50
stream
.seekg(pos);
51
return
stream
.good();
52
}
53
54
bool
FileInputStream::eof
()
const
{
55
return
stream
.eof();
56
}
57
58
59
bool
MemoryInputStream::operator()
(
void
* buffer,
msize
bytes) {
60
const
msize
step
=
ptr
+ bytes <
size
? bytes :
size
-
ptr
;
61
memcpy(buffer,
data
+
ptr
,
step
);
62
ptr
+=
step
;
63
return
step
== bytes;
64
}
65
66
bool
MemoryInputStream::seek
(
msize
pos) {
67
if
(pos <
size
)
68
ptr
= pos;
69
return
pos <
size
;
70
}
71
72
bool
MemoryInputStream::eof
()
const
{
73
return
ptr
>=
size
;
74
}
Beatmup::FileInputStream::stream
std::ifstream stream
Definition:
input_stream.h:56
Beatmup::FileInputStream::clear
void clear()
Definition:
input_stream.cpp:39
Beatmup::FileInputStream::close
void close()
Definition:
input_stream.cpp:35
Beatmup::FileInputStream::isOpen
bool isOpen() const
Definition:
input_stream.cpp:27
Beatmup::FileInputStream::eof
bool eof() const
Returns true, if the end of the stream is reached (i.e., all the data is read or the stream is empty)...
Definition:
input_stream.cpp:54
Beatmup::FileInputStream::open
void open(const char *filename)
Definition:
input_stream.cpp:31
Beatmup::FileInputStream::FileInputStream
FileInputStream()
Definition:
input_stream.cpp:24
Beatmup::FileInputStream::operator()
bool operator()(void *buffer, msize bytes)
Reads a given number of bytes into a specific memory location.
Definition:
input_stream.cpp:44
Beatmup::FileInputStream::seek
bool seek(msize pos)
Moves the read pointer to a given position in the stream.
Definition:
input_stream.cpp:49
Beatmup::MemoryInputStream::data
const char * data
Definition:
input_stream.h:77
Beatmup::MemoryInputStream::eof
bool eof() const
Returns true, if the end of the stream is reached (i.e., all the data is read or the stream is empty)...
Definition:
input_stream.cpp:72
Beatmup::MemoryInputStream::size
const msize size
Definition:
input_stream.h:78
Beatmup::MemoryInputStream::ptr
msize ptr
Definition:
input_stream.h:79
Beatmup::MemoryInputStream::seek
bool seek(msize pos)
Moves the read pointer to a given position in the stream.
Definition:
input_stream.cpp:66
Beatmup::MemoryInputStream::operator()
bool operator()(void *buffer, msize bytes)
Reads a given number of bytes into a specific memory location.
Definition:
input_stream.cpp:59
input_stream.h
Beatmup
Definition:
basic_types.h:22
Beatmup::msize
uint32_t msize
memory size
Definition:
basic_types.h:30
filename
JNIEnv jlong jstring filename
Definition:
wrapper_core.cpp:616
step
jlong jint jfloat step
Definition:
wrapper_imag.cpp:869
core
utils
input_stream.cpp
Generated on Tue Nov 21 2023 13:54:27 for Beatmup by
1.9.1