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