aimstil  5.0.5
progress_indicator.tpp
Go to the documentation of this file.
1 
2 namespace til
3 {
4 
5  //---------------------------------------------------------------------------
6 
7  template < typename TPICallback >
8  ProgressIndicator<TPICallback>::ProgressIndicator
9  (
10  std::size_t parts
11  , std::size_t total
12  )
13  : m_total(total)
14  , m_parts(parts)
15  {
16  this->init();
17  }
18 
19  //---------------------------------------------------------------------------
20 
21  template < typename TPICallback >
22  void ProgressIndicator<TPICallback>::init() { m_currentpart = 0; m_mark = 0.0; }
23 
24  //---------------------------------------------------------------------------
25 
26  template < typename TPICallback >
27  void ProgressIndicator<TPICallback>::operator()(std::size_t i)
28  {
29  if ( i >= m_mark && i < m_mark + 1 )
30  {
31  //std::cout << i << " " << m_parts << " " << m_total << " " << m_currentpart << " " << m_mark << std::endl;
32  m_callback(m_currentpart, m_parts);
33  this->nextPart();
34  }
35  }
36 
37  //---------------------------------------------------------------------------
38 
39  template < typename TPICallback >
40  void ProgressIndicator<TPICallback>::nextPart()
41  {
42  ++m_currentpart;
43  m_mark = m_currentpart * m_total / double(m_parts);
44  }
45 
46  //---------------------------------------------------------------------------
47 
48 } // namespace til
49 
50