mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 21:13:35 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
46
coding/reader_wrapper.hpp
Normal file
46
coding/reader_wrapper.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "coding/reader.hpp"
|
||||
|
||||
|
||||
/// Reader wrapper to avoid penalty on copy and polymorphic SubReader creation.
|
||||
template <class ReaderT> class SubReaderWrapper
|
||||
{
|
||||
ReaderT * m_p;
|
||||
uint64_t m_pos;
|
||||
uint64_t m_size;
|
||||
|
||||
protected:
|
||||
SubReaderWrapper(ReaderT * p, uint64_t pos, uint64_t size)
|
||||
: m_p(p), m_pos(pos), m_size(size)
|
||||
{
|
||||
ASSERT_LESS_OR_EQUAL ( pos + size, m_p->Size(), (pos, size) );
|
||||
}
|
||||
|
||||
public:
|
||||
explicit SubReaderWrapper(ReaderT * p) : m_p(p), m_pos(0), m_size(p->Size()) {}
|
||||
|
||||
uint64_t Size() const { return m_size; }
|
||||
|
||||
void Read(uint64_t pos, void * p, size_t size) const
|
||||
{
|
||||
ASSERT_LESS_OR_EQUAL ( pos + size, m_size, (pos, size) );
|
||||
m_p->Read(pos + m_pos, p, size);
|
||||
}
|
||||
|
||||
SubReaderWrapper SubReader(uint64_t pos, uint64_t size) const
|
||||
{
|
||||
return SubReaderWrapper(m_p, pos + m_pos, size);
|
||||
}
|
||||
};
|
||||
|
||||
/// Non template reader source for regular functions with incapsulated implementation.
|
||||
class ReaderSrc : public ReaderSource<SubReaderWrapper<Reader>>
|
||||
{
|
||||
typedef SubReaderWrapper<Reader> ReaderT;
|
||||
typedef ReaderSource<ReaderT> BaseT;
|
||||
|
||||
public:
|
||||
explicit ReaderSrc(Reader & reader) : BaseT(ReaderT(&reader)) {}
|
||||
explicit ReaderSrc(Reader * reader) : BaseT(ReaderT(reader)) {}
|
||||
};
|
||||
Reference in New Issue
Block a user