PLearn 0.1
|
Simple buffer class for getRow calls on a VMat. More...
#include <VMatAccessBuffer.h>
Public Member Functions | |
VMatAccessBuffer (VMat source, int max_size=250) | |
void | getRow (int row, const Vec &rowbuf) |
void | lookAhead (int row, const Vec &rowbuf) |
VMatAccessBuffer * | deepCopy (CopiesMap &copies) const |
Deep copying. | |
Private Attributes | |
VMat | m_source |
int | m_current_row |
int | m_max_size |
Vec | m_row_buffer |
deque< Vec > | m_cached_rows |
Simple buffer class for getRow calls on a VMat.
Definition at line 51 of file VMatAccessBuffer.h.
Definition at line 46 of file VMatAccessBuffer.cc.
References m_row_buffer, m_source, PLearn::TVec< T >::resize(), and PLearn::VMat::width().
Referenced by deepCopy().
: m_source( source ), m_current_row( -1 ), m_max_size( max_size ) { m_row_buffer.resize(m_source.width()); }
VMatAccessBuffer * PLearn::VMatAccessBuffer::deepCopy | ( | CopiesMap & | copies | ) | const |
Deep copying.
< a copy already exists, so return it
Otherwise call the copy constructor to obtain a copy
Put the copy in the map
return the completed deep_copy
Definition at line 116 of file VMatAccessBuffer.cc.
References PLearn::deepCopyField(), m_cached_rows, m_row_buffer, m_source, and VMatAccessBuffer().
{ CopiesMap::iterator it = copies.find(this); if(it!=copies.end()) return (VMatAccessBuffer*) it->second; VMatAccessBuffer* deep_copy = new VMatAccessBuffer(*this); deepCopyField(this->m_source, copies); deepCopyField(this->m_row_buffer, copies); deepCopyField(this->m_cached_rows, copies); copies[this] = deep_copy; return deep_copy; }
Definition at line 56 of file VMatAccessBuffer.cc.
References PLearn::TVec< T >::copy(), m_cached_rows, m_current_row, m_max_size, m_row_buffer, m_source, and PLASSERT.
{ int last_row = m_current_row + m_cached_rows.size() - 1; bool much_below = false; if ( row < m_current_row ) { int new_size = last_row - row + 1; much_below = ( new_size > m_max_size ); if ( !much_below ) while ( m_current_row > row ) { m_source->getRow(--m_current_row, m_row_buffer); m_cached_rows.push_front(m_row_buffer.copy()); } } if ( much_below || row > last_row ) { m_source->getRow(row, m_row_buffer); m_current_row = row; m_cached_rows.clear(); m_cached_rows.push_back(m_row_buffer.copy()); } else { for ( ; m_current_row < row; ++m_current_row ) m_cached_rows.pop_front(); m_row_buffer << m_cached_rows[0]; } // Finally rowbuf << m_row_buffer; PLASSERT( m_current_row == row ); PLASSERT( int(m_cached_rows.size()) <= m_max_size ); }
Definition at line 96 of file VMatAccessBuffer.cc.
References PLearn::TVec< T >::copy(), m_cached_rows, m_current_row, m_max_size, m_row_buffer, m_source, and PLASSERT.
{ PLASSERT( row > m_current_row ); int last_row = m_current_row + m_cached_rows.size() - 1; if ( row <= last_row ) m_row_buffer << m_cached_rows[row-m_current_row]; else while ( last_row < row ) { m_source->getRow(++last_row, m_row_buffer); m_cached_rows.push_back(m_row_buffer.copy()); } // Finally rowbuf << m_row_buffer; PLASSERT( int(m_cached_rows.size()) <= m_max_size ); }
deque<Vec> PLearn::VMatAccessBuffer::m_cached_rows [private] |
Definition at line 66 of file VMatAccessBuffer.h.
Referenced by deepCopy(), getRow(), and lookAhead().
int PLearn::VMatAccessBuffer::m_current_row [private] |
Definition at line 63 of file VMatAccessBuffer.h.
Referenced by getRow(), and lookAhead().
int PLearn::VMatAccessBuffer::m_max_size [private] |
Definition at line 64 of file VMatAccessBuffer.h.
Referenced by getRow(), and lookAhead().
Vec PLearn::VMatAccessBuffer::m_row_buffer [private] |
Definition at line 65 of file VMatAccessBuffer.h.
Referenced by deepCopy(), getRow(), lookAhead(), and VMatAccessBuffer().
VMat PLearn::VMatAccessBuffer::m_source [private] |
Definition at line 62 of file VMatAccessBuffer.h.
Referenced by deepCopy(), getRow(), lookAhead(), and VMatAccessBuffer().