PLearn 0.1
Public Member Functions | Private Attributes
PLearn::VMatAccessBuffer Class Reference

Simple buffer class for getRow calls on a VMat. More...

#include <VMatAccessBuffer.h>

Inheritance diagram for PLearn::VMatAccessBuffer:
Inheritance graph
[legend]
Collaboration diagram for PLearn::VMatAccessBuffer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 VMatAccessBuffer (VMat source, int max_size=250)
void getRow (int row, const Vec &rowbuf)
void lookAhead (int row, const Vec &rowbuf)
VMatAccessBufferdeepCopy (CopiesMap &copies) const
 Deep copying.

Private Attributes

VMat m_source
int m_current_row
int m_max_size
Vec m_row_buffer
deque< Vecm_cached_rows

Detailed Description

Simple buffer class for getRow calls on a VMat.

Definition at line 51 of file VMatAccessBuffer.h.


Constructor & Destructor Documentation

PLearn::VMatAccessBuffer::VMatAccessBuffer ( VMat  source,
int  max_size = 250 
)

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());
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

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;
}

Here is the call graph for this function:

void PLearn::VMatAccessBuffer::getRow ( int  row,
const Vec rowbuf 
)

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 );
}

Here is the call graph for this function:

void PLearn::VMatAccessBuffer::lookAhead ( int  row,
const Vec rowbuf 
)

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 );
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 66 of file VMatAccessBuffer.h.

Referenced by deepCopy(), getRow(), and lookAhead().

Definition at line 63 of file VMatAccessBuffer.h.

Referenced by getRow(), and lookAhead().

Definition at line 64 of file VMatAccessBuffer.h.

Referenced by getRow(), and lookAhead().

Definition at line 65 of file VMatAccessBuffer.h.

Referenced by deepCopy(), getRow(), lookAhead(), and VMatAccessBuffer().

Definition at line 62 of file VMatAccessBuffer.h.

Referenced by deepCopy(), getRow(), lookAhead(), and VMatAccessBuffer().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines