File indexing completed on 2026-09-27 09:14:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #ifndef LAGER_CORE_PROGRESS_METER_LOADED
0021 #define LAGER_CORE_PROGRESS_METER_LOADED
0022
0023 #include <cmath>
0024 #include <cstdint>
0025 #include <iostream>
0026 #include <limits>
0027
0028
0029
0030
0031 namespace lager {
0032 class progress_meter {
0033 public:
0034 constexpr static const size_t PRECISION = 10000.;
0035 explicit progress_meter(size_t max, size_t start_index = 0,
0036 size_t precision = PRECISION)
0037 : max_{max}
0038 , index_{start_index}
0039 , precision_{precision > max ? max : precision} {
0040 std::cerr << "\nProcessing... " << std::endl;
0041 update();
0042 }
0043 void update(size_t i) {
0044 index_ = i;
0045 if (index_ > max_) {
0046 index_ = max_;
0047 }
0048
0049
0050
0051 if (!(index_ % 100)) {
0052 const double cnt = (index_ > 50) ? (100. * index_) / max_ : 0.;
0053 char msg[15];
0054 sprintf(msg, " %3.2f%%\r", cnt);
0055 std::cerr << msg << std::flush;
0056 }
0057 }
0058 void update(size_t i, const size_t max) {
0059 max_ = max;
0060 update(i);
0061 }
0062 void update() {
0063 index_ += 1;
0064 update(index_);
0065 }
0066 ~progress_meter() { std::cerr << " Done!" << std::endl; }
0067
0068 private:
0069 size_t max_;
0070 size_t index_;
0071 const size_t precision_;
0072 };
0073 }
0074
0075 #endif