BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
eformat::PagedMemory< TMAXPAGES >::const_iterator Class Reference

#include <PagedMemory.h>

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
 

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

◆ const_iterator() [1/2]

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.

125: m_node(), m_off() {}

◆ const_iterator() [2/2]

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

Copies the value of an iterator

Parameters
otherThe iterator to copy the data from

Definition at line 132 of file PagedMemory.h.

133 : m_node(other.m_node), m_off(other.m_off) {}
Index other(Index i, Index j)
Definition: EvtCyclic3.cc:118

◆ ~const_iterator()

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

Destroys an iterator

Definition at line 138 of file PagedMemory.h.

138{}

Member Function Documentation

◆ at()

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
posThe number "N" of positions away from this iterator

Definition at line 330 of file PagedMemory.h.

331{
332 //immediate return (most of the cases)
333 if (m_off + pos < m_node->end) { //trying to reach data on the current page
334 return CAST32(m_node->page->iov_base)[(m_off+pos)-m_node->start];
335 }
336
337 //immediate points of failure
338 if (!m_node || (m_node->next == 0 && (m_off+pos) >= m_node->end))
339 throw EFORMAT_OUT_OF_BOUNDS(0, pos << 2);
340
341 //if I get here, the data is on another page and the request might still be
342 //out of bounds, so watch.
343 const_iterator it = *this;
344 it += pos;
345 return it.at(0);
346}
#define EFORMAT_OUT_OF_BOUNDS(size, pos)
#define CAST32(x)
Definition: PagedMemory.h:26
const_iterator end(void) const
Definition: PagedMemory.h:257
const struct iovec * page
Definition: PagedMemory.h:87

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

◆ operator!=()

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

Compares two pointers

Parameters
otherThe other iterator to compare this one with.

Definition at line 310 of file PagedMemory.h.

312{
313 return (m_node == other.m_node && m_off == other.m_off)?false:true;
314}

◆ operator*()

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.

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

◆ operator++()

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.

350{
351 ++m_off;
352 if ( m_off >= (m_node->end) ) {
353 if (!m_node->next) { //it was the last
354 m_off = m_node->end;
355 return *this;
356 }
357 m_node = m_node->next;
358 m_off = m_node->start;
359 }
360 return *this;
361}

◆ operator+=()

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
offsetThe amount of words to advance

Definition at line 379 of file PagedMemory.h.

380{
381 size_t aim = offset + m_off;
382 while (aim >= (m_node->end)) {
383 if (m_node->next) m_node = m_node->next;
384 else { //it was the last
385 m_off = m_node->end;
386 return *this;
387 }
388 }
389 m_off = aim;
390 return *this;
391}

◆ operator-()

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
otherThe other iterator to compare to

Definition at line 232 of file PagedMemory.h.

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

◆ operator--()

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

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

Definition at line 364 of file PagedMemory.h.

365{
366 --m_off;
367 if ( m_off < (m_node->start) ) {
368 if (!m_node->previous) { //it was the last
369 m_off = m_node->start;
370 return *this;
371 }
372 m_node = m_node->previous;
373 m_off = m_node->end - 1;
374 }
375 return *this;
376}

◆ operator-=()

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
offsetThe amount of words to advance

Definition at line 394 of file PagedMemory.h.

395{
396 size_t aim = m_off - offset;
397 while (aim < (m_node->start)) {
398 if (m_node->previous) m_node = m_node->previous;
399 else { //it was the first
400 m_off = m_node->start;
401 return *this;
402 }
403 }
404 m_off = aim;
405 return *this;
406}

◆ operator<()

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

Compares two operators (offset comparison)

Parameters
otherThe other iterator to compare to

Definition at line 216 of file PagedMemory.h.

217 { return m_off < other.m_off; }

◆ operator=()

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

Copies the value of an iterator

Parameters
otherThe iterator to copy the data from

Definition at line 301 of file PagedMemory.h.

303{
304 m_node = other.m_node;
305 m_off = other.m_off;
306 return *this;
307}

◆ operator==()

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

Compares two pointers

Parameters
otherThe other iterator to compare this one with.

Definition at line 159 of file PagedMemory.h.

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

◆ operator>()

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

Compares two operators (offset comparison)

Parameters
otherThe other iterator to compare to

Definition at line 224 of file PagedMemory.h.

225 { return m_off > other.m_off; }

◆ operator[]()

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
posThe number "N" of positions away from this iterator

Definition at line 317 of file PagedMemory.h.

319{
320 if (m_off + pos < m_node->end) { //trying to reach data on the current page
321 return CAST32(m_node->page->iov_base)[(m_off+pos)-m_node->start];
322 }
323 //otherwise it is not on this page, I have to find the page
324 const_iterator it = *this;
325 it += pos;
326 return *it;
327}

Friends And Related Function Documentation

◆ PagedMemory

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

Definition at line 105 of file PagedMemory.h.


The documentation for this class was generated from the following file: