Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
Log::Counter Class Reference

#include <log.hh>

Public Member Functions

void add (std::string const &tag)
 
void reset ()
 
void reset (std::string const &tag)
 

Static Public Member Functions

static Counterget ()
 

Private Types

typedef std::map< std::string, unsigned int > container_t
 

Private Member Functions

 Counter ()
 
 Counter (Counter const &)
 
Counteroperator= (Counter const &)
 

Private Attributes

container_t m_counters
 
boost::mutex m_mutex
 

Friends

std::ostream & operator<< (std::ostream &stream, Counter const &c)
 

Detailed Description

Definition at line 38 of file log.hh.

Member Typedef Documentation

◆ container_t

std::map< std::string, unsigned int> Log::Counter::container_t
private

Definition at line 40 of file log.hh.

Constructor & Destructor Documentation

◆ Counter() [1/2]

Log::Counter::Counter ( )
inlineprivate

Definition at line 45 of file log.hh.

45{}

◆ Counter() [2/2]

Log::Counter::Counter ( Counter const & )
private

Member Function Documentation

◆ operator=()

Counter & Log::Counter::operator= ( Counter const & )
private

◆ get()

static Counter & Log::Counter::get ( )
inlinestatic

Definition at line 53 of file log.hh.

54 {
55 static Counter c;
56
57 return c;
58 }
Counter()
Definition log.hh:45

◆ add()

void Log::Counter::add ( std::string const & tag)
inline

Definition at line 60 of file log.hh.

61 {
62 boost::mutex::scoped_lock lock(m_mutex);
63
64 container_t::iterator const it = m_counters.find(tag);
65
66 if (it != m_counters.end()) {
67 ++it->second;
68 } else {
69 m_counters.insert(std::make_pair(tag, 1));
70 }
71 }
container_t m_counters
Definition log.hh:42
boost::mutex m_mutex
Definition log.hh:43

◆ reset() [1/2]

void Log::Counter::reset ( )
inline

Definition at line 73 of file log.hh.

74 {
75 boost::mutex::scoped_lock lock(m_mutex);
76 m_counters.clear();
77 }

◆ reset() [2/2]

void Log::Counter::reset ( std::string const & tag)
inline

Definition at line 79 of file log.hh.

80 {
81 boost::mutex::scoped_lock lock(m_mutex);
82
83 container_t::iterator const it = m_counters.find(tag);
84
85 if (it != m_counters.end()) {
86 it->second = 0;
87 }
88 }

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & stream,
Counter const & c )
friend

Definition at line 91 of file log.hh.

92 {
93 boost::mutex::scoped_lock lock(c.m_mutex);
94
95 for (
96 container_t::const_iterator it = c.m_counters.begin(), et = c.m_counters.end();
97 it != et;
98 ++it
99 ) {
100 stream << it->first << ": " << it->second << ", ";
101 }
102
103 return stream;
104 }

Member Data Documentation

◆ m_counters

container_t Log::Counter::m_counters
private

Definition at line 42 of file log.hh.

◆ m_mutex

boost::mutex Log::Counter::m_mutex
mutableprivate

Definition at line 43 of file log.hh.


The documentation for this class was generated from the following file: