KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
l_heartbeat.h
Go to the documentation of this file.
1 
9 /*
10  * $Id: l_heartbeat.h 14984 2013-07-22 23:46:33Z predoehl $
11  *
12  * Recommended tab width: 4
13  */
14 
15 
16 #ifndef HEARTBEAT_H_PREDOEHL_UOFARIZONAVISION
17 #define HEARTBEAT_H_PREDOEHL_UOFARIZONAVISION
18 
19 #include <string>
20 
21 namespace kjb {
22 
23 
45 class Heartbeat {
46  const std::string m_msg;
47  const unsigned m_mask;
48  const unsigned m_total;
49  const float m_denominator;
50  const time_t m_start_time;
51  unsigned m_progress_counter;
52  const bool m_is_output_to_tty;
53 
55  mutable int m_lastlen;
56 
67  std::string thump( bool finalize = false ) const;
68 
69 public:
70 
92  Heartbeat(
93  const std::string& message,
94  unsigned total = 1,
95  unsigned masklen = 10
96  );
97 
98 
117  std::string beat()
118  {
119  std::string retval;
120  if ( m_is_output_to_tty && 0 == (m_progress_counter & m_mask) )
121  {
122  retval = thump(); // finalize default value is false
123  }
124  ++m_progress_counter;
125  return retval;
126  }
127 
139  std::string stop() const
140  {
141  return thump( /* set finalize to... */ true );
142  }
143 };
144 
145 }
146 
147 #endif
std::string beat()
Indicate one tiny step of your algorithm's execution.
Definition: l_heartbeat.h:117
A class for for indicating the status of slow-moving loops.
Definition: l_heartbeat.h:45
std::string stop() const
Call this when your algorithm is finished, to see total time.
Definition: l_heartbeat.h:139
Heartbeat(const std::string &message, unsigned total=1, unsigned masklen=10)
Make a "heart" which will beat while your slow algorithm runs.
Definition: l_heartbeat.cpp:103