CircularBuffer.cxx
Go to the documentation of this file.
1 
12 #include "CircularBuffer.h"
13 
14 #include <stdexcept>
15 
16 using std::runtime_error;
17 using std::string;
18 
19 using namespace hippodraw;
20 
21 CircularBuffer::CircularBuffer ( const std::string & filename )
22  : NTuple ( filename ),
23  m_capacity ( 0 ),
24  m_next_row ( 0 ),
25  m_has_filled ( false )
26 {
27 }
28 
29 CircularBuffer::CircularBuffer ( const std::vector< std::string > & v )
30  : NTuple ( v ),
31  m_capacity ( 0 ),
32  m_next_row ( 0 ),
33  m_has_filled ( false )
34 {
35 }
36 
38  : NTuple ( nt ),
39  m_capacity ( nt.m_capacity ),
40  m_next_row ( nt.m_next_row ),
41  m_has_filled ( nt.m_has_filled )
42 {
43 }
44 
46  : NTuple ( n ),
47  m_capacity ( 0 ),
48  m_next_row ( 0 ),
49  m_has_filled ( false )
50 {
51 }
52 
54  : NTuple (),
55  m_capacity ( 0 ),
56  m_next_row ( 0 ),
57  m_has_filled ( false )
58 {
59 }
60 
62 {
63  m_next_row = 0;
64  m_has_filled = false;
65 
66  NTuple::clear ();
67 }
68 
69 void
72 {
73  m_next_row++;
74  if ( m_next_row == m_capacity ) {
75  m_next_row = 0;
76  m_has_filled = true;
77  }
78 }
79 
80 void
82 addRow ( const std::vector< double > & v )
83 {
84  if ( m_has_filled ) {
86  }
87  else {
88  NTuple::addRow ( v );
89  }
90 
92 }
93 
94 void CircularBuffer::reserve ( unsigned int count )
95 {
96  if ( empty () == false ) {
97  const string what ( "CircularBuffer: Attempt to set the capacity of "
98  "non-empty buffer is not allowed" );
99  throw runtime_error ( what );
100  }
101 
102  NTuple::reserve ( count );
103  m_capacity = count;
104 }
void replaceRow(unsigned int i, const std::vector< double > &data)
Replaces the data in the row i.
Definition: NTuple.cxx:244
virtual void clear()
Clears the NTuple.
Definition: NTuple.cxx:211
virtual void reserve(unsigned int count)
For each column, reserves enough space for the data source to grow to count rows. ...
Definition: NTuple.cxx:395
unsigned int m_next_row
The index to the next row to be added.
virtual void addRow(const std::vector< double > &v)
Adds a row to the end of the ntuple.
Definition: NTuple.cxx:266
void incrementRowIndex()
Increments the next row index.
virtual void reserve(unsigned int count)
Sets the size, in rows, of the circular buffer.
ViewBase * v
Definition: PlotTable.cxx:104
CircularBuffer class interface.
virtual void addRow(const std::vector< double > &v)
Adds a row to the buffer.
virtual void clear()
Clears the contents without changing the capacity.
unsigned int m_capacity
The capacity.
A DataSource class implemented with std::vector&lt;double&gt; to store the column data. ...
Definition: NTuple.h:33
virtual bool empty() const
Returns true, if NTuple is empty, i.e.
Definition: NTuple.cxx:223
CircularBuffer manager.
CircularBuffer()
The default constructor creating an circular buffer with 0 columns.
bool m_has_filled
A flog which when true, indicates the buffer has been filled to capacity.

Generated for HippoDraw Class Library by doxygen