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 
25 
26 
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 
36  stream.close();
37 }
38 
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 
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 
67  if (pos < size)
68  ptr = pos;
69  return pos < size;
70 }
71 
72 bool MemoryInputStream::eof() const {
73  return ptr >= size;
74 }
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)...
void open(const char *filename)
bool operator()(void *buffer, msize bytes)
Reads a given number of bytes into a specific memory location.
bool seek(msize pos)
Moves the read pointer to a given position in the stream.
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)...
bool seek(msize pos)
Moves the read pointer to a given position in the stream.
bool operator()(void *buffer, msize bytes)
Reads a given number of bytes into a specific memory location.
uint32_t msize
memory size
Definition: basic_types.h:30
JNIEnv jlong jstring filename
jlong jint jfloat step