13#ifndef EFORMAT_PAGEDMEMORY_H
14#define EFORMAT_PAGEDMEMORY_H
26#define CAST32(x) reinterpret_cast<const uint32_t*>(x)
66 inline const struct iovec*
pages (
void)
const {
return m_iovec; }
71 inline size_t count (
void)
const {
return m_count; }
76 inline size_t size (
void)
const {
return m_size; }
116 : m_node(node), m_off(offset) {}
133 : m_node(other.m_node), m_off(other.m_off) {}
160 {
return !(*
this != other); }
175 uint32_t
at (
size_t pos)
const;
217 {
return m_off < other.m_off; }
225 {
return m_off > other.m_off; }
233 {
return (int32_t)m_off - (int32_t)other.m_off; }
262 const struct iovec* m_iovec;
264 node_t m_node[TMAXPAGES];
271template <
unsigned int TMAXPAGES>
const unsigned int
275(
const struct iovec* pages,
size_t count)
284 for (
size_t i=0; i<
count; ++i) {
286 if (
pages[i].iov_len % 4 != 0) {
290 m_node[i].
start = m_size;
291 m_size +=
pages[i].iov_len >> 2;
292 m_node[i].
end = m_size;
293 if (i > 0) m_node[i].
previous = &m_node[i-1];
295 if (i < (
count-1) ) m_node[i].
next = &m_node[i+1];
296 else m_node[i].
next = 0;
304 m_node = other.m_node;
309template <
unsigned int TMAXPAGES>
313 return (m_node == other.m_node && m_off == other.m_off)?
false:
true;
316template <
unsigned int TMAXPAGES>
320 if (m_off + pos < m_node->end) {
321 return CAST32(m_node->page->iov_base)[(m_off+pos)-m_node->start];
329template <
unsigned int TMAXPAGES>
333 if (m_off + pos < m_node->end) {
334 return CAST32(m_node->page->iov_base)[(m_off+pos)-m_node->start];
338 if (!m_node || (m_node->next == 0 && (m_off+pos) >= m_node->end))
352 if ( m_off >= (m_node->end) ) {
357 m_node = m_node->next;
358 m_off = m_node->start;
367 if ( m_off < (m_node->start) ) {
368 if (!m_node->previous) {
369 m_off = m_node->start;
372 m_node = m_node->previous;
373 m_off = m_node->end - 1;
381 size_t aim = offset + m_off;
382 while (aim >= (m_node->end)) {
383 if (m_node->next) m_node = m_node->next;
396 size_t aim = m_off - offset;
397 while (aim < (m_node->start)) {
398 if (m_node->previous) m_node = m_node->previous;
400 m_off = m_node->start;
Describes the exception where some chunk of memory is not 32-bit aligned.
#define EFORMAT_NOT_ALIGNED(base, size)
Out of bounds exception when trying to read beyond existing buffers.
#define EFORMAT_OUT_OF_BOUNDS(size, pos)
Describes an exception that happens when the total number of blocks I'm managing is bigger than the o...
#define EFORMAT_TOO_BIG_COUNT(count, maxcount)
DOUBLE_PRECISION count[3]
uint32_t operator[](size_t pos) const
bool operator!=(const const_iterator &other) const
const_iterator & operator=(const const_iterator &other)
const_iterator(const const_iterator &other)
const_iterator & operator+=(size_t offset)
const_iterator & operator++(void)
const_iterator & operator--()
uint32_t at(size_t pos) const
bool operator==(const const_iterator &other) const
uint32_t operator*(void) const
const_iterator & operator-=(size_t offset)
bool operator>(const const_iterator &other) const
bool operator<(const const_iterator &other) const
int32_t operator-(const const_iterator &other) const
PagedMemory(const struct iovec *pages, size_t count)
const struct iovec * pages(void) const
static const unsigned int MAXPAGES
const_iterator begin(void) const
const_iterator end(void) const
const struct iovec * page
Defines a set of utilities common to many event operations.