Grok 12.0.1
SparseBuffer.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016-2024 Grok Image Compression Inc.
3 *
4 * This source code is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License, version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This source code is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Affero General Public License for more details.
12 *
13 * You should have received a copy of the GNU Affero General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17#include <vector>
18
19#pragma once
20namespace grk
21{
22/* SparseBuffer
23
24 Manage a list of buffers, which can be treated as one single
25 contiguous buffer.
26 */
28{
31 grk_buf8* pushBack(uint8_t* buf, size_t len, bool ownsData);
32 void incrementCurrentChunkOffset(size_t offset);
33 size_t getCurrentChunkLength(void);
34 // Treat segmented buffer as single contiguous buffer, and get current pointer
36 // Reset all offsets to zero, and set current chunk to beginning of list
37 void rewind(void);
38 size_t skip(size_t numBytes);
39 void increment(void);
40 size_t read(void* buffer, size_t numBytes);
41 size_t totalLength(void) const;
42
43 private:
44 // Treat segmented buffer as single contiguous buffer, and get current offset
45 size_t getGlobalOffset(void);
46 // Copy all chunks, in sequence, into contiguous array
47 bool copyToContiguousBuffer(uint8_t* buffer);
48 // Clean up internal resources
49 void cleanup(void);
50 size_t getCurrentChunkOffset(void);
51 void pushBack(grk_buf8* chunk);
52 size_t dataLen; /* total length of all chunks*/
53 size_t currentChunkId; /* current index into chunk vector */
54 std::vector<grk_buf8*> chunks;
56};
57
58} // namespace grk
Copyright (C) 2016-2024 Grok Image Compression Inc.
Definition ICacheable.h:20
void grk_read(const uint8_t *buffer, TYPE *value, uint32_t numBytes)
Definition BufferedStream.h:239
Definition SparseBuffer.h:28
void rewind(void)
Definition SparseBuffer.cpp:129
~SparseBuffer()
Definition SparseBuffer.cpp:24
grk_buf8 * pushBack(uint8_t *buf, size_t len, bool ownsData)
Definition SparseBuffer.cpp:108
SparseBuffer()
Definition SparseBuffer.cpp:23
size_t getCurrentChunkOffset(void)
Definition SparseBuffer.cpp:177
size_t totalLength(void) const
Definition SparseBuffer.cpp:41
size_t read(void *buffer, size_t numBytes)
Definition SparseBuffer.cpp:45
size_t dataLen
Definition SparseBuffer.h:52
void cleanup(void)
Definition SparseBuffer.cpp:123
bool reachedEnd_
Definition SparseBuffer.h:55
void increment(void)
Definition SparseBuffer.cpp:28
size_t currentChunkId
Definition SparseBuffer.h:53
bool copyToContiguousBuffer(uint8_t *buffer)
Definition SparseBuffer.cpp:153
uint8_t * getCurrentChunkPtr(void)
Definition SparseBuffer.cpp:167
size_t getGlobalOffset(void)
Definition SparseBuffer.cpp:182
void incrementCurrentChunkOffset(size_t offset)
Definition SparseBuffer.cpp:140
std::vector< grk_buf8 * > chunks
Definition SparseBuffer.h:54
size_t getCurrentChunkLength(void)
Definition SparseBuffer.cpp:172
size_t skip(size_t numBytes)
Definition SparseBuffer.cpp:77