00001 #ifndef UTIL_ERSATZ_PROGRESS_H
00002 #define UTIL_ERSATZ_PROGRESS_H
00003
00004 #include <iostream>
00005 #include <string>
00006 #include <stdint.h>
00007
00008
00009
00010
00011 namespace util {
00012
00013 extern const char kProgressBanner[];
00014
00015 class ErsatzProgress {
00016 public:
00017
00018 ErsatzProgress();
00019
00020
00021 explicit ErsatzProgress(uint64_t complete, std::ostream *to = &std::cerr, const std::string &message = "");
00022
00023 ~ErsatzProgress();
00024
00025 ErsatzProgress &operator++() {
00026 if (++current_ >= next_) Milestone();
00027 return *this;
00028 }
00029
00030 ErsatzProgress &operator+=(uint64_t amount) {
00031 if ((current_ += amount) >= next_) Milestone();
00032 return *this;
00033 }
00034
00035 void Set(uint64_t to) {
00036 if ((current_ = to) >= next_) Milestone();
00037 }
00038
00039 void Finished() {
00040 Set(complete_);
00041 }
00042
00043 private:
00044 void Milestone();
00045
00046 uint64_t current_, next_, complete_;
00047 unsigned char stones_written_;
00048 std::ostream *out_;
00049
00050
00051 ErsatzProgress(const ErsatzProgress &other);
00052 ErsatzProgress &operator=(const ErsatzProgress &other);
00053 };
00054
00055 }
00056
00057 #endif // UTIL_ERSATZ_PROGRESS_H