DDS  ver. 3.6
ProgressDisplay.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 //
4 //
5 #ifndef _DDS_PROGRESSDISPLAY_H_
6 #define _DDS_PROGRESSDISPLAY_H_
7 
8 #include <chrono>
9 
10 namespace dds::misc
11 {
12  inline std::string getProgressDisplayString(int _completed, int _total)
13  {
14  float progress = (_total != 0) ? (float)_completed / (float)_total : 0;
15  if (progress > 1.)
16  progress = 1.;
17 
18  const unsigned int barWidth = 50;
19 
20  std::stringstream ss;
21  ss << "[";
22  unsigned int pos = progress * barWidth;
23 
24  for (unsigned int i = 0; i < barWidth; ++i)
25  {
26  if (i <= pos)
27  ss << "=";
28  else
29  ss << " ";
30  }
31  ss << "] " << int(progress * 100.0) << " % (" << _completed << "/" << _total << ")\r";
32 
33  return ss.str();
34  }
35 } // namespace dds::misc
36 
37 #endif /*_DDS_PROGRESSDISPLAY_H_*/
std::string getProgressDisplayString(int _completed, int _total)
Definition: ProgressDisplay.h:12
Definition: BoostHelper.h:14