CircularBuffer.cxx

Go to the documentation of this file.
00001 
00012 #include "CircularBuffer.h"
00013 
00014 #include <stdexcept>
00015 
00016 using std::runtime_error;
00017 using std::string;
00018 
00019 using namespace hippodraw;
00020 
00021 CircularBuffer::CircularBuffer ( const std::string & filename )
00022   : NTuple ( filename ),
00023     m_capacity ( 0 ),
00024     m_next_row ( 0 ),
00025     m_has_filled ( false )
00026 {
00027 }
00028 
00029 CircularBuffer::CircularBuffer ( const std::vector< std::string >  & v )
00030   : NTuple ( v ),
00031     m_capacity ( 0 ),
00032     m_next_row ( 0 ),
00033     m_has_filled ( false )
00034 {
00035 }
00036 
00037 CircularBuffer::CircularBuffer ( const CircularBuffer & nt )
00038   : NTuple ( nt ),
00039     m_capacity ( nt.m_capacity ),
00040     m_next_row ( nt.m_next_row ),
00041     m_has_filled ( nt.m_has_filled )
00042 {
00043 }
00044 
00045 CircularBuffer::CircularBuffer ( unsigned int n )
00046   : NTuple ( n ),
00047     m_capacity ( 0 ),
00048     m_next_row ( 0 ),
00049     m_has_filled ( false )
00050 {
00051 }
00052 
00053 CircularBuffer::CircularBuffer ()
00054   : NTuple (),
00055     m_capacity ( 0 ),
00056     m_next_row ( 0 ),
00057     m_has_filled ( false )
00058 {
00059 }
00060 
00061 void CircularBuffer::clear()
00062 {
00063   m_next_row = 0;
00064   m_has_filled = false;
00065 
00066   NTuple::clear ();
00067 }
00068 
00069 void
00070 CircularBuffer::
00071 incrementRowIndex ()
00072 {
00073   m_next_row++;
00074   if ( m_next_row == m_capacity ) {
00075     m_next_row = 0;
00076     m_has_filled = true;
00077   }
00078 }
00079 
00080 void
00081 CircularBuffer::
00082 addRow ( const std::vector< double > & v )
00083 {
00084   if ( m_has_filled ) {
00085     NTuple::replaceRow ( m_next_row, v );
00086   }
00087   else {
00088     NTuple::addRow ( v );
00089   }
00090 
00091   incrementRowIndex ( );
00092 }
00093 
00094 void CircularBuffer::reserve ( unsigned int count )
00095 {
00096   if ( empty () == false ) {
00097     const string what ( "CircularBuffer: Attempt to set the capacity of "
00098                         "non-empty buffer is not allowed" );
00099     throw runtime_error ( what );
00100   }
00101 
00102   NTuple::reserve ( count );
00103   m_capacity = count;
00104 }

Generated for HippoDraw Class Library by doxygen