1 | /* |
2 | * Legal Notice |
3 | * |
4 | * This document and associated source code (the "Work") is a part of a |
5 | * benchmark specification maintained by the TPC. |
6 | * |
7 | * The TPC reserves all right, title, and interest to the Work as provided |
8 | * under U.S. and international laws, including without limitation all patent |
9 | * and trademark rights therein. |
10 | * |
11 | * No Warranty |
12 | * |
13 | * 1.1 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE INFORMATION |
14 | * CONTAINED HEREIN IS PROVIDED "AS IS" AND WITH ALL FAULTS, AND THE |
15 | * AUTHORS AND DEVELOPERS OF THE WORK HEREBY DISCLAIM ALL OTHER |
16 | * WARRANTIES AND CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, |
17 | * INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES, |
18 | * DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR |
19 | * PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF |
20 | * WORKMANLIKE EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE. |
21 | * ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT, |
22 | * QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT |
23 | * WITH REGARD TO THE WORK. |
24 | * 1.2 IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THE WORK BE LIABLE TO |
25 | * ANY OTHER PARTY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO THE |
26 | * COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS |
27 | * OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT, |
28 | * INDIRECT, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY, |
29 | * OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT |
30 | * RELATING TO THE WORK, WHETHER OR NOT SUCH AUTHOR OR DEVELOPER HAD |
31 | * ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. |
32 | * |
33 | * Contributors |
34 | * - Christopher Chan-Nui |
35 | */ |
36 | |
37 | /* |
38 | * Simple class to display the progress of long running job to the console. |
39 | */ |
40 | |
41 | #ifndef PROGRESSMETER_H_INCLUDED |
42 | #define PROGRESSMETER_H_INCLUDED |
43 | |
44 | #include <iostream> |
45 | |
46 | #include "utilities/DateTime.h" |
47 | #include "progressmeterinterface.h" |
48 | #include "utilities/locking.h" |
49 | |
50 | namespace TPCE { |
51 | |
52 | class ProgressMeter : public ProgressMeterInterface { |
53 | private: |
54 | int m_total; |
55 | int m_current; |
56 | int m_display_interval; |
57 | CDateTime m_start_time; |
58 | CDateTime m_last_time; |
59 | std::ostream *m_output; |
60 | int m_verbosity; |
61 | mutable CMutex m_mutex; |
62 | |
63 | public: |
64 | // total - The total number of tasks to complete before the job is done. |
65 | ProgressMeter(int total, int verbosity = 0, std::ostream *output = &std::cout); |
66 | |
67 | // val - minimum number of seconds between automatic display updates |
68 | // set to -1 to disable automatic displays |
69 | void set_display_interval(int val); |
70 | int display_interval() const; |
71 | |
72 | // Displays the current progress and an estimated time to finish onto |
73 | // the provided output stream. |
74 | virtual void display() const; |
75 | |
76 | // Displays a progress message to the specified output stream |
77 | // |
78 | // output - output stream to display progress to |
79 | virtual void display_message(std::ostream &out) const; |
80 | |
81 | // Notifies the progress meter that some tasks have been completed. If |
82 | // there hasn't been a display update within display_interval seconds then |
83 | // an update will be emitted to the output stream. |
84 | // |
85 | // count - number of tasks completed |
86 | // output - output stream to display progress to |
87 | void inc(int count = 1); |
88 | |
89 | // Return current count |
90 | int current() const; |
91 | |
92 | // Return total count |
93 | int total() const; |
94 | |
95 | void lock() const; |
96 | void unlock() const; |
97 | |
98 | // Output a message if it has the correct verbosity |
99 | // |
100 | // mesg - message to display |
101 | // level - verbosity level to display at |
102 | virtual void message(const std::string &mesg, int level = 0); |
103 | }; |
104 | |
105 | } // namespace TPCE |
106 | |
107 | #endif // PROGRESSMETER_H_INCLUDED |
108 | |