diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-01-09 14:01:51 -0500 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-01-09 14:01:51 -0500 |
| commit | 46b7119fab32b05923dbf9cda7cd6ce62f572846 (patch) | |
| tree | 31ac6c281869085e5dbc6b210886c554d4c52cad /generator/progress.h | |
| download | cadence-46b7119fab32b05923dbf9cda7cd6ce62f572846.tar.gz cadence-46b7119fab32b05923dbf9cda7cd6ce62f572846.tar.bz2 cadence-46b7119fab32b05923dbf9cda7cd6ce62f572846.zip | |
Initial commit
Diffstat (limited to 'generator/progress.h')
| -rw-r--r-- | generator/progress.h | 56 |
1 files changed, 56 insertions, 0 deletions
| diff --git a/generator/progress.h b/generator/progress.h new file mode 100644 index 0000000..f42f701 --- /dev/null +++ b/generator/progress.h | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | #ifndef PROGRESS_H_A34EF856 | ||
| 2 | #define PROGRESS_H_A34EF856 | ||
| 3 | |||
| 4 | #include <string> | ||
| 5 | |||
| 6 | namespace cadence { | ||
| 7 | namespace generator { | ||
| 8 | |||
| 9 | class progress { | ||
| 10 | private: | ||
| 11 | std::string message; | ||
| 12 | int total; | ||
| 13 | int cur = 0; | ||
| 14 | int lprint = 0; | ||
| 15 | |||
| 16 | public: | ||
| 17 | progress(std::string message, int total) : message(message), total(total) | ||
| 18 | { | ||
| 19 | std::cout << message << " 0%" << std::flush; | ||
| 20 | } | ||
| 21 | |||
| 22 | void update(int val) | ||
| 23 | { | ||
| 24 | if (val <= total) | ||
| 25 | { | ||
| 26 | cur = val; | ||
| 27 | } else { | ||
| 28 | cur = total; | ||
| 29 | } | ||
| 30 | |||
| 31 | int pp = cur * 100 / total; | ||
| 32 | if (pp != lprint) | ||
| 33 | { | ||
| 34 | lprint = pp; | ||
| 35 | |||
| 36 | std::cout << "\b\b\b\b" << std::right; | ||
| 37 | std::cout.width(3); | ||
| 38 | std::cout << pp << "%" << std::flush; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | void update() | ||
| 43 | { | ||
| 44 | update(cur+1); | ||
| 45 | } | ||
| 46 | |||
| 47 | ~progress() | ||
| 48 | { | ||
| 49 | std::cout << "\b\b\b\b100%" << std::endl; | ||
| 50 | } | ||
| 51 | }; | ||
| 52 | |||
| 53 | }; | ||
| 54 | }; | ||
| 55 | |||
| 56 | #endif /* end of include guard: PROGRESS_H_A34EF856 */ | ||
