MCPcopy Create free account
hub / github.com/Xtra-Computing/thundersvm / HitCounter

Class HitCounter

include/thundersvm/util/log.h:2086–2169  ·  view source on GitHub ↗

@brief Class that keeps record of current line hit for occasional logging

Source from the content-addressed store, hash-verified

2084 };
2085/// @brief Class that keeps record of current line hit for occasional logging
2086 class HitCounter {
2087 public:
2088 HitCounter(void) :
2089 m_filename(""),
2090 m_lineNumber(0),
2091 m_hitCounts(0) {
2092 }
2093
2094 HitCounter(const char* filename, base::type::LineNumber lineNumber) :
2095 m_filename(filename),
2096 m_lineNumber(lineNumber),
2097 m_hitCounts(0) {
2098 }
2099
2100 HitCounter(const HitCounter& hitCounter) :
2101 m_filename(hitCounter.m_filename),
2102 m_lineNumber(hitCounter.m_lineNumber),
2103 m_hitCounts(hitCounter.m_hitCounts) {
2104 }
2105
2106 HitCounter& operator=(const HitCounter& hitCounter) {
2107 if (&hitCounter != this) {
2108 m_filename = hitCounter.m_filename;
2109 m_lineNumber = hitCounter.m_lineNumber;
2110 m_hitCounts = hitCounter.m_hitCounts;
2111 }
2112 return *this;
2113 }
2114
2115 virtual ~HitCounter(void) {
2116 }
2117
2118 /// @brief Resets location of current hit counter
2119 inline void resetLocation(const char* filename, base::type::LineNumber lineNumber) {
2120 m_filename = filename;
2121 m_lineNumber = lineNumber;
2122 }
2123
2124 /// @brief Validates hit counts and resets it if necessary
2125 inline void validateHitCounts(std::size_t n) {
2126 if (m_hitCounts >= base::consts::kMaxLogPerCounter) {
2127 m_hitCounts = (n >= 1 ? base::consts::kMaxLogPerCounter % n : 0);
2128 }
2129 ++m_hitCounts;
2130 }
2131
2132 inline const char* filename(void) const {
2133 return m_filename;
2134 }
2135
2136 inline base::type::LineNumber lineNumber(void) const {
2137 return m_lineNumber;
2138 }
2139
2140 inline std::size_t hitCounts(void) const {
2141 return m_hitCounts;
2142 }
2143

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected