Beatmup
chunk_collection.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 
21 #include <pybind11/pytypes.h>
22 #include <map>
23 #include <string>
24 
25 #include "utils/chunkfile.h"
26 #include "context.h"
27 
28 namespace Beatmup {
29  namespace Python {
30 
31  /**
32  Writable ChunkCollection implementation for Python.
33  Allows to exchange binary data without copying.
34  */
36  private:
37  std::map<std::string, pybind11::buffer> data;
38 
39  public:
41 
42  inline pybind11::buffer& operator[](const std::string& id) {
43  return data[id];
44  }
45 
46  inline void open() {}
47  inline void close() {}
48 
49  inline size_t size() const { return data.size(); }
50 
51  inline bool chunkExists(const std::string& id) const { return data.find(id) != data.cend(); }
52 
53  chunksize_t chunkSize(const std::string& id) const;
54 
55  chunksize_t fetch(const std::string& id, void* data, const chunksize_t limit);
56 
57  void save(const std::string& filename, bool append = false);
58  };
59 
60  }
61 }
A key-value pair set storing pieces of arbitrary data (chunks) under string keys.
Definition: chunkfile.h:36
Writable ChunkCollection implementation for Python.
pybind11::buffer & operator[](const std::string &id)
void open()
Opens the collection to read chunks from it.
bool chunkExists(const std::string &id) const
Check if a specific chunk exists.
size_t size() const
Returns the number of chunks available in the collection after it is opened.
std::map< std::string, pybind11::buffer > data
chunksize_t chunkSize(const std::string &id) const
Retrieves size of a specific chunk.
chunksize_t fetch(const std::string &id, void *data, const chunksize_t limit)
Reads a chunk.
void close()
Closes the collection after a reading session.
void save(const std::string &filename, bool append=false)
Saves the collection to a file.
uint32_t chunksize_t
Definition: chunkfile.h:29
JNIEnv jlong jstring id
JNIEnv jlong jstring filename
JNIEnv jlong jstring jboolean append