diff options
Diffstat (limited to 'generator/progress.h')
| -rw-r--r-- | generator/progress.h | 78 | 
1 files changed, 42 insertions, 36 deletions
| diff --git a/generator/progress.h b/generator/progress.h index 81f07a3..fcb680d 100644 --- a/generator/progress.h +++ b/generator/progress.h | |||
| @@ -3,48 +3,54 @@ | |||
| 3 | 3 | ||
| 4 | #include <string> | 4 | #include <string> | 
| 5 | 5 | ||
| 6 | class progress { | 6 | namespace verbly { | 
| 7 | private: | 7 | namespace generator { | 
| 8 | std::string message; | ||
| 9 | int total; | ||
| 10 | int cur = 0; | ||
| 11 | int lprint = 0; | ||
| 12 | 8 | ||
| 13 | public: | 9 | class progress { | 
| 14 | progress(std::string message, int total) : message(message), total(total) | 10 | private: | 
| 15 | { | 11 | std::string message; | 
| 16 | std::cout << message << " 0%" << std::flush; | 12 | int total; | 
| 17 | } | 13 | int cur = 0; | 
| 14 | int lprint = 0; | ||
| 18 | 15 | ||
| 19 | void update(int val) | 16 | public: | 
| 20 | { | 17 | progress(std::string message, int total) : message(message), total(total) | 
| 21 | if (val <= total) | 18 | { | 
| 22 | { | 19 | std::cout << message << " 0%" << std::flush; | 
| 23 | cur = val; | 20 | } | 
| 24 | } else { | 21 | |
| 25 | cur = total; | 22 | void update(int val) | 
| 26 | } | 23 | { | 
| 24 | if (val <= total) | ||
| 25 | { | ||
| 26 | cur = val; | ||
| 27 | } else { | ||
| 28 | cur = total; | ||
| 29 | } | ||
| 27 | 30 | ||
| 28 | int pp = cur * 100 / total; | 31 | int pp = cur * 100 / total; | 
| 29 | if (pp != lprint) | 32 | if (pp != lprint) | 
| 30 | { | 33 | { | 
| 31 | lprint = pp; | 34 | lprint = pp; | 
| 32 | 35 | ||
| 33 | std::cout << "\b\b\b\b" << std::right; | 36 | std::cout << "\b\b\b\b" << std::right; | 
| 34 | std::cout.width(3); | 37 | std::cout.width(3); | 
| 35 | std::cout << pp << "%" << std::flush; | 38 | std::cout << pp << "%" << std::flush; | 
| 36 | } | 39 | } | 
| 37 | } | 40 | } | 
| 41 | |||
| 42 | void update() | ||
| 43 | { | ||
| 44 | update(cur+1); | ||
| 45 | } | ||
| 38 | 46 | ||
| 39 | void update() | 47 | ~progress() | 
| 40 | { | 48 | { | 
| 41 | update(cur+1); | 49 | std::cout << "\b\b\b\b100%" << std::endl; | 
| 42 | } | 50 | } | 
| 51 | }; | ||
| 43 | 52 | ||
| 44 | ~progress() | 53 | }; | 
| 45 | { | ||
| 46 | std::cout << "\b\b\b\b100%" << std::endl; | ||
| 47 | } | ||
| 48 | }; | 54 | }; | 
| 49 | 55 | ||
| 50 | #endif /* end of include guard: PROGRESS_H_A34EF856 */ | 56 | #endif /* end of include guard: PROGRESS_H_A34EF856 */ | 
