|
Joshua
open source statistical hierarchical phrase-based machine translation system
|
00001 #ifndef UTIL_ERSATZ_PROGRESS__ 00002 #define UTIL_ERSATZ_PROGRESS__ 00003 00004 #include <iosfwd> 00005 #include <string> 00006 00007 // Ersatz version of boost::progress so core language model doesn't depend on 00008 // boost. Also adds option to print nothing. 00009 00010 namespace util { 00011 class ErsatzProgress { 00012 public: 00013 // No output. 00014 ErsatzProgress(); 00015 00016 // Null means no output. The null value is useful for passing along the ostream pointer from another caller. 00017 ErsatzProgress(std::ostream *to, const std::string &message, std::size_t complete); 00018 00019 ~ErsatzProgress(); 00020 00021 ErsatzProgress &operator++() { 00022 if (++current_ >= next_) Milestone(); 00023 return *this; 00024 } 00025 00026 ErsatzProgress &operator+=(std::size_t amount) { 00027 if ((current_ += amount) >= next_) Milestone(); 00028 return *this; 00029 } 00030 00031 void Set(std::size_t to) { 00032 if ((current_ = to) >= next_) Milestone(); 00033 Milestone(); 00034 } 00035 00036 void Finished() { 00037 Set(complete_); 00038 } 00039 00040 private: 00041 void Milestone(); 00042 00043 std::size_t current_, next_, complete_; 00044 unsigned char stones_written_; 00045 std::ostream *out_; 00046 00047 // noncopyable 00048 ErsatzProgress(const ErsatzProgress &other); 00049 ErsatzProgress &operator=(const ErsatzProgress &other); 00050 }; 00051 00052 } // namespace util 00053 00054 #endif // UTIL_ERSATZ_PROGRESS__