libcrn  3.9.5
A document image processing library
•All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNProgress.h
Go to the documentation of this file.
1 /* Copyright 2007-2016 Yann LEYDIER, CoReNum, INSA-Lyon, Université Paris Descartes, ENS-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.h
19  * \author Yann LEYDIER
20  */
21 
22 #ifndef CRNPROGRESS_HEADER
23 #define CRNPROGRESS_HEADER
24 
25 #include <CRNString.h>
26 
27 namespace crn
28 {
29  /****************************************************************************/
39  class Progress
40  {
41  public:
42  enum class Type { PERCENT = 0, ABSOLUTE = 1 };
44  Progress(const String &nam, size_t maxcount = 100):name(nam),end(maxcount),current(0),type(Type::PERCENT) { }
45  Progress(const Progress &) = delete;
46  Progress(Progress&&) = default;
47  Progress& operator=(const Progress &) = delete;
48  Progress& operator=(Progress&&) = default;
49 
51  virtual ~Progress();
52 
54  void Advance();
56  void SetMaxCount(size_t maxcount, bool reset = true) { end = maxcount; if (reset) Reset(); }
58  void Reset();
59 
61  void SetType(Type typ) noexcept { type = typ; }
62 
63  void SetName(const crn::String &nam) { name = nam; }
64 
65  protected:
67  virtual void display(const String &msg) = 0;
68 
70  size_t current;
71  size_t end;
74  };
75 
77 
78  /****************************************************************************/
88  class ConsoleProgress: public Progress
89  {
90  public:
92  ConsoleProgress(const String &name, size_t maxcount = 100):Progress(name, maxcount) {}
94  virtual ~ConsoleProgress() override {}
95 
96  protected:
98  virtual void display(const String &msg) override;
99  };
100 
101  CRN_ALIAS_SMART_PTR(ConsoleProgress)
102 }
103 
104 #endif
ConsoleProgress(const String &name, size_t maxcount=100)
Constructor.
Definition: CRNProgress.h:92
Base class for a progress display.
Definition: CRNProgress.h:39
void SetName(const crn::String &nam)
Definition: CRNProgress.h:63
Progress display in console.
Definition: CRNProgress.h:88
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
void SetType(Type typ) noexcept
Sets the type of progress bar.
Definition: CRNProgress.h:61
Progress(const String &nam, size_t maxcount=100)
Constructor.
Definition: CRNProgress.h:44
void SetMaxCount(size_t maxcount, bool reset=true)
Sets the total number of steps.
Definition: CRNProgress.h:56
virtual ~ConsoleProgress() override
Destructor.
Definition: CRNProgress.h:94
void Reset()
Resets the progress to 0.
Definition: CRNProgress.cpp:53
virtual ~Progress()
Destructor.
Definition: CRNProgress.cpp:59
CRN_ALIAS_SMART_PTR(ImageBW)
virtual void display(const String &msg)=0
Displays the progress.
Progress & operator=(const Progress &)=delete