libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNProgress.cpp
Go to the documentation of this file.
1 /* Copyright 2007-2013 Yann LEYDIER, INSA-Lyon
2  *
3  * This file is part of libcrn.
4  *
5  * libcrn is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libcrn is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libcrn. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: CRNProgress.cpp
19  * \author Yann LEYDIER
20  */
21 
22 #include <CRNUtils/CRNProgress.h>
23 #include <CRNIO/CRNIO.h>
24 #include <CRNMath/CRNMath.h>
25 #include <cstdio>
26 
27 using namespace crn;
28 
29 /*****************************************************************************/
35 {
36  current += 1;
37  double f = (double(current) * 100.0) / double(end);
38  char buff[1024];
39  switch (type)
40  {
41  case Type::ABSOLUTE:
42  snprintf(buff, 1024, " %zi / %zi", Min(current + 1, end), end);
43  break;
44  case Type::PERCENT:
45  default:
46  snprintf(buff, 1024, " %.2f %%", (double)f);
47  break;
48  }
49  disp = name + buff;
50  display(disp);
51 }
52 
54 {
55  current = -1;
56  Advance();
57 }
58 
60 {
61 }
62 
64 {
65  CRNVerbose(msg);
66 }
67 
size_t current
Definition: CRNProgress.h:70
void Advance()
Progresses of one step.
Definition: CRNProgress.cpp:34
A UTF32 character string class.
Definition: CRNString.h:61
const T & Min(const T &a, const T &b)
Returns the min of two values.
Definition: CRNMath.h:49
void Reset()
Resets the progress to 0.
Definition: CRNProgress.cpp:53
virtual ~Progress()
Destructor.
Definition: CRNProgress.cpp:59
virtual void display(const String &msg)=0
Displays the progress.
virtual void display(const String &msg) override
Displays the progress.
Definition: CRNProgress.cpp:63
#define CRNVerbose(x)
Definition: CRNIO.h:146