[mmap] partial revert of 8cef8db4 to disable using mmap file reader
[videoplayer.git] / stats.cpp
blob60749e376b61f793eafbe463c8c59a472efb2cb9
1 #include "stats.h"
3 #include <iostream>
5 using namespace std;
7 //singleton pointer initialisation
8 Stats *Stats::_instance = 0;
10 Stats::Stats()
15 void Stats::addStat(const string &section_name, const string &stat_name, const string &stat_value)
17 inner_t *sec = sections[section_name];
19 if(!sec) {
20 //create the section if it does not exist
21 sec = sections[section_name] = new inner_t();
24 //insert the stat into the section
25 (*sec)[stat_name] = stat_value;
28 Stats::section_t::const_iterator Stats::get_section_begin()
30 return sections.begin();
33 Stats::section_t::const_iterator Stats::get_section_end()
35 return sections.end();
38 #ifdef HARNESS
39 int main(void)
41 Stats &s = Stats::getInstance();
43 s.addStat("S1", "first", "1");
44 s.addStat("S1", "first", "5");
45 s.addStat("S1", "second", "2");
47 s.addStat("foo", "xfirst", "1");
48 s.addStat("foo", "xsecond", "2");
50 Stats::section_t::const_iterator it = s.get_section_begin();
51 while(it != s.get_section_end())
53 std::cout << (*it).first << std::endl; //name of the section
55 Stats::inner_t::const_iterator it2 = (*it).second->begin();
57 while(it2 != (*it).second->end()) {
58 std::cout << (*it2).first << " = " << (*it2).second << std::endl;
59 it2++;
62 it++;
65 #endif