7 //singleton pointer initialisation
8 Stats
*Stats::_instance
= 0;
15 void Stats::addStat(const string
§ion_name
, const string
&stat_name
, const string
&stat_value
)
17 inner_t
*sec
= sections
[section_name
];
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();
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
;