eformat::PagedMemory< TMAXPAGES >::const_iterator Class Reference

#include <PagedMemory.h>

List of all members.

Public Member Functions

 const_iterator ()
 const_iterator (const const_iterator &other)
 ~const_iterator ()
const_iteratoroperator= (const const_iterator &other)
bool operator!= (const const_iterator &other) const
bool operator== (const const_iterator &other) const
uint32_t operator[] (size_t pos) const
uint32_t at (size_t pos) const
uint32_t operator * (void) const
const_iteratoroperator++ (void)
const_iteratoroperator-- ()
const_iteratoroperator+= (size_t offset)
const_iteratoroperator-= (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

Private Member Functions

 const_iterator (const node_t *node, size_t offset)

Private Attributes

const node_tm_node
 base address of the index table
size_t m_off
 the current offset, in 32-bit words

Friends

class PagedMemory


Detailed Description

template<unsigned int TMAXPAGES = 128>
class eformat::PagedMemory< TMAXPAGES >::const_iterator

Defines an iterator-like type for this type of memory. There are no guarantees on the iteration. The user should test and only iterate from begin() till end()

Definition at line 101 of file PagedMemory.h.


Constructor & Destructor Documentation

template<unsigned int TMAXPAGES = 128>
eformat::PagedMemory< TMAXPAGES >::const_iterator::const_iterator ( const node_t node,
size_t  offset 
) [inline, private]

Builds a new iterator giving an index and an offset inside that index.

Parameters:
base The base address of the memory block being pointed now
size The total size of this block, in 32-bit words
offset The offset to where I should point to, in 32-bit words

Definition at line 115 of file PagedMemory.h.

00116         : m_node(node), m_off(offset) {}

template<unsigned int TMAXPAGES = 128>
eformat::PagedMemory< TMAXPAGES >::const_iterator::const_iterator (  )  [inline]

Returns an iterator that points nowhere, to fake similar behaviour as the normal pointers.

Definition at line 125 of file PagedMemory.h.

00125 : m_node(), m_off() {}

template<unsigned int TMAXPAGES = 128>
eformat::PagedMemory< TMAXPAGES >::const_iterator::const_iterator ( const const_iterator other  )  [inline]

Copies the value of an iterator

Parameters:
other The iterator to copy the data from

Definition at line 132 of file PagedMemory.h.

00133         : m_node(other.m_node), m_off(other.m_off) {}

template<unsigned int TMAXPAGES = 128>
eformat::PagedMemory< TMAXPAGES >::const_iterator::~const_iterator (  )  [inline]

Destroys an iterator

Definition at line 138 of file PagedMemory.h.

00138 {}


Member Function Documentation

template<unsigned int TMAXPAGES>
uint32_t eformat::PagedMemory< TMAXPAGES >::const_iterator::at ( size_t  pos  )  const

Gets a value away N positions from this iterator, checked and may throw an exception

Parameters:
pos The number "N" of positions away from this iterator

Definition at line 330 of file PagedMemory.h.

References eformat::PagedMemory< TMAXPAGES >::const_iterator::at(), CAST32, EFORMAT_OUT_OF_BOUNDS, eformat::PagedMemory< TMAXPAGES >::node_t::end, eformat::PagedMemory< TMAXPAGES >::end(), eformat::PagedMemory< TMAXPAGES >::const_iterator::m_node, eformat::PagedMemory< TMAXPAGES >::const_iterator::m_off, eformat::PagedMemory< TMAXPAGES >::node_t::next, eformat::PagedMemory< TMAXPAGES >::node_t::page, and eformat::PagedMemory< TMAXPAGES >::node_t::start.

Referenced by eformat::PagedMemory< TMAXPAGES >::const_iterator::at().

00331 {
00332   //immediate return (most of the cases)
00333   if (m_off + pos < m_node->end) { //trying to reach data on the current page
00334     return CAST32(m_node->page->iov_base)[(m_off+pos)-m_node->start];
00335   }
00336 
00337   //immediate points of failure
00338   if (!m_node || (m_node->next == 0 && (m_off+pos) >= m_node->end))
00339     throw EFORMAT_OUT_OF_BOUNDS(0, pos << 2);
00340 
00341   //if I get here, the data is on another page and the request might still be
00342   //out of bounds, so watch.
00343   const_iterator it = *this;
00344   it += pos;
00345   return it.at(0);
00346 }

template<unsigned int TMAXPAGES = 128>
uint32_t eformat::PagedMemory< TMAXPAGES >::const_iterator::operator * ( void   )  const [inline]

Gets the current value for the pointed position, as a 32-bit integer. This is unchecked so you have to make sure you are before end().

Definition at line 182 of file PagedMemory.h.

References CAST32, eformat::PagedMemory< TMAXPAGES >::const_iterator::m_node, eformat::PagedMemory< TMAXPAGES >::const_iterator::m_off, eformat::PagedMemory< TMAXPAGES >::node_t::page, and eformat::PagedMemory< TMAXPAGES >::node_t::start.

00183       { return CAST32(m_node->page->iov_base)[m_off-m_node->start]; }

template<unsigned int TMAXPAGES = 128>
bool eformat::PagedMemory< TMAXPAGES >::const_iterator::operator!= ( const const_iterator other  )  const

Compares two pointers

Parameters:
other The other iterator to compare this one with.

template<unsigned int TMAXPAGES>
eformat::PagedMemory< TMAXPAGES >::const_iterator & eformat::PagedMemory< TMAXPAGES >::const_iterator::operator++ ( void   ) 

Advances forward on the pointing place, 4 bytes or 1 word. This is the prefix operator.

Definition at line 349 of file PagedMemory.h.

References eformat::PagedMemory< TMAXPAGES >::node_t::end, eformat::PagedMemory< TMAXPAGES >::const_iterator::m_node, eformat::PagedMemory< TMAXPAGES >::const_iterator::m_off, eformat::PagedMemory< TMAXPAGES >::node_t::next, and eformat::PagedMemory< TMAXPAGES >::node_t::start.

00350 { 
00351   ++m_off;
00352   if ( m_off >= (m_node->end) ) {
00353     if (!m_node->next) { //it was the last
00354       m_off = m_node->end;
00355       return *this;
00356     }
00357     m_node = m_node->next;
00358     m_off = m_node->start;
00359   }
00360   return *this; 
00361 }

template<unsigned int TMAXPAGES>
eformat::PagedMemory< TMAXPAGES >::const_iterator & eformat::PagedMemory< TMAXPAGES >::const_iterator::operator+= ( size_t  offset  ) 

Advances forward on the pointing place, by a number of (32-bit) words

Parameters:
offset The amount of words to advance

Definition at line 379 of file PagedMemory.h.

References eformat::PagedMemory< TMAXPAGES >::node_t::end, eformat::PagedMemory< TMAXPAGES >::const_iterator::m_node, eformat::PagedMemory< TMAXPAGES >::const_iterator::m_off, and eformat::PagedMemory< TMAXPAGES >::node_t::next.

00380 {
00381   size_t aim = offset + m_off;
00382   while (aim >= (m_node->end)) {
00383     if (m_node->next) m_node = m_node->next;
00384     else { //it was the last
00385       m_off = m_node->end;
00386       return *this;
00387     }
00388   }
00389   m_off = aim;
00390   return *this;
00391 }

template<unsigned int TMAXPAGES = 128>
int32_t eformat::PagedMemory< TMAXPAGES >::const_iterator::operator- ( const const_iterator other  )  const [inline]

Returns the difference in position between two iterators

Parameters:
other The other iterator to compare to

Definition at line 232 of file PagedMemory.h.

References eformat::PagedMemory< TMAXPAGES >::const_iterator::m_off, and EvtCyclic3::other().

00233       { return (int32_t)m_off - (int32_t)other.m_off; }

template<unsigned int TMAXPAGES>
eformat::PagedMemory< TMAXPAGES >::const_iterator & eformat::PagedMemory< TMAXPAGES >::const_iterator::operator-- (  ) 

Step back on the pointing place, 4 bytes or 1 word. This is the prefix operator.

Definition at line 364 of file PagedMemory.h.

References eformat::PagedMemory< TMAXPAGES >::node_t::end, eformat::PagedMemory< TMAXPAGES >::const_iterator::m_node, eformat::PagedMemory< TMAXPAGES >::const_iterator::m_off, eformat::PagedMemory< TMAXPAGES >::node_t::previous, and eformat::PagedMemory< TMAXPAGES >::node_t::start.

00365 { 
00366   --m_off;
00367   if ( m_off < (m_node->start) ) {
00368     if (!m_node->previous) { //it was the last
00369       m_off = m_node->start;
00370       return *this;
00371     }
00372     m_node = m_node->previous;
00373     m_off = m_node->end - 1;
00374   }
00375   return *this; 
00376 }

template<unsigned int TMAXPAGES>
eformat::PagedMemory< TMAXPAGES >::const_iterator & eformat::PagedMemory< TMAXPAGES >::const_iterator::operator-= ( size_t  offset  ) 

Retrocesses on the pointing place, by a number of (32-bit) words

Parameters:
offset The amount of words to advance

Definition at line 394 of file PagedMemory.h.

References eformat::PagedMemory< TMAXPAGES >::const_iterator::m_node, eformat::PagedMemory< TMAXPAGES >::const_iterator::m_off, eformat::PagedMemory< TMAXPAGES >::node_t::previous, and eformat::PagedMemory< TMAXPAGES >::node_t::start.

00395 {
00396   size_t aim = m_off - offset;
00397   while (aim < (m_node->start)) {
00398     if (m_node->previous) m_node = m_node->previous;
00399     else { //it was the first
00400       m_off = m_node->start;
00401       return *this;
00402     }
00403   }
00404   m_off = aim;
00405   return *this;
00406 }

template<unsigned int TMAXPAGES = 128>
bool eformat::PagedMemory< TMAXPAGES >::const_iterator::operator< ( const const_iterator other  )  const [inline]

Compares two operators (offset comparison)

Parameters:
other The other iterator to compare to

Definition at line 216 of file PagedMemory.h.

References eformat::PagedMemory< TMAXPAGES >::const_iterator::m_off, and EvtCyclic3::other().

00217       { return m_off < other.m_off; }

template<unsigned int TMAXPAGES = 128>
const_iterator& eformat::PagedMemory< TMAXPAGES >::const_iterator::operator= ( const const_iterator other  ) 

Copies the value of an iterator

Parameters:
other The iterator to copy the data from

template<unsigned int TMAXPAGES = 128>
bool eformat::PagedMemory< TMAXPAGES >::const_iterator::operator== ( const const_iterator other  )  const [inline]

Compares two pointers

Parameters:
other The other iterator to compare this one with.

Definition at line 159 of file PagedMemory.h.

References EvtCyclic3::other().

00160       { return !(*this != other); }

template<unsigned int TMAXPAGES = 128>
bool eformat::PagedMemory< TMAXPAGES >::const_iterator::operator> ( const const_iterator other  )  const [inline]

Compares two operators (offset comparison)

Parameters:
other The other iterator to compare to

Definition at line 224 of file PagedMemory.h.

References eformat::PagedMemory< TMAXPAGES >::const_iterator::m_off, and EvtCyclic3::other().

00225       { return m_off > other.m_off; }

template<unsigned int TMAXPAGES>
uint32_t eformat::PagedMemory< TMAXPAGES >::const_iterator::operator[] ( size_t  pos  )  const

Gets a value away N positions from this iterator, unchecked

Parameters:
pos The number "N" of positions away from this iterator

Definition at line 318 of file PagedMemory.h.

References CAST32, deljobs::end, and boss::pos.

00319 {
00320   if (m_off + pos < m_node->end) { //trying to reach data on the current page
00321     return CAST32(m_node->page->iov_base)[(m_off+pos)-m_node->start];
00322   }
00323   //otherwise it is not on this page, I have to find the page
00324   const_iterator it = *this;
00325   it += pos;
00326   return *it;
00327 }


Friends And Related Function Documentation

template<unsigned int TMAXPAGES = 128>
friend class PagedMemory [friend]

Definition at line 105 of file PagedMemory.h.


Member Data Documentation

template<unsigned int TMAXPAGES = 128>
const node_t* eformat::PagedMemory< TMAXPAGES >::const_iterator::m_node [private]

base address of the index table

Definition at line 237 of file PagedMemory.h.

Referenced by eformat::PagedMemory< TMAXPAGES >::const_iterator::at(), eformat::PagedMemory< TMAXPAGES >::const_iterator::operator *(), eformat::PagedMemory< TMAXPAGES >::const_iterator::operator++(), eformat::PagedMemory< TMAXPAGES >::const_iterator::operator+=(), eformat::PagedMemory< TMAXPAGES >::const_iterator::operator--(), and eformat::PagedMemory< TMAXPAGES >::const_iterator::operator-=().

template<unsigned int TMAXPAGES = 128>
size_t eformat::PagedMemory< TMAXPAGES >::const_iterator::m_off [private]

the current offset, in 32-bit words

Definition at line 238 of file PagedMemory.h.

Referenced by eformat::PagedMemory< TMAXPAGES >::const_iterator::at(), eformat::PagedMemory< TMAXPAGES >::const_iterator::operator *(), eformat::PagedMemory< TMAXPAGES >::const_iterator::operator++(), eformat::PagedMemory< TMAXPAGES >::const_iterator::operator+=(), eformat::PagedMemory< TMAXPAGES >::const_iterator::operator-(), eformat::PagedMemory< TMAXPAGES >::const_iterator::operator--(), eformat::PagedMemory< TMAXPAGES >::const_iterator::operator-=(), eformat::PagedMemory< TMAXPAGES >::const_iterator::operator<(), and eformat::PagedMemory< TMAXPAGES >::const_iterator::operator>().


Generated on Tue Nov 29 23:36:29 2016 for BOSS_7.0.2 by  doxygen 1.4.7