| 62 | } |
| 63 | |
| 64 | void ProgressContext::Show(int count) |
| 65 | { |
| 66 | // only update if the percent has changed |
| 67 | int percent = int(100.0f * float(count) / float(m_total)); |
| 68 | if (m_lastPercent == percent) |
| 69 | return; |
| 70 | m_lastPercent = percent; |
| 71 | |
| 72 | // get time since start |
| 73 | std::chrono::high_resolution_clock::time_point now = std::chrono::high_resolution_clock::now(); |
| 74 | std::chrono::duration<double> timeSpan = std::chrono::duration_cast<std::chrono::duration<double>>(now - m_start); |
| 75 | |
| 76 | std::string elapsed = MakeDurationString(m_constantTimeSeconds + (float)timeSpan.count()); |
| 77 | |
| 78 | float estimateMultiplier = std::max(float(m_total) / float(count), 1.0f); |
| 79 | std::string estimate = MakeDurationString(m_constantTimeSeconds + estimateMultiplier * (float)timeSpan.count()); |
| 80 | |
| 81 | // make the message |
| 82 | char buffer[1024]; |
| 83 | if (count < 0) |
| 84 | { |
| 85 | sprintf_s(buffer, "\r%s100%% elapsed %s", m_label, elapsed.c_str()); |
| 86 | } |
| 87 | else |
| 88 | { |
| 89 | sprintf_s(buffer, "\r%s%i%% elapsed %s estimated %s", m_label, percent, elapsed.c_str(), estimate.c_str()); |
| 90 | } |
| 91 | int newBufferLength = (int)strlen(buffer); |
| 92 | int newBufferLengthCopy = newBufferLength; |
| 93 | |
| 94 | // pad with spaces to erase whatever may be there from before |
| 95 | while (newBufferLength < m_lastBufferLength) |
| 96 | { |
| 97 | buffer[newBufferLength] = ' '; |
| 98 | newBufferLength++; |
| 99 | } |
| 100 | buffer[newBufferLength] = 0; |
| 101 | if (count < 0) |
| 102 | strcat_s(buffer, "\n"); |
| 103 | |
| 104 | // show the message |
| 105 | printf("%s", buffer); |
| 106 | m_lastBufferLength = newBufferLengthCopy; |
| 107 | } |
nothing calls this directly
no outgoing calls
no test coverage detected