All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Protected Member Functions | Private Attributes | List of all members
icarus::ns::util::PassCounter< Count > Class Template Reference

Class counting pass/fail events. More...

#include <PassCounter.h>

Public Types

using Count_t = Count
 Type used for counters. More...
 

Public Member Functions

Access
Count_t passed () const
 Returns the number of events which "passed". More...
 
Count_t failed () const
 Returns the number of events which "failed". More...
 
Count_t total () const
 Returns the total number of registered events. More...
 
bool empty () const
 Returns whether there is no event recorded yet. More...
 
Registration and reset
void add (bool pass)
 Adds a single event, specifying whether it "passes" or not. More...
 
void addFailed ()
 Adds a single event which did not "pass". More...
 
void addPassed ()
 Adds a single event which did "pass". More...
 
void reset ()
 Resets all counts. More...
 

Protected Member Functions

Count_t const & totalRef () const
 Direct read-only access to data members for derived classes. More...
 
Count_t const & passedRef () const
 Direct read-only access to data members for derived classes. More...
 

Private Attributes

Count_t fTotal {}
 Total entries. More...
 
Count_t fPassed {}
 Entries which "passed". More...
 

Detailed Description

template<typename Count = unsigned int>
class icarus::ns::util::PassCounter< Count >

Class counting pass/fail events.

Template Parameters
Count(default: unsigned int) type of counter

The class keeps track of events which may fall in one of two categories, called "passed" and "failed". Example of usage:

for (int i = 0; i < 15; ++i) OddCounter.add(i % 2 == 1);
std::cout << "Counted " << OddCounter.passed() << " odd entries and "
<< OddCounter.failed() << " even entries, "
<< OddCounter.total() << " in total." << std::endl;

will print: Counted 7 odd entries and 8 even entries, 15 in total..

The type Count must support:

Definition at line 15 of file PassCounter.h.

Member Typedef Documentation

template<typename Count = unsigned int>
using icarus::ns::util::PassCounter< Count >::Count_t = Count

Type used for counters.

Definition at line 45 of file PassCounter.h.

Member Function Documentation

template<typename Count >
void icarus::ns::util::PassCounter< Count >::add ( bool  pass)

Adds a single event, specifying whether it "passes" or not.

Definition at line 112 of file PassCounter.h.

112  {
113 
114  ++fTotal;
115  if (pass) ++fPassed;
116 
117 } // icarus::ns::util::PassCounter<>::add()
Count_t fTotal
Total entries.
Definition: PassCounter.h:99
Count_t fPassed
Entries which &quot;passed&quot;.
Definition: PassCounter.h:100
template<typename Count = unsigned int>
void icarus::ns::util::PassCounter< Count >::addFailed ( )
inline

Adds a single event which did not "pass".

Definition at line 76 of file PassCounter.h.

76 { add(false); }
void add(bool pass)
Adds a single event, specifying whether it &quot;passes&quot; or not.
Definition: PassCounter.h:112
template<typename Count = unsigned int>
void icarus::ns::util::PassCounter< Count >::addPassed ( )
inline

Adds a single event which did "pass".

Definition at line 79 of file PassCounter.h.

79 { add(true); }
void add(bool pass)
Adds a single event, specifying whether it &quot;passes&quot; or not.
Definition: PassCounter.h:112
template<typename Count = unsigned int>
bool icarus::ns::util::PassCounter< Count >::empty ( ) const
inline

Returns whether there is no event recorded yet.

Definition at line 63 of file PassCounter.h.

63 { return total() == Count_t{}; }
Count_t total() const
Returns the total number of registered events.
Definition: PassCounter.h:60
Count Count_t
Type used for counters.
Definition: PassCounter.h:45
template<typename Count = unsigned int>
Count_t icarus::ns::util::PassCounter< Count >::failed ( ) const
inline

Returns the number of events which "failed".

Definition at line 57 of file PassCounter.h.

57 { return total() - passed(); }
Count_t total() const
Returns the total number of registered events.
Definition: PassCounter.h:60
Count_t passed() const
Returns the number of events which &quot;passed&quot;.
Definition: PassCounter.h:54
template<typename Count = unsigned int>
Count_t icarus::ns::util::PassCounter< Count >::passed ( ) const
inline

Returns the number of events which "passed".

Definition at line 54 of file PassCounter.h.

54 { return fPassed; }
Count_t fPassed
Entries which &quot;passed&quot;.
Definition: PassCounter.h:100
template<typename Count = unsigned int>
Count_t const& icarus::ns::util::PassCounter< Count >::passedRef ( ) const
inlineprotected

Direct read-only access to data members for derived classes.

Definition at line 93 of file PassCounter.h.

93 { return fPassed; }
Count_t fPassed
Entries which &quot;passed&quot;.
Definition: PassCounter.h:100
template<typename Count >
void icarus::ns::util::PassCounter< Count >::reset ( )

Resets all counts.

Definition at line 122 of file PassCounter.h.

122  {
123 
124  fTotal = Count_t{};
125  fPassed = Count_t{};
126 
127 } // icarus::ns::util::PassCounter<>::reset()
Count_t fTotal
Total entries.
Definition: PassCounter.h:99
Count Count_t
Type used for counters.
Definition: PassCounter.h:45
Count_t fPassed
Entries which &quot;passed&quot;.
Definition: PassCounter.h:100
template<typename Count = unsigned int>
Count_t icarus::ns::util::PassCounter< Count >::total ( ) const
inline

Returns the total number of registered events.

Definition at line 60 of file PassCounter.h.

60 { return fTotal; }
Count_t fTotal
Total entries.
Definition: PassCounter.h:99
template<typename Count = unsigned int>
Count_t const& icarus::ns::util::PassCounter< Count >::totalRef ( ) const
inlineprotected

Direct read-only access to data members for derived classes.

Definition at line 90 of file PassCounter.h.

90 { return fTotal; }
Count_t fTotal
Total entries.
Definition: PassCounter.h:99

Member Data Documentation

template<typename Count = unsigned int>
Count_t icarus::ns::util::PassCounter< Count >::fPassed {}
private

Entries which "passed".

Definition at line 100 of file PassCounter.h.

template<typename Count = unsigned int>
Count_t icarus::ns::util::PassCounter< Count >::fTotal {}
private

Total entries.

Definition at line 99 of file PassCounter.h.


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