Beatmup
input_stream.h
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
#pragma once
20
#include "../basic_types.h"
21
#include <fstream>
22
23
namespace
Beatmup
{
24
/**
25
Minimal input stream interface
26
*/
27
class
InputStream
{
28
public
:
29
/**
30
Reads a given number of bytes into a specific memory location.
31
\param[in] buffer The address to store the data to
32
\param[in] bytes Number of bytes to read
33
\return `true` on success.
34
*/
35
virtual
bool
operator()
(
void
* buffer,
msize
bytes) = 0;
36
37
/**
38
Moves the read pointer to a given position in the stream.
39
\param pos The position in bytes from the beginning of the stream
40
\return `true` on success.
41
*/
42
virtual
bool
seek
(
msize
pos) = 0;
43
44
/**
45
Returns `true`, if the end of the stream is reached (i.e., all the data is read or the stream is empty).
46
*/
47
virtual
bool
eof
()
const
= 0;
48
};
49
50
51
/**
52
InputStream reading from a file
53
*/
54
class
FileInputStream
:
public
InputStream
{
55
private
:
56
std::ifstream
stream
;
57
public
:
58
FileInputStream
();
59
inline
FileInputStream
(
const
char
*
filename
) {
open
(
filename
); }
60
61
bool
isOpen
()
const
;
62
void
open
(
const
char
*
filename
);
63
void
close
();
64
void
clear
();
65
66
bool
operator()
(
void
* buffer,
msize
bytes);
67
bool
seek
(
msize
pos);
68
bool
eof
()
const
;
69
};
70
71
72
/**
73
InputStream reading from memory
74
*/
75
class
MemoryInputStream
:
public
InputStream
{
76
private
:
77
const
char
*
data
;
78
const
msize
size
;
79
msize
ptr
;
80
public
:
81
inline
MemoryInputStream
(
const
void
*
data
,
msize
size
):
data
(static_cast<const char*>(
data
)),
size
(
size
),
ptr
(0) {}
82
83
bool
operator()
(
void
* buffer,
msize
bytes);
84
bool
seek
(
msize
pos);
85
bool
eof
()
const
;
86
};
87
}
Beatmup::FileInputStream
InputStream reading from a file.
Definition:
input_stream.h:54
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(const char *filename)
Definition:
input_stream.h:59
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::InputStream
Minimal input stream interface.
Definition:
input_stream.h:27
Beatmup::InputStream::seek
virtual bool seek(msize pos)=0
Moves the read pointer to a given position in the stream.
Beatmup::InputStream::operator()
virtual bool operator()(void *buffer, msize bytes)=0
Reads a given number of bytes into a specific memory location.
Beatmup::InputStream::eof
virtual bool eof() const =0
Returns true, if the end of the stream is reached (i.e., all the data is read or the stream is empty)...
Beatmup::MemoryInputStream
InputStream reading from memory.
Definition:
input_stream.h:75
Beatmup::MemoryInputStream::MemoryInputStream
MemoryInputStream(const void *data, msize size)
Definition:
input_stream.h:81
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
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
core
utils
input_stream.h
Generated on Tue Nov 21 2023 13:54:27 for Beatmup by
1.9.1