Debian Codegraph @

lib/common/Statistic.cpp

raw
1 #include "Statistic.h"
2 #include <string.h>
3
4 AVM_BEGIN_NAMESPACE;
5
6 Statistic::Statistic(const char* name, uint_t size)
7 :m_pName(name), m_pValues(0), m_uiSize(size), m_uiPos(0), m_dSum(0)
8 {
9 }
10
11 Statistic::~Statistic()
12 {
13 delete[] m_pValues;
14 }
15
16 Statistic::Statistic(const Statistic& s)
17 {
18 m_pName = s.m_pName;
19 m_uiSize = s.m_uiSize;
20 if ((m_pValues = new float[m_uiSize]))
21 memcpy(m_pValues, s.m_pValues, sizeof(float) * m_uiSize);
22 m_dSum = s.m_dSum;
23 m_uiPos = s.m_uiPos;
24 }
25
26 void Statistic::clear()
27 {
28 m_dSum = 0;
29 delete[] m_pValues;
30 m_pValues = 0;
31 }
32
33 void Statistic::insert(float v)
34 {
35 if (!m_pValues)
36 {
37 m_pValues = new float[m_uiSize];
38 if (!m_pValues)
39 return;
40 for (unsigned i = 0; i < m_uiSize; i++)
41 m_pValues[i] = v;
42 m_dSum = v * float(m_uiSize);
43 }
44
45 m_dSum -= m_pValues[m_uiPos];
46 m_pValues[m_uiPos] = v;
47 m_dSum += v;
48
49 m_uiPos = (m_uiPos + 1) % m_uiSize;
50 }
51
52 AVM_END_NAMESPACE;