Joshua
open source statistical hierarchical phrase-based machine translation system
|
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 // Ersatz version of boost::progress so core language model doesn't depend on 00009 // boost. Also adds option to print nothing. 00010 00011 namespace util { 00012 00013 extern const char kProgressBanner[]; 00014 00015 class ErsatzProgress { 00016 public: 00017 // No output. 00018 ErsatzProgress(); 00019 00020 // Null means no output. The null value is useful for passing along the ostream pointer from another caller. 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 // noncopyable 00051 ErsatzProgress(const ErsatzProgress &other); 00052 ErsatzProgress &operator=(const ErsatzProgress &other); 00053 }; 00054 00055 } // namespace util 00056 00057 #endif // UTIL_ERSATZ_PROGRESS_H